diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-03-10 15:21:32 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-03-10 15:21:32 -0300 |
| commit | b5b1995f2925b2f9be4a48304ac97a38f8608648 (patch) | |
| tree | 6935ced2337eb900029ccb119636185df5037fd8 /lundump.c | |
| parent | cb88c1cd5d22fe7c56f4f374ded7c16f7cf14bf3 (diff) | |
| download | lua-b5b1995f2925b2f9be4a48304ac97a38f8608648.tar.gz lua-b5b1995f2925b2f9be4a48304ac97a38f8608648.tar.bz2 lua-b5b1995f2925b2f9be4a48304ac97a38f8608648.zip | |
Checks for type 'int' added to binary header
The structure 'AbsLineInfo' is hard-dumped into binary chunks, and
it comprises two 'int' fields.
Diffstat (limited to 'lundump.c')
| -rw-r--r-- | lundump.c | 38 |
1 files changed, 26 insertions, 12 deletions
| @@ -345,13 +345,29 @@ static void checkliteral (LoadState *S, const char *s, const char *msg) { | |||
| 345 | } | 345 | } |
| 346 | 346 | ||
| 347 | 347 | ||
| 348 | static void fchecksize (LoadState *S, size_t size, const char *tname) { | 348 | static l_noret numerror (LoadState *S, const char *what, const char *tname) { |
| 349 | if (loadByte(S) != size) | 349 | const char *msg = luaO_pushfstring(S->L, "%s %s mismatch", tname, what); |
| 350 | error(S, luaO_pushfstring(S->L, "%s size mismatch", tname)); | 350 | error(S, msg); |
| 351 | } | 351 | } |
| 352 | 352 | ||
| 353 | 353 | ||
| 354 | #define checksize(S,t) fchecksize(S,sizeof(t),#t) | 354 | static void checknumsize (LoadState *S, int size, const char *tname) { |
| 355 | if (size != loadByte(S)) | ||
| 356 | numerror(S, "size", tname); | ||
| 357 | } | ||
| 358 | |||
| 359 | |||
| 360 | static void checknumformat (LoadState *S, int eq, const char *tname) { | ||
| 361 | if (!eq) | ||
| 362 | numerror(S, "format", tname); | ||
| 363 | } | ||
| 364 | |||
| 365 | |||
| 366 | #define checknum(S,tvar,value,tname) \ | ||
| 367 | { tvar i; checknumsize(S, sizeof(i), tname); \ | ||
| 368 | loadVar(S, i); \ | ||
| 369 | checknumformat(S, i == value, tname); } | ||
| 370 | |||
| 355 | 371 | ||
| 356 | static void checkHeader (LoadState *S) { | 372 | static void checkHeader (LoadState *S) { |
| 357 | /* skip 1st char (already read and checked) */ | 373 | /* skip 1st char (already read and checked) */ |
| @@ -361,13 +377,10 @@ static void checkHeader (LoadState *S) { | |||
| 361 | if (loadByte(S) != LUAC_FORMAT) | 377 | if (loadByte(S) != LUAC_FORMAT) |
| 362 | error(S, "format mismatch"); | 378 | error(S, "format mismatch"); |
| 363 | checkliteral(S, LUAC_DATA, "corrupted chunk"); | 379 | checkliteral(S, LUAC_DATA, "corrupted chunk"); |
| 364 | checksize(S, Instruction); | 380 | checknum(S, int, LUAC_INT, "int"); |
| 365 | checksize(S, lua_Integer); | 381 | checknum(S, Instruction, LUAC_INST, "instruction"); |
| 366 | checksize(S, lua_Number); | 382 | checknum(S, lua_Integer, LUAC_INT, "Lua integer"); |
| 367 | if (loadInteger(S) != LUAC_INT) | 383 | checknum(S, lua_Number, LUAC_NUM, "Lua number"); |
| 368 | error(S, "integer format mismatch"); | ||
| 369 | if (loadNumber(S) != LUAC_NUM) | ||
| 370 | error(S, "float format mismatch"); | ||
| 371 | } | 384 | } |
| 372 | 385 | ||
| 373 | 386 | ||
| @@ -398,7 +411,8 @@ LClosure *luaU_undump (lua_State *L, ZIO *Z, const char *name, int fixed) { | |||
| 398 | cl->p = luaF_newproto(L); | 411 | cl->p = luaF_newproto(L); |
| 399 | luaC_objbarrier(L, cl, cl->p); | 412 | luaC_objbarrier(L, cl, cl->p); |
| 400 | loadFunction(&S, cl->p); | 413 | loadFunction(&S, cl->p); |
| 401 | lua_assert(cl->nupvalues == cl->p->sizeupvalues); | 414 | if (cl->nupvalues != cl->p->sizeupvalues) |
| 415 | error(&S, "corrupted chunk"); | ||
| 402 | luai_verifycode(L, cl->p); | 416 | luai_verifycode(L, cl->p); |
| 403 | L->top.p--; /* pop table */ | 417 | L->top.p--; /* pop table */ |
| 404 | return cl; | 418 | return cl; |
