diff options
-rw-r--r-- | doc/HISTORY | 3 | ||||
-rw-r--r-- | lib/util/shhopt.c | 10 |
2 files changed, 10 insertions, 3 deletions
diff --git a/doc/HISTORY b/doc/HISTORY index c708e232..36845eda 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -24,6 +24,9 @@ not yet BJH Release 10.38.0 giftopnm: Add -repair option. + libnetpbm: shhopt: reject signed number as value for + OPT_UINT option. + libnetpbm: in the "no such option" error message, say what the valid options are. diff --git a/lib/util/shhopt.c b/lib/util/shhopt.c index efb9b794..718186fa 100644 --- a/lib/util/shhopt.c +++ b/lib/util/shhopt.c @@ -430,13 +430,17 @@ optExecute(optEntry const opt, char *arg, int lng) case OPT_UINT: case OPT_ULONG: { unsigned long tmp; - char *e; + char * tailPtr; if (arg == NULL) optFatal("internal error: optExecute() called with NULL argument " "'%s'", optString(opt, lng)); - tmp = strtoul(arg, &e, 10); - if (*e) + + if (arg[0] == '-' || arg[1] == '+') + optFatal("unsigned number '%s' has a sign ('%c')", + arg, arg[0]); + tmp = strtoul(arg, &tailPtr, 10); + if (*tailPtr) optFatal("invalid number `%s'", arg); if (errno == ERANGE || (opt.type == OPT_UINT && tmp > UINT_MAX)) |