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>
This commit is contained in:
Bill Meier 2014-11-18 22:53:32 -05:00 committed by Alexis La Goutte
parent ead585fda7
commit 9145acb68a
1 changed files with 22 additions and 15 deletions

View File

@ -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;
if ( ( i == 0) && (errno == ERANGE || errno == EINVAL) ) {
errno = 0;
i = strtol(str,&strn,base);
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_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);
}
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;
}
}
*err = NULL;
return TRUE;
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) {