mirror of
https://github.com/lua/lua
synced 2025-01-01 15:14:35 +03:00
keep chunk's headers compatible at least up to LUAC_VERSION (to be
able to detect correctly version mismatches)
This commit is contained in:
parent
68f4ccdd00
commit
e976384213
8
ldump.c
8
ldump.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldump.c,v 2.24 2014/03/01 15:18:44 roberto Exp roberto $
|
||||
** $Id: ldump.c,v 2.25 2014/03/10 17:56:32 roberto Exp roberto $
|
||||
** save precompiled Lua chunks
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -160,11 +160,13 @@ static void DumpFunction (const Proto *f, DumpState *D) {
|
||||
}
|
||||
|
||||
|
||||
#define DumpLiteral(s,D) DumpBlock(s, sizeof(s) - sizeof(char), D)
|
||||
|
||||
static void DumpHeader (DumpState *D) {
|
||||
DumpBlock(LUA_SIGNATURE, sizeof(LUA_SIGNATURE), D);
|
||||
DumpBlock(LUAC_DATA, sizeof(LUAC_DATA), D);
|
||||
DumpLiteral(LUA_SIGNATURE, D);
|
||||
DumpByte(LUAC_VERSION, D);
|
||||
DumpByte(LUAC_FORMAT, D);
|
||||
DumpLiteral(LUAC_DATA, D);
|
||||
DumpByte(sizeof(int), D);
|
||||
DumpByte(sizeof(size_t), D);
|
||||
DumpByte(sizeof(Instruction), D);
|
||||
|
15
lundump.c
15
lundump.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lundump.c,v 2.31 2014/03/10 17:56:32 roberto Exp roberto $
|
||||
** $Id: lundump.c,v 2.32 2014/03/10 19:50:19 roberto Exp roberto $
|
||||
** load precompiled Lua chunks
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -195,10 +195,11 @@ static void LoadFunction (LoadState *S, Proto *f) {
|
||||
}
|
||||
|
||||
|
||||
static void checkstring (LoadState *S, const char *s, const char *msg) {
|
||||
char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than each */
|
||||
LoadVector(S, buff, strlen(s) + 1);
|
||||
if (strcmp(s, buff) != 0)
|
||||
static void checkliteral (LoadState *S, const char *s, const char *msg) {
|
||||
char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */
|
||||
int len = strlen(s);
|
||||
LoadVector(S, buff, len);
|
||||
if (memcmp(s, buff, len) != 0)
|
||||
error(S, msg);
|
||||
}
|
||||
|
||||
@ -212,12 +213,12 @@ static void fchecksize (LoadState *S, size_t size, const char *tname) {
|
||||
#define checksize(S,t) fchecksize(S,sizeof(t),#t)
|
||||
|
||||
static void checkHeader (LoadState *S) {
|
||||
checkstring(S, LUA_SIGNATURE + 1, "not a");
|
||||
checkstring(S, LUAC_DATA, "corrupted");
|
||||
checkliteral(S, LUA_SIGNATURE + 1, "not a"); /* 1st char already checked */
|
||||
if (LoadByte(S) != LUAC_VERSION)
|
||||
error(S, "version mismatch in");
|
||||
if (LoadByte(S) != LUAC_FORMAT)
|
||||
error(S, "format mismatch in");
|
||||
checkliteral(S, LUAC_DATA, "corrupted");
|
||||
checksize(S, int);
|
||||
checksize(S, size_t);
|
||||
checksize(S, Instruction);
|
||||
|
Loading…
Reference in New Issue
Block a user