Skip to content

Commit

Permalink
Add negative integer check when using ASN1_BIT_STRING
Browse files Browse the repository at this point in the history
The negative integer check is done to prevent potential overflow.
Fixes #20719.

CLA: trivial

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #20862)

(cherry picked from commit 1258a8e)
  • Loading branch information
mlitre authored and paulidale committed May 3, 2023
1 parent 0f05c54 commit 8ddacec
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crypto/asn1/a_bitstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
int w, v, iv;
unsigned char *c;

if (n < 0)
return 0;

w = n / 8;
v = 1 << (7 - (n & 0x07));
iv = ~v;
Expand Down Expand Up @@ -182,6 +185,9 @@ int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n)
{
int w, v;

if (n < 0)
return 0;

w = n / 8;
v = 1 << (7 - (n & 0x07));
if ((a == NULL) || (a->length < (w + 1)) || (a->data == NULL))
Expand Down

0 comments on commit 8ddacec

Please sign in to comment.