aboutsummaryrefslogtreecommitdiffstats
path: root/epan/uat.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-10-20 13:36:56 -0700
committerGuy Harris <guy@alum.mit.edu>2018-10-20 21:03:51 +0000
commit8652762738f1bc4a4b5bac221463bb77718b6531 (patch)
tree59509a96fc8377553d3e82e23780ad9fa342980e /epan/uat.c
parente0401ad15b6b2c0da2ec6cbf96a1dd63b2c278e8 (diff)
Separate signed and unsigned decimal UAT fields.
Most of them are unsigned; do the appropriate fetching, checking, and writing-to-UAT-file for them. Have separate macros and routines for the one signed one, which is the drbid in the LTE MAC dissector. Use the Wireshark string-to-number routines; they do the appropriate bounds checking, and make sure unsigned numbers don't start with a -. Change-Id: I4f137aa31d631c5b5622b2c320574b8ab3333f31 Reviewed-on: https://code.wireshark.org/review/30288 Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/uat.c')
-rw-r--r--epan/uat.c58
1 files changed, 33 insertions, 25 deletions
diff --git a/epan/uat.c b/epan/uat.c
index 893d91eb3b..fb88ab7b56 100644
--- a/epan/uat.c
+++ b/epan/uat.c
@@ -606,32 +606,36 @@ gboolean uat_fld_chk_proto(void* u1 _U_, const char* strptr, guint len, const vo
static gboolean uat_fld_chk_num(int base, const char* strptr, guint len, char** err) {
if (len > 0) {
- char* str = g_strndup(strptr,len);
- char* strn;
- long i;
-
- errno = 0;
- i = strtol(str,&strn,base);
+ char* str = g_strndup(strptr, len);
+ const char* strn;
+ gboolean result;
+ guint32 value;
- if (((i == G_MAXLONG || i == G_MINLONG) && errno == ERANGE)
- || (errno != 0 && i == 0)) {
- *err = g_strdup(g_strerror(errno));
- g_free(str);
- return FALSE;
- }
- if ((*strn != '\0') && (*strn != ' ')) {
- *err = g_strdup("Invalid value");
- g_free(str);
- return FALSE;
- }
- /* Allow only 32bit values */
- if ((sizeof(long) > 4) && ((i < G_MININT) || (i > G_MAXINT))) {
- *err = g_strdup("Value too large");
- g_free(str);
- return FALSE;
+ result = ws_basestrtou32(str, &strn, &value, base);
+ 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);
+
+ return result;
}
*err = NULL;
@@ -643,13 +647,17 @@ 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) {
+ return uat_fld_chk_num(16, strptr, len, err);
+}
+
+gboolean uat_fld_chk_num_signed_dec(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);
+ char* str = g_strndup(strptr,len);
const char* strn;
gboolean result;
- guint32 value;
+ gint32 value;
- result = ws_hexstrtou32(str, &strn, &value);
+ result = ws_strtoi32(str, &strn, &value);
if (result && ((*strn != '\0') && (*strn != ' '))) {
/* string valid, but followed by something other than a space */
result = FALSE;