mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-27 06:41:08 +00:00
Make overflow checks more readable
Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
parent
21b8387929
commit
34b3f1b757
@ -844,7 +844,7 @@ int mbedtls_oid_get_numeric_string(char *buf, size_t size,
|
|||||||
|
|
||||||
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 << 7) >> 7) != value) {
|
if (value > (UINT_MAX >> 7)) {
|
||||||
return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
|
return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -873,7 +873,7 @@ int mbedtls_oid_get_numeric_string(char *buf, size_t size,
|
|||||||
value = 0;
|
value = 0;
|
||||||
for (; i < oid->len; i++) {
|
for (; i < oid->len; i++) {
|
||||||
/* Prevent overflow in value. */
|
/* Prevent overflow in value. */
|
||||||
if (((value << 7) >> 7) != value) {
|
if (value > (UINT_MAX >> 7)) {
|
||||||
return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
|
return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
|
||||||
}
|
}
|
||||||
if ((value == 0) && ((oid->p[i]) == 0x80)) {
|
if ((value == 0) && ((oid->p[i]) == 0x80)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user