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, CALLBACK(parse_bytes, bool,
uint64_t *out, chunk_t v) uint64_t *out, chunk_t v)
{ {
char buf[16], *end; char buf[32], *end;
unsigned long long l; unsigned long long l, ll;
if (!vici_stringify(v, buf, sizeof(buf))) if (!vici_stringify(v, buf, sizeof(buf)))
{ {
return FALSE; return FALSE;
} }
l = strtoull(buf, &end, 0); l = ll = strtoull(buf, &end, 0);
while (*end == ' ') while (*end == ' ')
{ {
end++; end++;
@@ -1288,15 +1288,15 @@ CALLBACK(parse_bytes, bool,
{ {
case 'g': case 'g':
case 'G': case 'G':
l *= 1024; ll *= 1024;
/* fall */ /* fall */
case 'm': case 'm':
case 'M': case 'M':
l *= 1024; ll *= 1024;
/* fall */ /* fall */
case 'k': case 'k':
case 'K': case 'K':
l *= 1024; ll *= 1024;
end++; end++;
break; break;
case '\0': case '\0':
@@ -1308,7 +1308,7 @@ CALLBACK(parse_bytes, bool,
{ {
return FALSE; return FALSE;
} }
*out = l; *out = (ll < l) ? UINT64_MAX : ll;
return TRUE; return TRUE;
} }