openssl: Allocate our own buffer for i2d_* wrapper macro
If we pass a pointer to NULL, the memory allocated by OpenSSL has to be freed with OPENSSL_free(). Otherwise, this can lead to random crashes/freezes for Windows builds as seen on AppVeyor. To not complicate things for callers of this macro, we allocate our own memory, which we already do for other i2d_* calls.
This commit is contained in:
@@ -101,9 +101,14 @@ bool openssl_bn2chunk(const BIGNUM *bn, chunk_t *chunk);
|
|||||||
* @returns allocated chunk of the object, or chunk_empty
|
* @returns allocated chunk of the object, or chunk_empty
|
||||||
*/
|
*/
|
||||||
#define openssl_i2chunk(type, obj) ({ \
|
#define openssl_i2chunk(type, obj) ({ \
|
||||||
unsigned char *ptr = NULL; \
|
chunk_t chunk = chunk_empty; \
|
||||||
int len = i2d_##type(obj, &ptr); \
|
int len = i2d_##type(obj, NULL); \
|
||||||
len < 0 ? chunk_empty : chunk_create(ptr, len);})
|
if (len >= 0) { \
|
||||||
|
chunk = chunk_alloc(len); \
|
||||||
|
u_char *p = chunk.ptr; \
|
||||||
|
i2d_##type(obj, &p); \
|
||||||
|
} \
|
||||||
|
chunk; })
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an OpenSSL ASN1_OBJECT to a chunk.
|
* Convert an OpenSSL ASN1_OBJECT to a chunk.
|
||||||
|
|||||||
Reference in New Issue
Block a user