Check the return from OPENSSL_buf2hexstr()
The function OPENSSL_buf2hexstr() can return NULL if it fails to allocate memory so the callers should check its return value. Fixes #10525 Reported-by: Ziyang Li (@Liby99) Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com> (Merged from https://github.com/openssl/openssl/pull/10526)
This commit is contained in:
parent
c1ff599440
commit
17197a2f61
5 changed files with 20 additions and 5 deletions
|
@ -138,6 +138,10 @@ opthelp:
|
||||||
BIO_write(out, dkm_bytes, dkm_len);
|
BIO_write(out, dkm_bytes, dkm_len);
|
||||||
} else {
|
} else {
|
||||||
hexout = OPENSSL_buf2hexstr(dkm_bytes, dkm_len);
|
hexout = OPENSSL_buf2hexstr(dkm_bytes, dkm_len);
|
||||||
|
if (hexout == NULL) {
|
||||||
|
BIO_printf(bio_err, "Memory allocation failure\n");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
BIO_printf(out, "%s\n\n", hexout);
|
BIO_printf(out, "%s\n\n", hexout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,8 @@ static size_t internal_trace_cb(const char *buf, size_t cnt,
|
||||||
tid = CRYPTO_THREAD_get_current_id();
|
tid = CRYPTO_THREAD_get_current_id();
|
||||||
hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));
|
hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));
|
||||||
BIO_snprintf(buffer, sizeof(buffer), "TRACE[%s]:%s: ",
|
BIO_snprintf(buffer, sizeof(buffer), "TRACE[%s]:%s: ",
|
||||||
hex, OSSL_trace_get_category_name(category));
|
hex == NULL ? "<null>" : hex,
|
||||||
|
OSSL_trace_get_category_name(category));
|
||||||
OPENSSL_free(hex);
|
OPENSSL_free(hex);
|
||||||
BIO_ctrl(trace_data->bio, PREFIX_CTRL_SET_PREFIX,
|
BIO_ctrl(trace_data->bio, PREFIX_CTRL_SET_PREFIX,
|
||||||
strlen(buffer), buffer);
|
strlen(buffer), buffer);
|
||||||
|
|
|
@ -36,7 +36,8 @@ void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
|
||||||
data = "";
|
data = "";
|
||||||
hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));
|
hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));
|
||||||
BIO_snprintf(buf, sizeof(buf), "%s:error:%s:%s:%s:%s:%d:%s\n",
|
BIO_snprintf(buf, sizeof(buf), "%s:error:%s:%s:%s:%s:%d:%s\n",
|
||||||
hex, lib, func, reason, file, line, data);
|
hex == NULL ? "<null>" : hex, lib, func, reason, file,
|
||||||
|
line, data);
|
||||||
OPENSSL_free(hex);
|
OPENSSL_free(hex);
|
||||||
if (cb(buf, strlen(buf), u) <= 0)
|
if (cb(buf, strlen(buf), u) <= 0)
|
||||||
break; /* abort outputting the error report */
|
break; /* abort outputting the error report */
|
||||||
|
|
|
@ -374,8 +374,8 @@ static void print_leak(const MEM *m, MEM_LEAK *l)
|
||||||
|
|
||||||
hex = OPENSSL_buf2hexstr((const unsigned char *)&m->threadid,
|
hex = OPENSSL_buf2hexstr((const unsigned char *)&m->threadid,
|
||||||
sizeof(m->threadid));
|
sizeof(m->threadid));
|
||||||
n = BIO_snprintf(bufp, len, "thread=%s, number=%d, address=%p\n", hex,
|
n = BIO_snprintf(bufp, len, "thread=%s, number=%d, address=%p\n",
|
||||||
m->num, m->addr);
|
hex == NULL ? "<null>" : hex, m->num, m->addr);
|
||||||
OPENSSL_free(hex);
|
OPENSSL_free(hex);
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -42,13 +42,22 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
|
||||||
char *tmp;
|
char *tmp;
|
||||||
if (akeyid->keyid) {
|
if (akeyid->keyid) {
|
||||||
tmp = OPENSSL_buf2hexstr(akeyid->keyid->data, akeyid->keyid->length);
|
tmp = OPENSSL_buf2hexstr(akeyid->keyid->data, akeyid->keyid->length);
|
||||||
X509V3_add_value((akeyid->issuer || akeyid->serial) ? "keyid" : NULL, tmp, &extlist);
|
if (tmp == NULL) {
|
||||||
|
ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
X509V3_add_value((akeyid->issuer || akeyid->serial) ? "keyid" : NULL,
|
||||||
|
tmp, &extlist);
|
||||||
OPENSSL_free(tmp);
|
OPENSSL_free(tmp);
|
||||||
}
|
}
|
||||||
if (akeyid->issuer)
|
if (akeyid->issuer)
|
||||||
extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist);
|
extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist);
|
||||||
if (akeyid->serial) {
|
if (akeyid->serial) {
|
||||||
tmp = OPENSSL_buf2hexstr(akeyid->serial->data, akeyid->serial->length);
|
tmp = OPENSSL_buf2hexstr(akeyid->serial->data, akeyid->serial->length);
|
||||||
|
if (tmp == NULL) {
|
||||||
|
ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
X509V3_add_value("serial", tmp, &extlist);
|
X509V3_add_value("serial", tmp, &extlist);
|
||||||
OPENSSL_free(tmp);
|
OPENSSL_free(tmp);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue