Skip to content

Commit ee7043a

Browse files
committed
Guard TFTP numeric option parse against 32-bit overflow
1 parent 632e2c7 commit ee7043a

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/tftp/wolftftp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,17 @@ static int wolftftp_parse_u32(const char *value, uint32_t max_value,
9494
uint32_t *out)
9595
{
9696
uint32_t v = 0;
97+
uint32_t digit;
9798

9899
if (value == NULL || out == NULL || *value == '\0')
99100
return -1;
100101
while (*value != '\0') {
101102
if (*value < '0' || *value > '9')
102103
return -1;
103-
v = (v * 10U) + (uint32_t)(*value - '0');
104+
digit = (uint32_t)(*value - '0');
105+
if (v > (0xFFFFFFFFU - digit) / 10U)
106+
return -1;
107+
v = (v * 10U) + digit;
104108
if (v > max_value)
105109
return -1;
106110
value++;

0 commit comments

Comments
 (0)