aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-01-02 00:50:59 +1100
committerdaurnimator <quae@daurnimator.com>2018-01-02 00:50:59 +1100
commit169b92c6b3d7a4ed9722da4fe0d3279e94f4ea5d (patch)
treecb9057bc55660d592b8f746394f61935c43bb450 /src
parentca087aef0afc793e52e870da57cfddb17eeb5701 (diff)
downloadfengari-169b92c6b3d7a4ed9722da4fe0d3279e94f4ea5d.tar.gz
fengari-169b92c6b3d7a4ed9722da4fe0d3279e94f4ea5d.tar.bz2
fengari-169b92c6b3d7a4ed9722da4fe0d3279e94f4ea5d.zip
src/lobject.js: Check string length before indexing
Strings aren't null terminated in JS
Diffstat (limited to 'src')
-rw-r--r--src/lobject.js6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lobject.js b/src/lobject.js
index 1b490f3..37419a9 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -474,12 +474,12 @@ const l_str2int = function(s) {
if (s[i] === char['0'] && (s[i+1] === char['x'] || s[i+1] === char['X'])) { /* hex? */
i += 2; /* skip '0x' */
- for (; ljstype.lisxdigit(s[i]); i++) {
+ for (; i < s.length && ljstype.lisxdigit(s[i]); i++) {
a = (a * 16 + luaO_hexavalue(s[i]))|0;
empty = false;
}
} else { /* decimal */
- for (; ljstype.lisdigit(s[i]); i++) {
+ for (; i < s.length && ljstype.lisdigit(s[i]); i++) {
let d = s[i] - char['0'];
if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */
return null; /* do not accept it (as integer) */
@@ -487,7 +487,7 @@ const l_str2int = function(s) {
empty = false;
}
}
- while (ljstype.lisspace(s[i])) i++; /* skip trailing spaces */
+ while (i < s.length && ljstype.lisspace(s[i])) i++; /* skip trailing spaces */
if (empty || (i !== s.length && s[i] !== 0)) return null; /* something wrong in the numeral */
else {
return {