eval/decode: Reject even more numbers

Rejects leading zeroes and numbers like 1.e+5 (decimal dot with missing number 
with signed exponent).
This commit is contained in:
ZyX
2016-03-09 02:08:53 +03:00
parent 69ce17878e
commit 515fea1ef0
2 changed files with 45 additions and 1 deletions

View File

@@ -492,6 +492,7 @@ static inline int parse_json_number(const char *const buf, const size_t buf_len,
const char *ints = NULL;
const char *fracs = NULL;
const char *exps = NULL;
const char *exps_s = NULL;
if (*p == '-') {
p++;
}
@@ -499,6 +500,10 @@ static inline int parse_json_number(const char *const buf, const size_t buf_len,
while (p < e && ascii_isdigit(*p)) {
p++;
}
if (p != ints + 1 && *ints == '0') {
emsgf(_("E474: Leading zeroes are not allowed: %.*s"), LENP(s, e));
goto parse_json_number_fail;
}
if (p < e && p != ints && (*p == '.' || *p == 'e' || *p == 'E')) {
if (*p == '.') {
p++;
@@ -509,6 +514,7 @@ static inline int parse_json_number(const char *const buf, const size_t buf_len,
}
if (p < e && (*p == 'e' || *p == 'E')) {
p++;
exps_s = p;
if (p < e && (*p == '-' || *p == '+')) {
p++;
}
@@ -521,7 +527,7 @@ static inline int parse_json_number(const char *const buf, const size_t buf_len,
if (p == ints) {
emsgf(_("E474: Missing number after minus sign: %.*s"), LENP(s, e));
goto parse_json_number_fail;
} else if (p == fracs || exps == fracs + 1) {
} else if (p == fracs || exps_s == fracs + 1) {
emsgf(_("E474: Missing number after decimal dot: %.*s"), LENP(s, e));
goto parse_json_number_fail;
} else if (p == exps) {