[Asterisk-code-review] conversions.c: Specify that we only want to parse decimal numbers. (asterisk[master])
Friendly Automation
asteriskteam at digium.com
Wed Mar 23 17:13:04 CDT 2022
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/18204 )
Change subject: conversions.c: Specify that we only want to parse decimal numbers.
......................................................................
conversions.c: Specify that we only want to parse decimal numbers.
Passing 0 as the last argument to strtoimax() or strtoumax() causes
octal and hexadecimal to be accepted which was not originally
intended. So we now force to only accept decimal.
ASTERISK-29950 #close
Change-Id: I93baf0f273441e8280354630a463df263a8c0edd
---
M main/conversions.c
M tests/test_conversions.c
2 files changed, 14 insertions(+), 2 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Benjamin Keith Ford: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/main/conversions.c b/main/conversions.c
index 007e24d..4b58140 100644
--- a/main/conversions.c
+++ b/main/conversions.c
@@ -99,7 +99,7 @@
}
errno = 0;
- val = strtoimax(str, &end, 0);
+ val = strtoimax(str, &end, 10);
/*
* If str equals end then no digits were found. If end is not pointing to
@@ -126,7 +126,7 @@
}
errno = 0;
- val = strtoumax(str, &end, 0);
+ val = strtoumax(str, &end, 10);
/*
* If str equals end then no digits were found. If end is not pointing to
diff --git a/tests/test_conversions.c b/tests/test_conversions.c
index f49c8e6..7ec1731 100644
--- a/tests/test_conversions.c
+++ b/tests/test_conversions.c
@@ -48,6 +48,7 @@
const char *spaces = " ";
const char *valid = "7";
const char *valid_spaces = " 7";
+ const char *valid_decimal = "08";
int val;
char str[64];
@@ -73,6 +74,7 @@
ast_test_validate(test, ast_str_to_int(spaces, &val));
ast_test_validate(test, !ast_str_to_int(valid, &val));
ast_test_validate(test, !ast_str_to_int(valid_spaces, &val));
+ ast_test_validate(test, !ast_str_to_int(valid_decimal, &val));
ast_test_validate(test, snprintf(str, sizeof(str), "%d", INT_MAX) > 0);
ast_test_validate(test, !ast_str_to_int(str, &val));
@@ -95,6 +97,7 @@
const char *spaces = " ";
const char *valid = "7";
const char *valid_spaces = " 7";
+ const char *valid_decimal = "08";
unsigned int val;
char str[64];
@@ -119,6 +122,7 @@
ast_test_validate(test, ast_str_to_uint(spaces, &val));
ast_test_validate(test, !ast_str_to_uint(valid, &val));
ast_test_validate(test, !ast_str_to_uint(valid_spaces, &val));
+ ast_test_validate(test, !ast_str_to_uint(valid_decimal, &val));
ast_test_validate(test, snprintf(str, sizeof(str), "%u", UINT_MAX) > 0);
ast_test_validate(test, !ast_str_to_uint(str, &val));
@@ -138,6 +142,7 @@
const char *spaces = " ";
const char *valid = "7";
const char *valid_spaces = " 7";
+ const char *valid_decimal = "08";
long val;
char str[64];
@@ -163,6 +168,7 @@
ast_test_validate(test, ast_str_to_long(spaces, &val));
ast_test_validate(test, !ast_str_to_long(valid, &val));
ast_test_validate(test, !ast_str_to_long(valid_spaces, &val));
+ ast_test_validate(test, !ast_str_to_long(valid_decimal, &val));
ast_test_validate(test, snprintf(str, sizeof(str), "%ld", LONG_MAX) > 0);
ast_test_validate(test, !ast_str_to_long(str, &val));
@@ -185,6 +191,7 @@
const char *spaces = " ";
const char *valid = "7";
const char *valid_spaces = " 7";
+ const char *valid_decimal = "08";
unsigned long val;
char str[64];
@@ -209,6 +216,7 @@
ast_test_validate(test, ast_str_to_ulong(spaces, &val));
ast_test_validate(test, !ast_str_to_ulong(valid, &val));
ast_test_validate(test, !ast_str_to_ulong(valid_spaces, &val));
+ ast_test_validate(test, !ast_str_to_ulong(valid_decimal, &val));
ast_test_validate(test, snprintf(str, sizeof(str), "%lu", ULONG_MAX) > 0);
ast_test_validate(test, !ast_str_to_ulong(str, &val));
@@ -228,6 +236,7 @@
const char *spaces = " ";
const char *valid = "7";
const char *valid_spaces = " 7";
+ const char *valid_decimal = "08";
intmax_t val;
char str[64];
@@ -253,6 +262,7 @@
ast_test_validate(test, ast_str_to_imax(spaces, &val));
ast_test_validate(test, !ast_str_to_imax(valid, &val));
ast_test_validate(test, !ast_str_to_imax(valid_spaces, &val));
+ ast_test_validate(test, !ast_str_to_imax(valid_decimal, &val));
ast_test_validate(test, snprintf(str, sizeof(str), "%jd", INTMAX_MAX) > 0);
ast_test_validate(test, !ast_str_to_imax(str, &val));
@@ -276,6 +286,7 @@
const char *spaces = " ";
const char *valid = "7";
const char *valid_spaces = " 7";
+ const char *valid_decimal = "08";
uintmax_t val;
char str[64];
@@ -300,6 +311,7 @@
ast_test_validate(test, ast_str_to_umax(spaces, &val));
ast_test_validate(test, !ast_str_to_umax(valid, &val));
ast_test_validate(test, !ast_str_to_umax(valid_spaces, &val));
+ ast_test_validate(test, !ast_str_to_umax(valid_decimal, &val));
ast_test_validate(test, snprintf(str, sizeof(str), "%ju", UINTMAX_MAX) > 0);
ast_test_validate(test, !ast_str_to_umax(str, &val));
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18204
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I93baf0f273441e8280354630a463df263a8c0edd
Gerrit-Change-Number: 18204
Gerrit-PatchSet: 3
Gerrit-Owner: Sean Bright <sean at seanbright.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220323/0f528cba/attachment-0001.html>
More information about the asterisk-code-review
mailing list