diff options
author | Mike Pall <mike> | 2010-11-02 16:01:26 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2010-11-02 16:01:43 +0100 |
commit | 188f0b04e1bfec8d12c1845eb14217100814b737 (patch) | |
tree | 95a78c18cb736c6269089ba2314468031c3c80fe /src | |
parent | 44372a44530702b817a1059d8b086149e8554998 (diff) | |
download | luajit-188f0b04e1bfec8d12c1845eb14217100814b737.tar.gz luajit-188f0b04e1bfec8d12c1845eb14217100814b737.tar.bz2 luajit-188f0b04e1bfec8d12c1845eb14217100814b737.zip |
Number parser shouldn't accept '0x' without hex digits.
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_str.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lj_str.c b/src/lj_str.c index 1f31c615..618687f5 100644 --- a/src/lj_str.c +++ b/src/lj_str.c | |||
@@ -186,12 +186,14 @@ int LJ_FASTCALL lj_str_numconv(const char *s, TValue *n) | |||
186 | uint32_t k = (uint32_t)(*p++ - '0'); | 186 | uint32_t k = (uint32_t)(*p++ - '0'); |
187 | if (k == 0 && ((*p & ~0x20) == 'X')) { | 187 | if (k == 0 && ((*p & ~0x20) == 'X')) { |
188 | p++; | 188 | p++; |
189 | while (lj_ctype_isxdigit(*p)) { | 189 | if (!lj_ctype_isxdigit(*p)) |
190 | return 0; /* Don't accept '0x' without hex digits. */ | ||
191 | do { | ||
190 | if (k >= 0x10000000) goto parsedbl; | 192 | if (k >= 0x10000000) goto parsedbl; |
191 | k = (k << 4) + (*p & 15u); | 193 | k = (k << 4) + (*p & 15u); |
192 | if (!lj_ctype_isdigit(*p)) k += 9; | 194 | if (!lj_ctype_isdigit(*p)) k += 9; |
193 | p++; | 195 | p++; |
194 | } | 196 | } while (lj_ctype_isxdigit(*p)); |
195 | } else { | 197 | } else { |
196 | while ((uint32_t)(*p - '0') < 10) { | 198 | while ((uint32_t)(*p - '0') < 10) { |
197 | if (k >= 0x19999999) goto parsedbl; | 199 | if (k >= 0x19999999) goto parsedbl; |
@@ -209,10 +211,10 @@ parsedbl: | |||
209 | TValue tv; | 211 | TValue tv; |
210 | char *endptr; | 212 | char *endptr; |
211 | setnumV(&tv, lua_str2number(s, &endptr)); | 213 | setnumV(&tv, lua_str2number(s, &endptr)); |
212 | if (endptr == s) return 0; /* conversion failed */ | 214 | if (endptr == s) return 0; /* Conversion failed. */ |
213 | if (LJ_UNLIKELY(*endptr != '\0')) { | 215 | if (LJ_UNLIKELY(*endptr != '\0')) { |
214 | while (lj_ctype_isspace((uint8_t)*endptr)) endptr++; | 216 | while (lj_ctype_isspace((uint8_t)*endptr)) endptr++; |
215 | if (*endptr != '\0') return 0; /* invalid trailing characters? */ | 217 | if (*endptr != '\0') return 0; /* Invalid trailing characters? */ |
216 | } | 218 | } |
217 | if (LJ_LIKELY(!tvisnan(&tv))) | 219 | if (LJ_LIKELY(!tvisnan(&tv))) |
218 | setnumV(n, numV(&tv)); | 220 | setnumV(n, numV(&tv)); |