diff options
author | Bill Meier <wmeier@newsguy.com> | 2014-11-18 22:53:32 -0500 |
---|---|---|
committer | Alexis La Goutte <alexis.lagoutte@gmail.com> | 2014-11-20 13:47:13 +0000 |
commit | 9145acb68ac5485d9abe9be23d02964755890c67 (patch) | |
tree | d7cdc160a8b8449fc43166691c2cb11c11344d08 /epan/uat.c | |
parent | ead585fda74edcde8ceac44f014fa844c29a27ce (diff) |
uat: tighten up dec/hex uat field validity checking
Specifically:
- Use the proper code for testing strtol() result;
- Also: Values greater than 32-bits treated as an error
(on LP64 architectures);
Change-Id: I56e8e734fbb9a22dbd9ed4112e24327ffd7ee3c0
Reviewed-on: https://code.wireshark.org/review/5394
Reviewed-by: Bill Meier <wmeier@newsguy.com>
Petri-Dish: Bill Meier <wmeier@newsguy.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Diffstat (limited to 'epan/uat.c')
-rw-r--r-- | epan/uat.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/epan/uat.c b/epan/uat.c index 076ac48e5a..824e64d5a2 100644 --- a/epan/uat.c +++ b/epan/uat.c @@ -497,34 +497,41 @@ gboolean uat_fld_chk_proto(void* u1 _U_, const char* strptr, guint len, const vo } } -gboolean uat_fld_chk_num_dec(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, const char** err) { +static gboolean uat_fld_chk_num(int base, const char* strptr, guint len, const char** err) { if (len > 0) { char* str = ep_strndup(strptr,len); - long i = strtol(str,&str,10); + char* strn; + long i; + + errno = 0; + i = strtol(str,&strn,base); - if ( ( i == 0) && (errno == ERANGE || errno == EINVAL) ) { + if (((i == G_MAXLONG || i == G_MINLONG) && errno == ERANGE) + || (errno != 0 && i == 0)) { *err = g_strerror(errno); return FALSE; } + if ((*strn != '\0') && (*strn != ' ')) { + *err = "Invalid value"; + return FALSE; + } + /* Allow only 32bit values */ + if ((sizeof(long) > 4) && ((i < G_MININT) || (i > G_MAXINT))) { + *err = "Value too large"; + return FALSE; + } } *err = NULL; return TRUE; } -gboolean uat_fld_chk_num_hex(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, const char** err) { - if (len > 0) { - char* str = ep_strndup(strptr,len); - long i = strtol(str,&str,16); - - if ( ( i == 0) && (errno == ERANGE || errno == EINVAL) ) { - *err = g_strerror(errno); - return FALSE; - } - } +gboolean uat_fld_chk_num_dec(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, const char** err) { + return uat_fld_chk_num(10, strptr, len, err); +} - *err = NULL; - return TRUE; +gboolean uat_fld_chk_num_hex(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, const char** err) { + return uat_fld_chk_num(16, strptr, len, err); } gboolean uat_fld_chk_enum(void* u1 _U_, const char* strptr, guint len, const void* v, const void* u3 _U_, const char** err) { |