mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 20:20:07 +00:00
Fix expression handling for string comparisions without quotes (bug #4478)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5919 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -32,6 +32,7 @@ struct val {
|
|||||||
|
|
||||||
#define SET_COLUMNS yylloc_param->first_column = (int)(yyg->yytext_r - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf);yylloc_param->last_column = yylloc_param->last_column + yyleng - 1; yylloc_param->first_line = yylloc_param->last_line = 1
|
#define SET_COLUMNS yylloc_param->first_column = (int)(yyg->yytext_r - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf);yylloc_param->last_column = yylloc_param->last_column + yyleng - 1; yylloc_param->first_line = yylloc_param->last_line = 1
|
||||||
#define SET_STRING yylval_param->val = (struct val *)calloc(sizeof(struct val),1); yylval_param->val->type = AST_EXPR_string; yylval_param->val->u.s = strdup(yytext);
|
#define SET_STRING yylval_param->val = (struct val *)calloc(sizeof(struct val),1); yylval_param->val->type = AST_EXPR_string; yylval_param->val->u.s = strdup(yytext);
|
||||||
|
#define SET_NUMERIC_STRING yylval_param->val = (struct val *)calloc(sizeof(struct val),1); yylval_param->val->type = AST_EXPR_numeric_string; yylval_param->val->u.s = strdup(yytext);
|
||||||
|
|
||||||
struct parse_io
|
struct parse_io
|
||||||
{
|
{
|
||||||
@@ -74,10 +75,8 @@ struct parse_io
|
|||||||
\"[^"]*\" {SET_COLUMNS; SET_STRING; return TOKEN;}
|
\"[^"]*\" {SET_COLUMNS; SET_STRING; return TOKEN;}
|
||||||
|
|
||||||
[\n] {/* what to do with eol */}
|
[\n] {/* what to do with eol */}
|
||||||
[0-9]+ { SET_COLUMNS;
|
[0-9]+ { SET_COLUMNS; /* the original behavior of the expression parser was to bring in numbers as a numeric string */
|
||||||
yylval_param->val = (struct val *)calloc(sizeof(struct val),1);
|
SET_NUMERIC_STRING;
|
||||||
yylval_param->val->type = AST_EXPR_integer;
|
|
||||||
yylval_param->val->u.i = atoi(yytext);
|
|
||||||
return TOKEN;}
|
return TOKEN;}
|
||||||
[a-zA-Z0-9,.?';{}\\_^%$#@!]+ {SET_COLUMNS; SET_STRING; return TOKEN;}
|
[a-zA-Z0-9,.?';{}\\_^%$#@!]+ {SET_COLUMNS; SET_STRING; return TOKEN;}
|
||||||
|
|
||||||
|
12
ast_expr2.y
12
ast_expr2.y
@@ -296,10 +296,11 @@ to_integer (struct val *vp)
|
|||||||
|
|
||||||
/* vp->type == AST_EXPR_numeric_string, make it numeric */
|
/* vp->type == AST_EXPR_numeric_string, make it numeric */
|
||||||
errno = 0;
|
errno = 0;
|
||||||
i = strtoq(vp->u.s, (char**)NULL, 10);
|
i = strtoll(vp->u.s, (char**)NULL, 10);
|
||||||
if (errno != 0) {
|
if (errno != 0) {
|
||||||
|
ast_log(LOG_WARNING,"Conversion of %s to integer under/overflowed!\n", vp->u.s);
|
||||||
free(vp->u.s);
|
free(vp->u.s);
|
||||||
ast_log(LOG_WARNING,"overflow\n");
|
vp->u.s = 0;
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
free (vp->u.s);
|
free (vp->u.s);
|
||||||
@@ -433,8 +434,15 @@ op_eq (struct val *a, struct val *b)
|
|||||||
to_string (b);
|
to_string (b);
|
||||||
r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) == 0));
|
r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) == 0));
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef DEBUG_FOR_CONVERSIONS
|
||||||
|
char buffer[2000];
|
||||||
|
sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
|
||||||
|
#endif
|
||||||
(void)to_integer(a);
|
(void)to_integer(a);
|
||||||
(void)to_integer(b);
|
(void)to_integer(b);
|
||||||
|
#ifdef DEBUG_FOR_CONVERSIONS
|
||||||
|
ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
|
||||||
|
#endif
|
||||||
r = make_integer ((quad_t)(a->u.i == b->u.i));
|
r = make_integer ((quad_t)(a->u.i == b->u.i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -310,7 +310,13 @@ Of course, all of the above examples use constants, but would work the same if a
|
|||||||
numeric or string constants were replaced with a variable reference ${CALLERIDNUM}, for
|
numeric or string constants were replaced with a variable reference ${CALLERIDNUM}, for
|
||||||
instance.
|
instance.
|
||||||
|
|
||||||
|
__________________________
|
||||||
|
NUMBERS VS STRINGS
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
Tokens consisting only of numbers are converted to 64-bit numbers for most of the
|
||||||
|
operators. This means that overflows can occur when the numbers get above 18 digits.
|
||||||
|
Warnings will appear in the logs in this case.
|
||||||
___________________________
|
___________________________
|
||||||
CONDITIONALS
|
CONDITIONALS
|
||||||
---------------------------
|
---------------------------
|
||||||
|
Reference in New Issue
Block a user