aboutsummaryrefslogtreecommitdiff
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
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)
-rw-r--r--ldump.c8
-rw-r--r--lundump.c15
2 files changed, 13 insertions, 10 deletions
diff --git a/ldump.c b/ldump.c
index c6df3ae9..c86a03c8 100644
--- a/ldump.c
+++ b/ldump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldump.c,v 2.24 2014/03/01 15:18:44 roberto Exp roberto $ 2** $Id: ldump.c,v 2.25 2014/03/10 17:56:32 roberto Exp roberto $
3** save precompiled Lua chunks 3** save precompiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -160,11 +160,13 @@ static void DumpFunction (const Proto *f, DumpState *D) {
160} 160}
161 161
162 162
163#define DumpLiteral(s,D) DumpBlock(s, sizeof(s) - sizeof(char), D)
164
163static void DumpHeader (DumpState *D) { 165static void DumpHeader (DumpState *D) {
164 DumpBlock(LUA_SIGNATURE, sizeof(LUA_SIGNATURE), D); 166 DumpLiteral(LUA_SIGNATURE, D);
165 DumpBlock(LUAC_DATA, sizeof(LUAC_DATA), D);
166 DumpByte(LUAC_VERSION, D); 167 DumpByte(LUAC_VERSION, D);
167 DumpByte(LUAC_FORMAT, D); 168 DumpByte(LUAC_FORMAT, D);
169 DumpLiteral(LUAC_DATA, D);
168 DumpByte(sizeof(int), D); 170 DumpByte(sizeof(int), D);
169 DumpByte(sizeof(size_t), D); 171 DumpByte(sizeof(size_t), D);
170 DumpByte(sizeof(Instruction), D); 172 DumpByte(sizeof(Instruction), D);
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);