summaryrefslogtreecommitdiffstats
path: root/lib/libssl/s3_lib.c
diff options
context:
space:
mode:
authormiod <miod@openbsd.org>2014-05-26 20:54:06 +0000
committermiod <miod@openbsd.org>2014-05-26 20:54:06 +0000
commit548d9b4efd029838b1a9a455f18ce59246e2e799 (patch)
tree82395fbebb7afa0921874e1e53917cff6009b1d6 /lib/libssl/s3_lib.c
parentUnchecked malloc() return value in SSL_COMP_add_compression_method(), in the (diff)
downloadwireguard-openbsd-548d9b4efd029838b1a9a455f18ce59246e2e799.tar.xz
wireguard-openbsd-548d9b4efd029838b1a9a455f18ce59246e2e799.zip
Replace the following logic:
if (nothing to allocate) ptr = malloc(1) else { if ((ptr = malloc(size to allocate)) memcpy(ptr, data to copy, size to allocate) } if (ptr == NULL) OMG ERROR with a saner logic where the NULL pointer check if moved to the actual malloc branch, so that we do not need to malloc a single byte, just to avoid having a NULL pointer. Whoever thought allocating a single byte was a smart idea was obviously not taking his meds. ok beck@ guenther@
Diffstat (limited to 'lib/libssl/s3_lib.c')
-rw-r--r--lib/libssl/s3_lib.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/libssl/s3_lib.c b/lib/libssl/s3_lib.c
index 8b67e7c36a3..d8a186040b8 100644
--- a/lib/libssl/s3_lib.c
+++ b/lib/libssl/s3_lib.c
@@ -2633,16 +2633,18 @@ ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
if (s->tlsext_opaque_prf_input != NULL)
free(s->tlsext_opaque_prf_input);
if ((size_t)larg == 0) {
- /* dummy byte just to get non-NULL */
- s->tlsext_opaque_prf_input = malloc(1);
- } else
+ s->tlsext_opaque_prf_input = NULL;
+ s->tlsext_opaque_prf_input_len = 0;
+ ret = 1;
+ } else {
s->tlsext_opaque_prf_input =
BUF_memdup(parg, (size_t)larg);
- if (s->tlsext_opaque_prf_input != NULL) {
- s->tlsext_opaque_prf_input_len = (size_t)larg;
- ret = 1;
- } else
- s->tlsext_opaque_prf_input_len = 0;
+ if (s->tlsext_opaque_prf_input != NULL) {
+ s->tlsext_opaque_prf_input_len = (size_t)larg;
+ ret = 1;
+ } else
+ s->tlsext_opaque_prf_input_len = 0;
+ }
break;
#endif