Increase buffer to 32 bytes to hold uint64_t completely and check for
overflows after multiplication with size modifiers.
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
CALLBACK(parse_bytes, bool,
uint64_t *out, chunk_t v)
{
- char buf[16], *end;
- unsigned long long l;
+ char buf[32], *end;
+ unsigned long long l, ll;
if (!vici_stringify(v, buf, sizeof(buf)))
{
return FALSE;
}
- l = strtoull(buf, &end, 0);
+ l = ll = strtoull(buf, &end, 0);
while (*end == ' ')
{
end++;
{
case 'g':
case 'G':
- l *= 1024;
+ ll *= 1024;
/* fall */
case 'm':
case 'M':
- l *= 1024;
+ ll *= 1024;
/* fall */
case 'k':
case 'K':
- l *= 1024;
+ ll *= 1024;
end++;
break;
case '\0':
{
return FALSE;
}
- *out = l;
+ *out = (ll < l) ? UINT64_MAX : ll;
return TRUE;
}