diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2016-06-01 11:38:52 -0400 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2016-06-01 11:38:52 -0400 |
commit | 9867841a4767347cd89c9fd0127db3c7eaf943e6 (patch) | |
tree | 4b01081a570ea6666823b54ef912630f1e3cdfe8 /node.c | |
parent | 88c6afdf1c83a7ea51225fbb173d910533c51bb0 (diff) | |
download | egawk-9867841a4767347cd89c9fd0127db3c7eaf943e6.tar.gz egawk-9867841a4767347cd89c9fd0127db3c7eaf943e6.tar.bz2 egawk-9867841a4767347cd89c9fd0127db3c7eaf943e6.zip |
Disallow negative hex numbers in input data.
Diffstat (limited to 'node.c')
-rw-r--r-- | node.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -38,6 +38,20 @@ NODE *(*str2number)(NODE *) = r_force_number; NODE *(*format_val)(const char *, int, NODE *) = r_format_val; int (*cmp_numbers)(const NODE *, const NODE *) = cmp_awknums; +/* is_hex --- return true if a string looks like a hex value */ + +static bool +is_hex(const char *str) +{ + if (*str == '-' || *str == '+') + str++; + + if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) + return true; + + return false; +} + /* force_number --- force a value to be numeric */ NODE * @@ -96,8 +110,7 @@ r_force_number(NODE *n) || (! do_posix /* not POSIXLY paranoid and */ && (is_alpha((unsigned char) *cp) /* letter, or */ /* CANNOT do non-decimal and saw 0x */ - || (! do_non_decimal_data && cp[0] == '0' - && (cp[1] == 'x' || cp[1] == 'X'))))) { + || (! do_non_decimal_data && is_hex(cp))))) { return n; } |