Commit Graph

14 Commits

Author SHA1 Message Date
Guy Harris cd6134da90 Add ws_strtoi() and ws_strtoui() routines and use them.
Those fetch gint and guint values, respectively, rather than values with
specified sizes in bits.

This should squelch Coverity CID 1457357.

Change-Id: Ia8f100bd3fe90c266e24a4346f80b2667c653b93
Reviewed-on: https://code.wireshark.org/review/36177
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2020-02-25 08:27:52 +00:00
Guy Harris 5e019c6b8f 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>
2018-10-19 20:30:53 +00:00
Dario Lombardo 8cd389e161 replace SPDX identifier GPL-2.0+ with GPL-2.0-or-later.
The first is deprecated, as per https://spdx.org/licenses/.

Change-Id: I8e21e1d32d09b8b94b93a2dc9fbdde5ffeba6bed
Reviewed-on: https://code.wireshark.org/review/25661
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-08 14:57:36 +00:00
Michael Mann 3d673da88c Convert to using use SPDX identifier on wsutil directory
Change-Id: Id73e641499e75bc1afc1dea29682418156f461fe
Reviewed-on: https://code.wireshark.org/review/24751
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-12-10 04:36:29 +00:00
Dario Lombardo 4863d813e9 wsutil: add initializer (found by clang ccc).
Warning:

wireshark/wsutil/strtoi.c:113:1: warning: The left operand of '<' is a garbage value
DEFINE_WS_STRTOI_BITS(32)
^~~~~~~~~~~~~~~~~~~~~~~~~
wireshark/wsutil/strtoi.c:83:12: note: expanded from macro 'DEFINE_WS_STRTOI_BITS'
                        if (val < 0) \
                            ~~~ ^
wireshark/wsutil/strtoi.c:114:1: warning: The left operand of '<' is a garbage value
DEFINE_WS_STRTOI_BITS(16)
^~~~~~~~~~~~~~~~~~~~~~~~~
wireshark/wsutil/strtoi.c:83:12: note: expanded from macro 'DEFINE_WS_STRTOI_BITS'
                        if (val < 0) \
                            ~~~ ^
wireshark/wsutil/strtoi.c:115:1: warning: The left operand of '<' is a garbage value
DEFINE_WS_STRTOI_BITS(8)
^~~~~~~~~~~~~~~~~~~~~~~~
wireshark/wsutil/strtoi.c:83:12: note: expanded from macro 'DEFINE_WS_STRTOI_BITS'
                        if (val < 0) \
                            ~~~ ^
3 warnings generated.

Change-Id: I9eef0f2c0d4500531655a8b43509205a1f4e0684
Reviewed-on: https://code.wireshark.org/review/18640
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
2016-11-03 08:32:18 +00:00
Dario Lombardo 94b4617aca wsutil: add check for input pointers to ws_strtoi functions.
Change-Id: I7353a3b00392aa606fad04ef76e8b18ffbabbf5e
Reviewed-on: https://code.wireshark.org/review/18449
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Dario Lombardo <lomato@gmail.com>
2016-10-27 12:33:41 +00:00
Guy Harris 770a8737d7 Add ws_hexstrtou{bits} and use ws_hexstrtou32 in androiddump.
Make the reply length unsigned - there's no reason for it to be signed.

Change-Id: I5f4d1f027eeddee939547c052220efb89800f4b1
Reviewed-on: https://code.wireshark.org/review/17740
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-09-16 17:42:03 +00:00
Peter Wu cea1737bd2 Let strtoi with NULL endptr require no invalid characters
If the caller is not interested in checking its end, then it probably
wants a valid number only if the string contains a valid number. Add a
shortcut for this.

Change-Id: I39701bd445e29fb2606720b18ca3764c74a7255b
Reviewed-on: https://code.wireshark.org/review/17658
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Reviewed-by: Dario Lombardo <lomato@gmail.com>
2016-09-12 16:00:52 +00:00
Guy Harris c7fc280222 Make the ws_strto* routines more like the strto* routines.
Not all uses of atoi() or various strto* routines in Wireshark expect
the string to contain *only* a number, so not all uses should require
that the byte after the number be a '\0'.  Have the ws_strto* routines
take a "pointer a pointer set to point to the character after the
number" argument, and have the callers do the appropriate checks of the
character after that.

This fixes the VMS trace reading code so that it can read those files
again.

The get_ routines are handed command-line arguments, so they *do* expect
the string to contain only a number; have them check to make sure the
byte after the number is a '\0'.

Change-Id: I46fc1bea7912b9278e385fe38491a0a2ad60d697
Reviewed-on: https://code.wireshark.org/review/17560
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-09-07 20:41:53 +00:00
Guy Harris 595610f9cc Always set *cint before returning.
Change-Id: I333aef7d3fe4ad3bf7c2a4d7318766fcbd2e4cd2
Reviewed-on: https://code.wireshark.org/review/17539
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-09-06 18:01:34 +00:00
Alexis La Goutte 36c8065cc3 strtoi(.c): fix extra ';' outside of a function [-Wextra-semi]
Change-Id: I2d92678b2117da732be309c2d430d0c97c7a7eed
Reviewed-on: https://code.wireshark.org/review/17528
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-09-06 12:41:19 +00:00
Guy Harris 9ef70fce3c Return the maximum or minimum value for ERANGE.
That way, for signed values, the caller knows whether ERANGE means "too
large" or "too small"; this is analogous to what the C routines return.

Change-Id: Ifc1fc4723733be606487093f8aa77ae2d89d2c40
Reviewed-on: https://code.wireshark.org/review/17512
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-09-06 02:05:41 +00:00
Guy Harris 97103d40e3 Check for signs in unsigned numbers and fail if we see one.
-1 is not an unsigned number.  For that matter, neither is +1;
"unsigned" means "without a sign", and they both have signs.

ANSI C's strto{whatever} routines - even the ones that supposedly are
for "unsigned" values - and the GLib routines modeled after them allow a
leading sign, so we have to check ourselves.

Change-Id: Ia0584bbf83394185cde88eec48efcdfa316f1c92
Reviewed-on: https://code.wireshark.org/review/17511
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-09-06 01:08:42 +00:00
Dario Lombardo ba981aced8 wsutil: add string to integer conversion utilities.
In the current code many functions have been used for convertion
(strtol, atoi, g_ascii_strtoll, etc). Those utilities want to be
the only, shared, way to convert integers.

Change-Id: I22ba1bf54e144e73a4728612a4437de5a2d339e2
Reviewed-on: https://code.wireshark.org/review/17414
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Roland Knall <rknall@gmail.com>
Reviewed-by: Dario Lombardo <lomato@gmail.com>
2016-09-05 09:54:12 +00:00