diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2026-04-23 17:57:42 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2026-04-23 17:57:42 -0300 |
| commit | 3228a97c6a953dcf397944161bb64b12f1ff5384 (patch) | |
| tree | 6497f6f8e93ba3bb381c0b48aed71646fca3f9b0 /lundump.c | |
| parent | 0c16a42d61d08266033ff63bc5dfade6312b7359 (diff) | |
| download | lua-3228a97c6a953dcf397944161bb64b12f1ff5384.tar.gz lua-3228a97c6a953dcf397944161bb64b12f1ff5384.tar.bz2 lua-3228a97c6a953dcf397944161bb64b12f1ff5384.zip | |
Bug: 'lua_load' does not preserve the stack
'lua_load' does not preserve the stack through the calls to the
reader function, as it should. Immediately after the first call (to
detect whether chunk is binary) it adds stuff, and it also adds a new
table when starting the compilation of each new function.
Diffstat (limited to 'lundump.c')
| -rw-r--r-- | lundump.c | 13 |
1 files changed, 5 insertions, 8 deletions
| @@ -392,7 +392,8 @@ static void checkHeader (LoadState *S) { | |||
| 392 | /* | 392 | /* |
| 393 | ** Load precompiled chunk. | 393 | ** Load precompiled chunk. |
| 394 | */ | 394 | */ |
| 395 | LClosure *luaU_undump (lua_State *L, ZIO *Z, const char *name, int fixed) { | 395 | LClosure *luaU_undump (lua_State *L, ZIO *Z, Table *anchor, const char *name, |
| 396 | int fixed) { | ||
| 396 | LoadState S; | 397 | LoadState S; |
| 397 | LClosure *cl; | 398 | LClosure *cl; |
| 398 | if (*name == '@' || *name == '=') | 399 | if (*name == '@' || *name == '=') |
| @@ -405,20 +406,16 @@ LClosure *luaU_undump (lua_State *L, ZIO *Z, const char *name, int fixed) { | |||
| 405 | S.fixed = cast_byte(fixed); | 406 | S.fixed = cast_byte(fixed); |
| 406 | S.offset = 1; /* fist byte was already read */ | 407 | S.offset = 1; /* fist byte was already read */ |
| 407 | checkHeader(&S); | 408 | checkHeader(&S); |
| 408 | cl = luaF_newLclosure(L, loadByte(&S)); | 409 | S.h = anchor; |
| 409 | setclLvalue2s(L, L->top.p, cl); | ||
| 410 | luaD_inctop(L); | ||
| 411 | S.h = luaH_new(L); /* create list of saved strings */ | ||
| 412 | S.nstr = 0; | 410 | S.nstr = 0; |
| 413 | sethvalue2s(L, L->top.p, S.h); /* anchor it */ | 411 | cl = luaF_newLclosure(L, loadByte(&S)); |
| 414 | luaD_inctop(L); | 412 | luaD_anchorobj(L, anchor, obj2gco(cl)); |
| 415 | cl->p = luaF_newproto(L); | 413 | cl->p = luaF_newproto(L); |
| 416 | luaC_objbarrier(L, cl, cl->p); | 414 | luaC_objbarrier(L, cl, cl->p); |
| 417 | loadFunction(&S, cl->p); | 415 | loadFunction(&S, cl->p); |
| 418 | if (cl->nupvalues != cl->p->sizeupvalues) | 416 | if (cl->nupvalues != cl->p->sizeupvalues) |
| 419 | error(&S, "corrupted chunk"); | 417 | error(&S, "corrupted chunk"); |
| 420 | luai_verifycode(L, cl->p); | 418 | luai_verifycode(L, cl->p); |
| 421 | L->top.p--; /* pop table */ | ||
| 422 | return cl; | 419 | return cl; |
| 423 | } | 420 | } |
| 424 | 421 | ||
