Let SSL_CIPHER_description() allocate the buffer for the description,
authorjsing <jsing@openbsd.org>
Sun, 24 Aug 2014 14:55:23 +0000 (14:55 +0000)
committerjsing <jsing@openbsd.org>
Sun, 24 Aug 2014 14:55:23 +0000 (14:55 +0000)
commitdb52929fe5c309c2b114763509171f6a1b956079
treeab544773ce1e0900eac9e960f2c699344e56bcc8
parentdf026f4d43d97ce92cef2b27d72a45906d5b556e
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.
lib/libssl/src/apps/ciphers.c