<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18202">View Change</a></p><div style="white-space:pre-wrap">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
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">conversions.c: Specify that we only want to parse decimal numbers.<br><br>Passing 0 as the last argument to strtoimax() or strtoumax() causes<br>octal and hexadecimal to be accepted which was not originally<br>intended. So we now force to only accept decimal.<br><br>ASTERISK-29950 #close<br><br>Change-Id: I93baf0f273441e8280354630a463df263a8c0edd<br>---<br>M main/conversions.c<br>M tests/test_conversions.c<br>2 files changed, 14 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/conversions.c b/main/conversions.c</span><br><span>index 007e24d..4b58140 100644</span><br><span>--- a/main/conversions.c</span><br><span>+++ b/main/conversions.c</span><br><span>@@ -99,7 +99,7 @@</span><br><span> }</span><br><span> </span><br><span> errno = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- val = strtoimax(str, &end, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ val = strtoimax(str, &end, 10);</span><br><span> </span><br><span> /*</span><br><span> * If str equals end then no digits were found. If end is not pointing to</span><br><span>@@ -126,7 +126,7 @@</span><br><span> }</span><br><span> </span><br><span> errno = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- val = strtoumax(str, &end, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ val = strtoumax(str, &end, 10);</span><br><span> </span><br><span> /*</span><br><span> * If str equals end then no digits were found. If end is not pointing to</span><br><span>diff --git a/tests/test_conversions.c b/tests/test_conversions.c</span><br><span>index f49c8e6..7ec1731 100644</span><br><span>--- a/tests/test_conversions.c</span><br><span>+++ b/tests/test_conversions.c</span><br><span>@@ -48,6 +48,7 @@</span><br><span> const char *spaces = " ";</span><br><span> const char *valid = "7";</span><br><span> const char *valid_spaces = " 7";</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *valid_decimal = "08";</span><br><span> int val;</span><br><span> char str[64];</span><br><span> </span><br><span>@@ -73,6 +74,7 @@</span><br><span> ast_test_validate(test, ast_str_to_int(spaces, &val));</span><br><span> ast_test_validate(test, !ast_str_to_int(valid, &val));</span><br><span> ast_test_validate(test, !ast_str_to_int(valid_spaces, &val));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_str_to_int(valid_decimal, &val));</span><br><span> </span><br><span> ast_test_validate(test, snprintf(str, sizeof(str), "%d", INT_MAX) > 0);</span><br><span> ast_test_validate(test, !ast_str_to_int(str, &val));</span><br><span>@@ -95,6 +97,7 @@</span><br><span> const char *spaces = " ";</span><br><span> const char *valid = "7";</span><br><span> const char *valid_spaces = " 7";</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *valid_decimal = "08";</span><br><span> unsigned int val;</span><br><span> char str[64];</span><br><span> </span><br><span>@@ -119,6 +122,7 @@</span><br><span> ast_test_validate(test, ast_str_to_uint(spaces, &val));</span><br><span> ast_test_validate(test, !ast_str_to_uint(valid, &val));</span><br><span> ast_test_validate(test, !ast_str_to_uint(valid_spaces, &val));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_str_to_uint(valid_decimal, &val));</span><br><span> </span><br><span> ast_test_validate(test, snprintf(str, sizeof(str), "%u", UINT_MAX) > 0);</span><br><span> ast_test_validate(test, !ast_str_to_uint(str, &val));</span><br><span>@@ -138,6 +142,7 @@</span><br><span> const char *spaces = " ";</span><br><span> const char *valid = "7";</span><br><span> const char *valid_spaces = " 7";</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *valid_decimal = "08";</span><br><span> long val;</span><br><span> char str[64];</span><br><span> </span><br><span>@@ -163,6 +168,7 @@</span><br><span> ast_test_validate(test, ast_str_to_long(spaces, &val));</span><br><span> ast_test_validate(test, !ast_str_to_long(valid, &val));</span><br><span> ast_test_validate(test, !ast_str_to_long(valid_spaces, &val));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_str_to_long(valid_decimal, &val));</span><br><span> </span><br><span> ast_test_validate(test, snprintf(str, sizeof(str), "%ld", LONG_MAX) > 0);</span><br><span> ast_test_validate(test, !ast_str_to_long(str, &val));</span><br><span>@@ -185,6 +191,7 @@</span><br><span> const char *spaces = " ";</span><br><span> const char *valid = "7";</span><br><span> const char *valid_spaces = " 7";</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *valid_decimal = "08";</span><br><span> unsigned long val;</span><br><span> char str[64];</span><br><span> </span><br><span>@@ -209,6 +216,7 @@</span><br><span> ast_test_validate(test, ast_str_to_ulong(spaces, &val));</span><br><span> ast_test_validate(test, !ast_str_to_ulong(valid, &val));</span><br><span> ast_test_validate(test, !ast_str_to_ulong(valid_spaces, &val));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_str_to_ulong(valid_decimal, &val));</span><br><span> </span><br><span> ast_test_validate(test, snprintf(str, sizeof(str), "%lu", ULONG_MAX) > 0);</span><br><span> ast_test_validate(test, !ast_str_to_ulong(str, &val));</span><br><span>@@ -228,6 +236,7 @@</span><br><span> const char *spaces = " ";</span><br><span> const char *valid = "7";</span><br><span> const char *valid_spaces = " 7";</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *valid_decimal = "08";</span><br><span> intmax_t val;</span><br><span> char str[64];</span><br><span> </span><br><span>@@ -253,6 +262,7 @@</span><br><span> ast_test_validate(test, ast_str_to_imax(spaces, &val));</span><br><span> ast_test_validate(test, !ast_str_to_imax(valid, &val));</span><br><span> ast_test_validate(test, !ast_str_to_imax(valid_spaces, &val));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_str_to_imax(valid_decimal, &val));</span><br><span> </span><br><span> ast_test_validate(test, snprintf(str, sizeof(str), "%jd", INTMAX_MAX) > 0);</span><br><span> ast_test_validate(test, !ast_str_to_imax(str, &val));</span><br><span>@@ -276,6 +286,7 @@</span><br><span> const char *spaces = " ";</span><br><span> const char *valid = "7";</span><br><span> const char *valid_spaces = " 7";</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *valid_decimal = "08";</span><br><span> uintmax_t val;</span><br><span> char str[64];</span><br><span> </span><br><span>@@ -300,6 +311,7 @@</span><br><span> ast_test_validate(test, ast_str_to_umax(spaces, &val));</span><br><span> ast_test_validate(test, !ast_str_to_umax(valid, &val));</span><br><span> ast_test_validate(test, !ast_str_to_umax(valid_spaces, &val));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_str_to_umax(valid_decimal, &val));</span><br><span> </span><br><span> ast_test_validate(test, snprintf(str, sizeof(str), "%ju", UINTMAX_MAX) > 0);</span><br><span> ast_test_validate(test, !ast_str_to_umax(str, &val));</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18202">change 18202</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/18202"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I93baf0f273441e8280354630a463df263a8c0edd </div>
<div style="display:none"> Gerrit-Change-Number: 18202 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean@seanbright.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>