aboutsummaryrefslogtreecommitdiffstats
path: root/epan/range.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-10-19 13:28:05 -0700
committerGuy Harris <guy@alum.mit.edu>2018-10-19 20:30:53 +0000
commit5e019c6b8fd01c1d0fe432ad99401612b87c5a36 (patch)
treeaae1076a42499bd4249388bf013979dd3f72fa8a /epan/range.c
parent075ef8029c0b8054383272d113629c4386d22ca6 (diff)
Use ws_basetostru32(), rather than strtoul(), when parsing ranges.
Make ws_basetostru32(), and the other ws_baseto... routines, public, and use ws_basetostru32() when parsing ranges, to detect additional errors such as negative values. Addresses part of https://ask.wireshark.org/question/5538/preference-range/. Change-Id: I00fac97a198a237b01b5cd9406ea32c220f80972 Reviewed-on: https://code.wireshark.org/review/30266 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/range.c')
-rw-r--r--epan/range.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/epan/range.c b/epan/range.c
index 7bbf4f8c70..0dce529554 100644
--- a/epan/range.c
+++ b/epan/range.c
@@ -13,6 +13,7 @@
#include "config.h"
+#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
@@ -22,7 +23,8 @@
#include <epan/frame_data.h>
#include <epan/range.h>
-#include <stdio.h>
+
+#include <wsutil/strtoi.h>
/*
* Size of the header of a range_t.
@@ -84,11 +86,11 @@ range_convert_str_work(wmem_allocator_t *scope, range_t **rangep, const gchar *e
range_t *range;
guint nranges;
const gchar *p;
- char *endp;
+ const char *endp;
gchar c;
guint i;
guint32 tmp;
- unsigned long val;
+ guint32 val;
if ( (rangep == NULL) || (es == NULL) )
return CVT_SYNTAX_ERROR;
@@ -135,8 +137,8 @@ range_convert_str_work(wmem_allocator_t *scope, range_t **rangep, const gchar *e
} else if (g_ascii_isdigit(c)) {
/* Subrange starts with the specified number */
errno = 0;
- val = strtoul(p, &endp, 0);
- if (p == endp) {
+ ws_basestrtou32(p, &endp, &val, 0);
+ if (errno == EINVAL) {
/* That wasn't a valid number. */
wmem_free(scope, range);
return CVT_SYNTAX_ERROR;
@@ -181,8 +183,8 @@ range_convert_str_work(wmem_allocator_t *scope, range_t **rangep, const gchar *e
} else if (g_ascii_isdigit(c)) {
/* Subrange ends with the specified number. */
errno = 0;
- val = strtoul(p, &endp, 0);
- if (p == endp) {
+ ws_basestrtou32(p, &endp, &val, 0);
+ if (errno == EINVAL) {
/* That wasn't a valid number. */
wmem_free(scope, range);
return CVT_SYNTAX_ERROR;