Skip to content

Commit 86edf13

Browse files
committed
Return error when a bit string indicates an invalid amount of bits left
Reviewed-by: Matt Caswell <matt@openssl.org>
1 parent fcd9b10 commit 86edf13

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

crypto/asn1/a_bitstr.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,16 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
136136

137137
p= *pp;
138138
i= *(p++);
139+
if (i > 7)
140+
{
141+
i=ASN1_R_INVALID_BIT_STRING_BITS_LEFT;
142+
goto err;
143+
}
139144
/* We do this to preserve the settings. If we modify
140145
* the settings, via the _set_bit function, we will recalculate
141146
* on output */
142147
ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
143-
ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */
148+
ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|i); /* set */
144149

145150
if (len-- > 1) /* using one because of the bits left byte */
146151
{

crypto/asn1/asn1.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,7 @@ void ERR_load_ASN1_strings(void);
13291329
#define ASN1_R_ILLEGAL_TIME_VALUE 184
13301330
#define ASN1_R_INTEGER_NOT_ASCII_FORMAT 185
13311331
#define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128
1332+
#define ASN1_R_INVALID_BIT_STRING_BITS_LEFT 220
13321333
#define ASN1_R_INVALID_BMPSTRING_LENGTH 129
13331334
#define ASN1_R_INVALID_DIGIT 130
13341335
#define ASN1_R_INVALID_MIME_TYPE 205

crypto/asn1/asn1_err.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
246246
{ERR_REASON(ASN1_R_ILLEGAL_TIME_VALUE) ,"illegal time value"},
247247
{ERR_REASON(ASN1_R_INTEGER_NOT_ASCII_FORMAT),"integer not ascii format"},
248248
{ERR_REASON(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG),"integer too large for long"},
249+
{ERR_REASON(ASN1_R_INVALID_BIT_STRING_BITS_LEFT),"invalid bit string bits left"},
249250
{ERR_REASON(ASN1_R_INVALID_BMPSTRING_LENGTH),"invalid bmpstring length"},
250251
{ERR_REASON(ASN1_R_INVALID_DIGIT) ,"invalid digit"},
251252
{ERR_REASON(ASN1_R_INVALID_MIME_TYPE) ,"invalid mime type"},

0 commit comments

Comments
 (0)