summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-09-04 14:36:36 +0200
committerThomas Haller <thaller@redhat.com>2017-09-05 18:44:04 +0200
commit69ccbb75138a5f188cc4fd8f7f92b3ed1d19108b (patch)
tree19ece3ca9b96063d2639bee26adf89c7e6ae890e
parentccc2af0efb4b3c01188552d0d4b041c9cc88d185 (diff)
downloadNetworkManager-69ccbb75138a5f188cc4fd8f7f92b3ed1d19108b.tar.gz
tui: avoid integer overflow checking the range in NmtNewtEntryNumeric
strtoul() operates on "unsigned long" while NmtNewtEntryNumeric uses "int". strtoul() might indicate that the text is a valid "unsigned long", however, then casting to "int" might lead to truncation of the number and wrong range check. Also, the type supposedly handles negative integers as well. Not with strtoul().
-rw-r--r--clients/tui/newt/nmt-newt-entry-numeric.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/clients/tui/newt/nmt-newt-entry-numeric.c b/clients/tui/newt/nmt-newt-entry-numeric.c
index 1492bf2047..f0eceb5ffe 100644
--- a/clients/tui/newt/nmt-newt-entry-numeric.c
+++ b/clients/tui/newt/nmt-newt-entry-numeric.c
@@ -123,18 +123,12 @@ newt_entry_numeric_validate (NmtNewtEntry *entry,
{
NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE (entry);
int val;
- char *end;
if (!*text)
return priv->optional ? TRUE : FALSE;
- val = strtoul (text, &end, 10);
- if (*end)
- return FALSE;
- if (val < priv->min || val > priv->max)
- return FALSE;
-
- return TRUE;
+ val = _nm_utils_ascii_str_to_int64 (text, 10, priv->min, priv->max, 0);
+ return val != 0 || errno == 0;
}
static void