mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-10-16 18:56:56 +02:00
Fix dehumanize_number() to correctly detect overflows
Do not allow numbers greated than INT64_MAX and smaller than INT64_MIN. Clarify the positive sign value by prefixing it with an explicit +. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=66909
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
@@ -60,5 +61,17 @@ main(int argc, char **argv)
|
||||
assert(dehumanize_number("-3G", &val) == 0);
|
||||
assert(val == -3221225472LL);
|
||||
|
||||
assert(dehumanize_number("9223372036854775807", &val) == 0);
|
||||
assert(val == INT64_MAX);
|
||||
|
||||
assert(dehumanize_number("9223372036854775808", &val) == -1);
|
||||
assert(errno == ERANGE);
|
||||
|
||||
assert(dehumanize_number("-9223372036854775808", &val) == 0);
|
||||
assert(val == INT64_MIN);
|
||||
|
||||
assert(dehumanize_number("-9223372036854775809", &val) == -1);
|
||||
assert(errno == ERANGE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user