From 3b7454fd9b4d310e2945763faf357aca3113ab12 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Wed, 17 Feb 2010 19:43:16 +0100 Subject: [PATCH] Try to make $if_match better handle stranger inputs This should fix sf.net #2953283 --- src/algebra.c | 21 ++++++++++++--------- src/algebra.h | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/algebra.c b/src/algebra.c index 3f41e335..a1bcda57 100644 --- a/src/algebra.c +++ b/src/algebra.c @@ -126,11 +126,9 @@ enum arg_type get_arg_type(const char *arg) const char *p, *e; p = arg; - e = arg + strlen(arg); + e = arg + strlen(arg)-1; - if (*(e - 1) == ' ') - e--; - while (*e && *e == ' ') + while (p != e && *e && *e == ' ') e--; while (p != e && *p == ' ') p++; @@ -140,23 +138,23 @@ enum arg_type get_arg_type(const char *arg) if (*p == '-') //allow negative values p++; - while (p != e) { + while (p <= e) { if (!isdigit(*p)) break; p++; } - if (p == e) + if (p == e+1) return ARG_LONG; if (*p == '.') { p++; - while (p != e) { + while (p <= e) { if (!isdigit(*p)) - return ARG_STRING; + return ARG_BAD; p++; } return ARG_DOUBLE; } - return ARG_STRING; + return ARG_BAD; } char *arg_to_string(const char *arg) @@ -213,6 +211,10 @@ int compare(const char *expr) type1 = get_arg_type(expr_dup); type2 = get_arg_type(expr_dup + idx + 1); + if (type1 == ARG_BAD || type2 == ARG_BAD) { + NORM_ERR("Bad arguments: '%s' and '%s'", expr_dup, (expr_dup + idx + 1)); + return -2; + } if (type1 == ARG_LONG && type2 == ARG_DOUBLE) type1 = ARG_DOUBLE; if (type1 == ARG_DOUBLE && type2 == ARG_LONG) @@ -239,6 +241,7 @@ int compare(const char *expr) case ARG_DOUBLE: return dcompare(arg_to_double(expr_dup), mtype, arg_to_double(expr_dup + idx + 1)); + case ARG_BAD: /* make_gcc_happy() */; } /* not reached */ return -2; diff --git a/src/algebra.h b/src/algebra.h index e338e5fc..4e4b721a 100644 --- a/src/algebra.h +++ b/src/algebra.h @@ -40,6 +40,7 @@ enum match_type { }; enum arg_type { + ARG_BAD = 0, /* something strange */ ARG_STRING = 1, /* "asdf" */ ARG_LONG = 2, /* 123456 */ ARG_DOUBLE = 3, /* 12.456 */