vici: Improve byte lifetime parsing

Increase buffer to 32 bytes to hold uint64_t completely and check for
overflows after multiplication with size modifiers.

Signed-off-by: Thomas Egerer <[email protected]>
This commit is contained in:
Thomas Egerer
2025-04-10 08:31:10 +02:00
committed by Tobias Brunner
parent 9fe58c83fb
commit ed8c08fbe7
+7 -7
View File
@@ -1271,15 +1271,15 @@ CALLBACK(parse_time32, bool,
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++;
@@ -1288,15 +1288,15 @@ CALLBACK(parse_bytes, bool,
{
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':
@@ -1308,7 +1308,7 @@ CALLBACK(parse_bytes, bool,
{
return FALSE;
}
*out = l;
*out = (ll < l) ? UINT64_MAX : ll;
return TRUE;
}