STIR/SHAKEN: OPENSSL_free serial hex from openssl.

We're getting the serial number of the certificate from openssl and
freeing it with ast_free(), but it needs to be freed with OPENSSL_free()
instead. Now we duplicate the string and free the one from openssl with
OPENSSL_free(), which means we can still use ast_free() on the returned
string.

https://wiki.asterisk.org/wiki/display/AST/OpenSIPit+2021

Change-Id: Ia6e1a4028c1933a0e1d204b769ebb9f5a11f00ab
This commit is contained in:
Ben Ford 2021-05-11 12:26:13 -05:00 committed by Benjamin Keith Ford
parent 5e6508b56f
commit e0cbdfe063
1 changed files with 9 additions and 1 deletions

View File

@ -144,6 +144,7 @@ char *stir_shaken_get_serial_number_x509(const char *path)
ASN1_INTEGER *serial;
BIGNUM *bignum;
char *serial_hex;
char *ret;
fp = fopen(path, "r");
if (!fp) {
@ -188,5 +189,12 @@ char *stir_shaken_get_serial_number_x509(const char *path)
return NULL;
}
return serial_hex;
ret = ast_strdup(serial_hex);
OPENSSL_free(serial_hex);
if (!ret) {
ast_log(LOG_ERROR, "Failed to dup serial from openssl for certificate %s\n", path);
return NULL;
}
return ret;
}