aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2012-05-03 19:04:44 +0200
committerMike Pall <mike>2012-05-03 19:04:44 +0200
commit53a285c0c3544ff5dea7c67b741c3c2d06d22b47 (patch)
treebbe5e5a6d385f872cae1f5b4ae52d98b3fd6c489 /src
parenteec0d80d1b9767beef0c38168b772a2b49175268 (diff)
downloadluajit-53a285c0c3544ff5dea7c67b741c3c2d06d22b47.tar.gz
luajit-53a285c0c3544ff5dea7c67b741c3c2d06d22b47.tar.bz2
luajit-53a285c0c3544ff5dea7c67b741c3c2d06d22b47.zip
Disable loading bytecode with an extra header (BOM or #!).
Diffstat (limited to 'src')
-rw-r--r--src/lj_errmsg.h1
-rw-r--r--src/lj_lex.c18
2 files changed, 18 insertions, 1 deletions
diff --git a/src/lj_errmsg.h b/src/lj_errmsg.h
index 83c69ea8..d1db4386 100644
--- a/src/lj_errmsg.h
+++ b/src/lj_errmsg.h
@@ -139,6 +139,7 @@ ERRDEF(XFOR, LUA_QL("=") " or " LUA_QL("in") " expected")
139/* Bytecode reader errors. */ 139/* Bytecode reader errors. */
140ERRDEF(BCFMT, "cannot load incompatible bytecode") 140ERRDEF(BCFMT, "cannot load incompatible bytecode")
141ERRDEF(BCBAD, "cannot load malformed bytecode") 141ERRDEF(BCBAD, "cannot load malformed bytecode")
142ERRDEF(BCHEAD, "attempt to load bytecode with extra header")
142 143
143#if LJ_HASFFI 144#if LJ_HASFFI
144/* FFI errors. */ 145/* FFI errors. */
diff --git a/src/lj_lex.c b/src/lj_lex.c
index d87a49dc..669d2dfe 100644
--- a/src/lj_lex.c
+++ b/src/lj_lex.c
@@ -411,6 +411,7 @@ static int llex(LexState *ls, TValue *tv)
411/* Setup lexer state. */ 411/* Setup lexer state. */
412int lj_lex_setup(lua_State *L, LexState *ls) 412int lj_lex_setup(lua_State *L, LexState *ls)
413{ 413{
414 int header = 0;
414 ls->L = L; 415 ls->L = L;
415 ls->fs = NULL; 416 ls->fs = NULL;
416 ls->n = 0; 417 ls->n = 0;
@@ -430,6 +431,7 @@ int lj_lex_setup(lua_State *L, LexState *ls)
430 ls->n -= 2; 431 ls->n -= 2;
431 ls->p += 2; 432 ls->p += 2;
432 next(ls); 433 next(ls);
434 header = 1;
433 } 435 }
434 if (ls->current == '#') { /* Skip POSIX #! header line. */ 436 if (ls->current == '#') { /* Skip POSIX #! header line. */
435 do { 437 do {
@@ -437,8 +439,22 @@ int lj_lex_setup(lua_State *L, LexState *ls)
437 if (ls->current == END_OF_STREAM) return 0; 439 if (ls->current == END_OF_STREAM) return 0;
438 } while (!currIsNewline(ls)); 440 } while (!currIsNewline(ls));
439 inclinenumber(ls); 441 inclinenumber(ls);
442 header = 1;
440 } 443 }
441 return (ls->current == LUA_SIGNATURE[0]); /* Bytecode dump? */ 444 if (ls->current == LUA_SIGNATURE[0]) { /* Bytecode dump. */
445 if (header) {
446 /*
447 ** Loading bytecode with an extra header is disabled for security
448 ** reasons. This may circumvent the usual check for bytecode vs.
449 ** Lua code by looking at the first char. Since this is a potential
450 ** security violation no attempt is made to echo the chunkname either.
451 */
452 setstrV(L, L->top++, lj_err_str(L, LJ_ERR_BCHEAD));
453 lj_err_throw(L, LUA_ERRSYNTAX);
454 }
455 return 1;
456 }
457 return 0;
442} 458}
443 459
444/* Cleanup lexer state. */ 460/* Cleanup lexer state. */