From e9763842134ac807262e3b86d5f40d25a8d69f1b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 11 Mar 2014 15:05:46 -0300 Subject: keep chunk's headers compatible at least up to LUAC_VERSION (to be able to detect correctly version mismatches) --- lundump.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lundump.c') diff --git a/lundump.c b/lundump.c index 3f274817..1807822f 100644 --- a/lundump.c +++ b/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); -- cgit v1.2.3-55-g6feb