diff options
author | Mike Pall <mike> | 2020-01-13 14:50:30 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2020-01-13 14:50:30 +0100 |
commit | 1357a25f81f520bf1be104d65d006f403d517ea5 (patch) | |
tree | b5e0441893012c15aada54f64cac965da20ff50a | |
parent | 0bee44c9dc9bee64d1143aa0febd2b61819d35bd (diff) | |
parent | 820339960123dc78a7ce03edf53fcf4fdae0e55d (diff) | |
download | luajit-1357a25f81f520bf1be104d65d006f403d517ea5.tar.gz luajit-1357a25f81f520bf1be104d65d006f403d517ea5.tar.bz2 luajit-1357a25f81f520bf1be104d65d006f403d517ea5.zip |
Merge branch 'master' into v2.1
Diffstat (limited to '')
-rw-r--r-- | src/lib_package.c | 4 | ||||
-rw-r--r-- | src/lj_bcread.c | 10 | ||||
-rw-r--r-- | src/lj_lex.c | 6 | ||||
-rw-r--r-- | src/lj_lex.h | 1 |
4 files changed, 14 insertions, 7 deletions
diff --git a/src/lib_package.c b/src/lib_package.c index bedd6d79..71201ecc 100644 --- a/src/lib_package.c +++ b/src/lib_package.c | |||
@@ -255,7 +255,7 @@ static int ll_loadfunc(lua_State *L, const char *path, const char *name, int r) | |||
255 | const char *bcdata = ll_bcsym(*reg, mksymname(L, name, SYMPREFIX_BC)); | 255 | const char *bcdata = ll_bcsym(*reg, mksymname(L, name, SYMPREFIX_BC)); |
256 | lua_pop(L, 1); | 256 | lua_pop(L, 1); |
257 | if (bcdata) { | 257 | if (bcdata) { |
258 | if (luaL_loadbuffer(L, bcdata, LJ_MAX_BUF, name) != 0) | 258 | if (luaL_loadbuffer(L, bcdata, ~(size_t)0, name) != 0) |
259 | return PACKAGE_ERR_LOAD; | 259 | return PACKAGE_ERR_LOAD; |
260 | return 0; | 260 | return 0; |
261 | } | 261 | } |
@@ -412,7 +412,7 @@ static int lj_cf_package_loader_preload(lua_State *L) | |||
412 | if (lua_isnil(L, -1)) { /* Not found? */ | 412 | if (lua_isnil(L, -1)) { /* Not found? */ |
413 | const char *bcname = mksymname(L, name, SYMPREFIX_BC); | 413 | const char *bcname = mksymname(L, name, SYMPREFIX_BC); |
414 | const char *bcdata = ll_bcsym(NULL, bcname); | 414 | const char *bcdata = ll_bcsym(NULL, bcname); |
415 | if (bcdata == NULL || luaL_loadbuffer(L, bcdata, LJ_MAX_BUF, name) != 0) | 415 | if (bcdata == NULL || luaL_loadbuffer(L, bcdata, ~(size_t)0, name) != 0) |
416 | lua_pushfstring(L, "\n\tno field package.preload['%s']", name); | 416 | lua_pushfstring(L, "\n\tno field package.preload['%s']", name); |
417 | } | 417 | } |
418 | return 1; | 418 | return 1; |
diff --git a/src/lj_bcread.c b/src/lj_bcread.c index 48c5e7c7..27d5d04a 100644 --- a/src/lj_bcread.c +++ b/src/lj_bcread.c | |||
@@ -73,6 +73,7 @@ static LJ_NOINLINE void bcread_fill(LexState *ls, MSize len, int need) | |||
73 | ls->c = -1; /* Only bad if we get called again. */ | 73 | ls->c = -1; /* Only bad if we get called again. */ |
74 | break; | 74 | break; |
75 | } | 75 | } |
76 | if (sz >= LJ_MAX_BUF - n) lj_err_mem(ls->L); | ||
76 | if (n) { /* Append to buffer. */ | 77 | if (n) { /* Append to buffer. */ |
77 | n += (MSize)sz; | 78 | n += (MSize)sz; |
78 | p = lj_buf_need(&ls->sb, n < len ? len : n); | 79 | p = lj_buf_need(&ls->sb, n < len ? len : n); |
@@ -84,20 +85,20 @@ static LJ_NOINLINE void bcread_fill(LexState *ls, MSize len, int need) | |||
84 | ls->p = buf; | 85 | ls->p = buf; |
85 | ls->pe = buf + sz; | 86 | ls->pe = buf + sz; |
86 | } | 87 | } |
87 | } while (ls->p + len > ls->pe); | 88 | } while ((MSize)(ls->pe - ls->p) < len); |
88 | } | 89 | } |
89 | 90 | ||
90 | /* Need a certain number of bytes. */ | 91 | /* Need a certain number of bytes. */ |
91 | static LJ_AINLINE void bcread_need(LexState *ls, MSize len) | 92 | static LJ_AINLINE void bcread_need(LexState *ls, MSize len) |
92 | { | 93 | { |
93 | if (LJ_UNLIKELY(ls->p + len > ls->pe)) | 94 | if (LJ_UNLIKELY((MSize)(ls->pe - ls->p) < len)) |
94 | bcread_fill(ls, len, 1); | 95 | bcread_fill(ls, len, 1); |
95 | } | 96 | } |
96 | 97 | ||
97 | /* Want to read up to a certain number of bytes, but may need less. */ | 98 | /* Want to read up to a certain number of bytes, but may need less. */ |
98 | static LJ_AINLINE void bcread_want(LexState *ls, MSize len) | 99 | static LJ_AINLINE void bcread_want(LexState *ls, MSize len) |
99 | { | 100 | { |
100 | if (LJ_UNLIKELY(ls->p + len > ls->pe)) | 101 | if (LJ_UNLIKELY((MSize)(ls->pe - ls->p) < len)) |
101 | bcread_fill(ls, len, 0); | 102 | bcread_fill(ls, len, 0); |
102 | } | 103 | } |
103 | 104 | ||
@@ -447,8 +448,7 @@ GCproto *lj_bcread(LexState *ls) | |||
447 | setprotoV(L, L->top, pt); | 448 | setprotoV(L, L->top, pt); |
448 | incr_top(L); | 449 | incr_top(L); |
449 | } | 450 | } |
450 | if ((int32_t)(2*(uint32_t)(ls->pe - ls->p)) > 0 || | 451 | if ((ls->pe != ls->p && !ls->endmark) || L->top-1 != bcread_oldtop(L, ls)) |
451 | L->top-1 != bcread_oldtop(L, ls)) | ||
452 | bcread_error(ls, LJ_ERR_BCBAD); | 452 | bcread_error(ls, LJ_ERR_BCBAD); |
453 | /* Pop off last prototype. */ | 453 | /* Pop off last prototype. */ |
454 | L->top--; | 454 | L->top--; |
diff --git a/src/lj_lex.c b/src/lj_lex.c index fb3d95ee..1c9923cd 100644 --- a/src/lj_lex.c +++ b/src/lj_lex.c | |||
@@ -48,6 +48,11 @@ static LJ_NOINLINE LexChar lex_more(LexState *ls) | |||
48 | size_t sz; | 48 | size_t sz; |
49 | const char *p = ls->rfunc(ls->L, ls->rdata, &sz); | 49 | const char *p = ls->rfunc(ls->L, ls->rdata, &sz); |
50 | if (p == NULL || sz == 0) return LEX_EOF; | 50 | if (p == NULL || sz == 0) return LEX_EOF; |
51 | if (sz >= LJ_MAX_BUF) { | ||
52 | if (sz != ~(size_t)0) lj_err_mem(ls->L); | ||
53 | sz = ~(uintptr_t)0 - (uintptr_t)p; | ||
54 | ls->endmark = 1; | ||
55 | } | ||
51 | ls->pe = p + sz; | 56 | ls->pe = p + sz; |
52 | ls->p = p + 1; | 57 | ls->p = p + 1; |
53 | return (LexChar)(uint8_t)p[0]; | 58 | return (LexChar)(uint8_t)p[0]; |
@@ -406,6 +411,7 @@ int lj_lex_setup(lua_State *L, LexState *ls) | |||
406 | ls->lookahead = TK_eof; /* No look-ahead token. */ | 411 | ls->lookahead = TK_eof; /* No look-ahead token. */ |
407 | ls->linenumber = 1; | 412 | ls->linenumber = 1; |
408 | ls->lastline = 1; | 413 | ls->lastline = 1; |
414 | ls->endmark = 0; | ||
409 | lex_next(ls); /* Read-ahead first char. */ | 415 | lex_next(ls); /* Read-ahead first char. */ |
410 | if (ls->c == 0xef && ls->p + 2 <= ls->pe && (uint8_t)ls->p[0] == 0xbb && | 416 | if (ls->c == 0xef && ls->p + 2 <= ls->pe && (uint8_t)ls->p[0] == 0xbb && |
411 | (uint8_t)ls->p[1] == 0xbf) { /* Skip UTF-8 BOM (if buffered). */ | 417 | (uint8_t)ls->p[1] == 0xbf) { /* Skip UTF-8 BOM (if buffered). */ |
diff --git a/src/lj_lex.h b/src/lj_lex.h index 33fa8657..38d28533 100644 --- a/src/lj_lex.h +++ b/src/lj_lex.h | |||
@@ -73,6 +73,7 @@ typedef struct LexState { | |||
73 | BCInsLine *bcstack; /* Stack for bytecode instructions/line numbers. */ | 73 | BCInsLine *bcstack; /* Stack for bytecode instructions/line numbers. */ |
74 | MSize sizebcstack; /* Size of bytecode stack. */ | 74 | MSize sizebcstack; /* Size of bytecode stack. */ |
75 | uint32_t level; /* Syntactical nesting level. */ | 75 | uint32_t level; /* Syntactical nesting level. */ |
76 | int endmark; /* Trust bytecode end marker, even if not at EOF. */ | ||
76 | } LexState; | 77 | } LexState; |
77 | 78 | ||
78 | LJ_FUNC int lj_lex_setup(lua_State *L, LexState *ls); | 79 | LJ_FUNC int lj_lex_setup(lua_State *L, LexState *ls); |