summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordoug <>2015-02-07 04:37:35 +0000
committerdoug <>2015-02-07 04:37:35 +0000
commit6b246d35bb311ef0726da2113541c9a56921791f (patch)
tree63acbaab02583769dc6109cb71eefe4e5bb8e7c8
parentbe7bacd2cbd3fc2572c636ac04282b2ca64f7272 (diff)
downloadopenbsd-6b246d35bb311ef0726da2113541c9a56921791f.tar.gz
openbsd-6b246d35bb311ef0726da2113541c9a56921791f.tar.bz2
openbsd-6b246d35bb311ef0726da2113541c9a56921791f.zip
Only call free in CBB_init().
CBB_init_fixed() should not call free because it can lead to use after free or double free bugs. The caller should be responsible for creating and destroying the buffer. From BoringSSL commit a84f06fc1eee6ea25ce040675fbad72c532afece miod agrees with the reasoning ok jsing@, beck@
-rw-r--r--src/lib/libssl/bs_cbb.c9
-rw-r--r--src/lib/libssl/src/ssl/bs_cbb.c9
2 files changed, 12 insertions, 6 deletions
diff --git a/src/lib/libssl/bs_cbb.c b/src/lib/libssl/bs_cbb.c
index 94ca54f43b..eed8091698 100644
--- a/src/lib/libssl/bs_cbb.c
+++ b/src/lib/libssl/bs_cbb.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bs_cbb.c,v 1.3 2015/02/06 22:22:33 doug Exp $ */ 1/* $OpenBSD: bs_cbb.c,v 1.4 2015/02/07 04:37:35 doug Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -29,7 +29,6 @@ cbb_init(CBB *cbb, uint8_t *buf, size_t cap)
29 29
30 base = malloc(sizeof(struct cbb_buffer_st)); 30 base = malloc(sizeof(struct cbb_buffer_st));
31 if (base == NULL) { 31 if (base == NULL) {
32 free(buf);
33 return 0; 32 return 0;
34 } 33 }
35 34
@@ -53,7 +52,11 @@ CBB_init(CBB *cbb, size_t initial_capacity)
53 if (initial_capacity > 0 && buf == NULL) 52 if (initial_capacity > 0 && buf == NULL)
54 return 0; 53 return 0;
55 54
56 return cbb_init(cbb, buf, initial_capacity); 55 if (!cbb_init(cbb, buf, initial_capacity)) {
56 free(buf);
57 return 0;
58 }
59 return 1;
57} 60}
58 61
59int 62int
diff --git a/src/lib/libssl/src/ssl/bs_cbb.c b/src/lib/libssl/src/ssl/bs_cbb.c
index 94ca54f43b..eed8091698 100644
--- a/src/lib/libssl/src/ssl/bs_cbb.c
+++ b/src/lib/libssl/src/ssl/bs_cbb.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bs_cbb.c,v 1.3 2015/02/06 22:22:33 doug Exp $ */ 1/* $OpenBSD: bs_cbb.c,v 1.4 2015/02/07 04:37:35 doug Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -29,7 +29,6 @@ cbb_init(CBB *cbb, uint8_t *buf, size_t cap)
29 29
30 base = malloc(sizeof(struct cbb_buffer_st)); 30 base = malloc(sizeof(struct cbb_buffer_st));
31 if (base == NULL) { 31 if (base == NULL) {
32 free(buf);
33 return 0; 32 return 0;
34 } 33 }
35 34
@@ -53,7 +52,11 @@ CBB_init(CBB *cbb, size_t initial_capacity)
53 if (initial_capacity > 0 && buf == NULL) 52 if (initial_capacity > 0 && buf == NULL)
54 return 0; 53 return 0;
55 54
56 return cbb_init(cbb, buf, initial_capacity); 55 if (!cbb_init(cbb, buf, initial_capacity)) {
56 free(buf);
57 return 0;
58 }
59 return 1;
57} 60}
58 61
59int 62int