mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-02 19:16:15 +00:00
strings.c: Improve numeric detection in ast_strings_match()
.
Essentially, we were treating 1234x1234 and 1234x5678 as 'equal'
because we were able to convert the prefix of each of these strings to
the same number.
Resolves: #1028
(cherry picked from commit 813b774cc1
)
This commit is contained in:
committed by
Asterisk Development Team
parent
24c077f1fb
commit
8b62a1c8a9
@@ -244,6 +244,19 @@ int ast_strings_equal(const char *str1, const char *str2)
|
|||||||
return str1 == str2 || !strcmp(str1, str2);
|
return str1 == str2 || !strcmp(str1, str2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int parse_double(const char *input, double *result)
|
||||||
|
{
|
||||||
|
char *endptr;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
*result = strtod(input, &endptr);
|
||||||
|
if (*endptr || errno == ERANGE) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int ast_strings_match(const char *left, const char *op, const char *right)
|
int ast_strings_match(const char *left, const char *op, const char *right)
|
||||||
{
|
{
|
||||||
char *internal_op = (char *)op;
|
char *internal_op = (char *)op;
|
||||||
@@ -311,7 +324,8 @@ regex:
|
|||||||
}
|
}
|
||||||
|
|
||||||
equals:
|
equals:
|
||||||
scan_numeric = (sscanf(left, "%lf", &left_num) > 0 && sscanf(internal_right, "%lf", &right_num) > 0);
|
scan_numeric = parse_double(left, &left_num)
|
||||||
|
&& parse_double(internal_right, &right_num);
|
||||||
|
|
||||||
if (internal_op[0] == '=') {
|
if (internal_op[0] == '=') {
|
||||||
if (ast_strlen_zero(left) && ast_strlen_zero(internal_right)) {
|
if (ast_strlen_zero(left) && ast_strlen_zero(internal_right)) {
|
||||||
|
@@ -717,6 +717,9 @@ AST_TEST_DEFINE(strings_match)
|
|||||||
ast_test_validate(test, !ast_strings_match(NULL, NULL, "abc"));
|
ast_test_validate(test, !ast_strings_match(NULL, NULL, "abc"));
|
||||||
ast_test_validate(test, !ast_strings_match(NULL, NULL, NULL));
|
ast_test_validate(test, !ast_strings_match(NULL, NULL, NULL));
|
||||||
|
|
||||||
|
/* See https://github.com/asterisk/asterisk/issues/1028 */
|
||||||
|
ast_test_validate(test, !ast_strings_match("123456789c1", NULL, "123456789c2"));
|
||||||
|
|
||||||
return AST_TEST_PASS;
|
return AST_TEST_PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user