Skip to content
/ openssl Public
forked from openssl/openssl

Commit

Permalink
apps/ocsp: Add check for OPENSSL_strdup
Browse files Browse the repository at this point in the history
Just assert 'bn' to be non-NULL is not enough.
The check for 'itmp' is still needed.
If 'bn' is 0, the 'itmp' is assigned by OPENSSL_strdup().
Since OPENSSL_strdup() may fail because of the lack of memory,
the 'itmp' will be NULL and be an valid parameter hashed in
TXT_DB_get_by_index(), returning a wrong result.

Signed-off-by: Jiasheng Jiang <[email protected]>

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#17677)
  • Loading branch information
JiangJias authored and t8m committed Feb 17, 2022
1 parent 0c59055 commit 8f084b4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions apps/ocsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1180,10 +1180,12 @@ static char **lookup_serial(CA_DB *db, ASN1_INTEGER *ser)
bn = ASN1_INTEGER_to_BN(ser, NULL);
OPENSSL_assert(bn); /* FIXME: should report an error at this
* point and abort */
if (BN_is_zero(bn))
if (BN_is_zero(bn)) {
itmp = OPENSSL_strdup("00");
else
OPENSSL_assert(itmp);
} else {
itmp = BN_bn2hex(bn);
}
row[DB_serial] = itmp;
BN_free(bn);
rrow = TXT_DB_get_by_index(db->db, DB_serial, row);
Expand Down

0 comments on commit 8f084b4

Please sign in to comment.