diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-10-19 22:57:35 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-10-20 05:59:41 +0000 |
commit | e317421aaaec5767ef4b3757002215028ede04df (patch) | |
tree | 42b9433d9b61bc21fc29745a97e8a2e2abf1603e /epan/uat.c | |
parent | 3fdc40f434626ef7791288d244277ab1a0b06035 (diff) |
Make uat_fld_chk_num_hex() more like other uat_fld_chk_num routines.
Allow a space after the number.
Return "Invalid value" for strings that aren't valid numbers and "Value
too large" for values that don't fit in a 32-bit integer.
Change-Id: Iff616330968bf434fc7daf822a09ffc4f768105b
Reviewed-on: https://code.wireshark.org/review/30272
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/uat.c')
-rw-r--r-- | epan/uat.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/epan/uat.c b/epan/uat.c index 43315e9419..893d91eb3b 100644 --- a/epan/uat.c +++ b/epan/uat.c @@ -645,13 +645,31 @@ gboolean uat_fld_chk_num_dec(void* u1 _U_, const char* strptr, guint len, const gboolean uat_fld_chk_num_hex(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err) { if (len > 0) { char* str = g_strndup(strptr, len); + const char* strn; gboolean result; guint32 value; - errno = 0; - result = ws_hexstrtou32(str, NULL, &value); - if (errno != 0) { - *err = g_strdup(g_strerror(errno)); + result = ws_hexstrtou32(str, &strn, &value); + if (result && ((*strn != '\0') && (*strn != ' '))) { + /* string valid, but followed by something other than a space */ + result = FALSE; + errno = EINVAL; + } + if (!result) { + switch (errno) { + + case EINVAL: + *err = g_strdup("Invalid value"); + break; + + case ERANGE: + *err = g_strdup("Value too large"); + break; + + default: + *err = g_strdup(g_strerror(errno)); + break; + } } g_free(str); |