diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-09-05 18:08:08 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-09-06 01:08:42 +0000 |
commit | 97103d40e36134436f96cc5efd06bbf2eccf734b (patch) | |
tree | 03af46a3d94b89a59bfccbe797365173784733de /wsutil/strtoi.c | |
parent | 4adf7f2be5b9132a0aef3e8f8f57ed525cff2e8e (diff) |
Check for signs in unsigned numbers and fail if we see one.
-1 is not an unsigned number. For that matter, neither is +1;
"unsigned" means "without a sign", and they both have signs.
ANSI C's strto{whatever} routines - even the ones that supposedly are
for "unsigned" values - and the GLib routines modeled after them allow a
leading sign, so we have to check ourselves.
Change-Id: Ia0584bbf83394185cde88eec48efcdfa316f1c92
Reviewed-on: https://code.wireshark.org/review/17511
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wsutil/strtoi.c')
-rw-r--r-- | wsutil/strtoi.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/wsutil/strtoi.c b/wsutil/strtoi.c index 574743d6b5..85897af026 100644 --- a/wsutil/strtoi.c +++ b/wsutil/strtoi.c @@ -53,6 +53,13 @@ gboolean ws_strtou64(const gchar* str, guint64* cint) gchar* endptr; guint64 val; + if (str[0] == '-' || str[0] == '+') { + /* + * Unsigned numbers don't have a sign. + */ + errno = EINVAL; + return FALSE; + } errno = 0; val = g_ascii_strtoull(str, &endptr, 10); if ((val == 0 && endptr == str) || (*endptr != 0)) { |