aboutsummaryrefslogtreecommitdiff
path: root/lundump.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-03-11 15:05:46 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-03-11 15:05:46 -0300
commite9763842134ac807262e3b86d5f40d25a8d69f1b (patch)
tree30ae76f6e935fc09dbce8b247b7c31182a76922d /lundump.c
parent68f4ccdd00edac2a1b02878f0ef6fa32e8893857 (diff)
downloadlua-e9763842134ac807262e3b86d5f40d25a8d69f1b.tar.gz
lua-e9763842134ac807262e3b86d5f40d25a8d69f1b.tar.bz2
lua-e9763842134ac807262e3b86d5f40d25a8d69f1b.zip
keep chunk's headers compatible at least up to LUAC_VERSION (to be
able to detect correctly version mismatches)
Diffstat (limited to 'lundump.c')
-rw-r--r--lundump.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/lundump.c b/lundump.c
index 3f274817..1807822f 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 2.31 2014/03/10 17:56:32 roberto Exp roberto $ 2** $Id: lundump.c,v 2.32 2014/03/10 19:50:19 roberto Exp roberto $
3** load precompiled Lua chunks 3** load precompiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -195,10 +195,11 @@ static void LoadFunction (LoadState *S, Proto *f) {
195} 195}
196 196
197 197
198static void checkstring (LoadState *S, const char *s, const char *msg) { 198static void checkliteral (LoadState *S, const char *s, const char *msg) {
199 char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than each */ 199 char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */
200 LoadVector(S, buff, strlen(s) + 1); 200 int len = strlen(s);
201 if (strcmp(s, buff) != 0) 201 LoadVector(S, buff, len);
202 if (memcmp(s, buff, len) != 0)
202 error(S, msg); 203 error(S, msg);
203} 204}
204 205
@@ -212,12 +213,12 @@ static void fchecksize (LoadState *S, size_t size, const char *tname) {
212#define checksize(S,t) fchecksize(S,sizeof(t),#t) 213#define checksize(S,t) fchecksize(S,sizeof(t),#t)
213 214
214static void checkHeader (LoadState *S) { 215static void checkHeader (LoadState *S) {
215 checkstring(S, LUA_SIGNATURE + 1, "not a"); 216 checkliteral(S, LUA_SIGNATURE + 1, "not a"); /* 1st char already checked */
216 checkstring(S, LUAC_DATA, "corrupted");
217 if (LoadByte(S) != LUAC_VERSION) 217 if (LoadByte(S) != LUAC_VERSION)
218 error(S, "version mismatch in"); 218 error(S, "version mismatch in");
219 if (LoadByte(S) != LUAC_FORMAT) 219 if (LoadByte(S) != LUAC_FORMAT)
220 error(S, "format mismatch in"); 220 error(S, "format mismatch in");
221 checkliteral(S, LUAC_DATA, "corrupted");
221 checksize(S, int); 222 checksize(S, int);
222 checksize(S, size_t); 223 checksize(S, size_t);
223 checksize(S, Instruction); 224 checksize(S, Instruction);