summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2014-08-24 14:55:23 +0000
committerjsing <>2014-08-24 14:55:23 +0000
commit62555a59e8e169497e389a9beaeb50964d9bda04 (patch)
treeb5a2e1744f832ba8feeedc5b2f75d581bc678149
parent15b6cd2e31b46d6dc4ad006b9dea11a3ea306237 (diff)
downloadopenbsd-62555a59e8e169497e389a9beaeb50964d9bda04.tar.gz
openbsd-62555a59e8e169497e389a9beaeb50964d9bda04.tar.bz2
openbsd-62555a59e8e169497e389a9beaeb50964d9bda04.zip
Let SSL_CIPHER_description() allocate the buffer for the description,
rather than passing in a fixed size buffer. This is yet another example of a horribly designed API - if the given buffer is NULL then SSL_CIPHER_description() allocates one for us (great!), which we then need to free (no problem). However, if this allocation fails it returns a pointer to a static string "OPENSSL_malloc Error" - obviously bad things happen if we call free() with this pointer. Unfortunately, there is no way of knowing that the function failed, other than comparing the returned string against the string literal - so do that before calling free()... Joint work with beck@ during g2k14.
-rw-r--r--src/lib/libssl/src/apps/ciphers.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lib/libssl/src/apps/ciphers.c b/src/lib/libssl/src/apps/ciphers.c
index 4d594fbaf4..7eddf2faba 100644
--- a/src/lib/libssl/src/apps/ciphers.c
+++ b/src/lib/libssl/src/apps/ciphers.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ciphers.c,v 1.26 2014/07/14 00:35:10 deraadt Exp $ */ 1/* $OpenBSD: ciphers.c,v 1.27 2014/08/24 14:55:23 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -89,8 +89,8 @@ ciphers_main(int argc, char **argv)
89 char *ciphers = NULL; 89 char *ciphers = NULL;
90 const SSL_METHOD *meth = NULL; 90 const SSL_METHOD *meth = NULL;
91 STACK_OF(SSL_CIPHER) * sk; 91 STACK_OF(SSL_CIPHER) * sk;
92 char buf[512];
93 BIO *STDout = NULL; 92 BIO *STDout = NULL;
93 char *desc;
94 94
95 meth = SSLv3_server_method(); 95 meth = SSLv3_server_method();
96 96
@@ -169,8 +169,10 @@ ciphers_main(int argc, char **argv)
169 else 169 else
170 BIO_printf(STDout, "0x%02X,0x%02X,0x%02X,0x%02X - ", id0, id1, id2, id3); /* whatever */ 170 BIO_printf(STDout, "0x%02X,0x%02X,0x%02X,0x%02X - ", id0, id1, id2, id3); /* whatever */
171 } 171 }
172 BIO_puts(STDout, 172 desc = SSL_CIPHER_description(c, NULL, 0);
173 SSL_CIPHER_description(c, buf, sizeof buf)); 173 BIO_puts(STDout, desc);
174 if (strcmp(desc, "OPENSSL_malloc Error") != 0)
175 free(desc);
174 } 176 }
175 } 177 }
176 178