mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-09 12:40:57 +00:00
Change error codes to more appropriate codes
The more precise error codes are borrowed from the ASN1 module. Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
parent
f51851dc70
commit
5b5a0b618c
@ -839,13 +839,13 @@ int mbedtls_oid_get_numeric_string(char *buf, size_t size,
|
|||||||
value = 0;
|
value = 0;
|
||||||
if ((oid->p[0]) == 0x80) {
|
if ((oid->p[0]) == 0x80) {
|
||||||
/* Overlong encoding is not allowed */
|
/* Overlong encoding is not allowed */
|
||||||
return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
|
return MBEDTLS_ERR_ASN1_INVALID_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (i < oid->len && ((oid->p[i] & 0x80) != 0)) {
|
while (i < oid->len && ((oid->p[i] & 0x80) != 0)) {
|
||||||
/* Prevent overflow in value. */
|
/* Prevent overflow in value. */
|
||||||
if (value > (UINT_MAX >> 7)) {
|
if (value > (UINT_MAX >> 7)) {
|
||||||
return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
|
return MBEDTLS_ERR_ASN1_INVALID_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
value |= oid->p[i] & 0x7F;
|
value |= oid->p[i] & 0x7F;
|
||||||
@ -853,7 +853,7 @@ int mbedtls_oid_get_numeric_string(char *buf, size_t size,
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (i >= oid->len) {
|
if (i >= oid->len) {
|
||||||
return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
|
return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
|
||||||
}
|
}
|
||||||
/* Last byte of first subidentifier */
|
/* Last byte of first subidentifier */
|
||||||
value |= oid->p[i] & 0x7F;
|
value |= oid->p[i] & 0x7F;
|
||||||
@ -874,11 +874,11 @@ int mbedtls_oid_get_numeric_string(char *buf, size_t size,
|
|||||||
for (; i < oid->len; i++) {
|
for (; i < oid->len; i++) {
|
||||||
/* Prevent overflow in value. */
|
/* Prevent overflow in value. */
|
||||||
if (value > (UINT_MAX >> 7)) {
|
if (value > (UINT_MAX >> 7)) {
|
||||||
return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
|
return MBEDTLS_ERR_ASN1_INVALID_DATA;
|
||||||
}
|
}
|
||||||
if ((value == 0) && ((oid->p[i]) == 0x80)) {
|
if ((value == 0) && ((oid->p[i]) == 0x80)) {
|
||||||
/* Overlong encoding is not allowed */
|
/* Overlong encoding is not allowed */
|
||||||
return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
|
return MBEDTLS_ERR_ASN1_INVALID_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
value <<= 7;
|
value <<= 7;
|
||||||
|
@ -102,20 +102,20 @@ OID get numeric string - multi-byte first subidentifier
|
|||||||
oid_get_numeric_string:"8837":0:"2.999"
|
oid_get_numeric_string:"8837":0:"2.999"
|
||||||
|
|
||||||
OID get numeric string - empty oid buffer
|
OID get numeric string - empty oid buffer
|
||||||
oid_get_numeric_string:"":MBEDTLS_ERR_OID_BUF_TOO_SMALL:""
|
oid_get_numeric_string:"":MBEDTLS_ERR_ASN1_OUT_OF_DATA:""
|
||||||
|
|
||||||
OID get numeric string - no final / all bytes have top bit set
|
OID get numeric string - no final / all bytes have top bit set
|
||||||
oid_get_numeric_string:"818181":MBEDTLS_ERR_OID_BUF_TOO_SMALL:""
|
oid_get_numeric_string:"818181":MBEDTLS_ERR_ASN1_OUT_OF_DATA:""
|
||||||
|
|
||||||
# Encodes the number 0x0400000000 as a subidentifier which overflows 32-bits
|
# Encodes the number 0x0400000000 as a subidentifier which overflows 32-bits
|
||||||
OID get numeric string - 32-bit overflow
|
OID get numeric string - 32-bit overflow
|
||||||
oid_get_numeric_string:"C080808000":MBEDTLS_ERR_OID_BUF_TOO_SMALL:""
|
oid_get_numeric_string:"C080808000":MBEDTLS_ERR_ASN1_INVALID_DATA:""
|
||||||
|
|
||||||
OID get numeric string - 32-bit overflow, second subidentifier
|
OID get numeric string - 32-bit overflow, second subidentifier
|
||||||
oid_get_numeric_string:"2BC080808000":MBEDTLS_ERR_OID_BUF_TOO_SMALL:""
|
oid_get_numeric_string:"2BC080808000":MBEDTLS_ERR_ASN1_INVALID_DATA:""
|
||||||
|
|
||||||
OID get numeric string - overlong encoding
|
OID get numeric string - overlong encoding
|
||||||
oid_get_numeric_string:"8001":MBEDTLS_ERR_OID_BUF_TOO_SMALL:""
|
oid_get_numeric_string:"8001":MBEDTLS_ERR_ASN1_INVALID_DATA:""
|
||||||
|
|
||||||
OID get numeric string - overlong encoding, second subidentifier
|
OID get numeric string - overlong encoding, second subidentifier
|
||||||
oid_get_numeric_string:"2B8001":MBEDTLS_ERR_OID_BUF_TOO_SMALL:""
|
oid_get_numeric_string:"2B8001":MBEDTLS_ERR_ASN1_INVALID_DATA:""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user