lua: apply upstream bugfix for "Loading a corrupted binary file can segfault."diff -r1.10 -r1.11 src/external/mit/lua/dist/src/ldump.c
(nikita)
--- src/external/mit/lua/dist/src/ldump.c 2023/04/16 20:46:17 1.10
+++ src/external/mit/lua/dist/src/ldump.c 2023/04/17 21:17:57 1.11
@@ -1,29 +1,30 @@ | @@ -1,29 +1,30 @@ | |||
1 | /* $NetBSD: ldump.c,v 1.10 2023/04/16 20:46:17 nikita Exp $ */ | 1 | /* $NetBSD: ldump.c,v 1.11 2023/04/17 21:17:57 nikita Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | ** Id: ldump.c | 4 | ** Id: ldump.c | |
5 | ** save precompiled Lua chunks | 5 | ** save precompiled Lua chunks | |
6 | ** See Copyright Notice in lua.h | 6 | ** See Copyright Notice in lua.h | |
7 | */ | 7 | */ | |
8 | 8 | |||
9 | #define ldump_c | 9 | #define ldump_c | |
10 | #define LUA_CORE | 10 | #define LUA_CORE | |
11 | 11 | |||
12 | #include "lprefix.h" | 12 | #include "lprefix.h" | |
13 | 13 | |||
14 | 14 | |||
15 | #ifndef _KERNEL | 15 | #ifndef _KERNEL | |
16 | #include <stddef.h> | 16 | #include <stddef.h> | |
17 | #include <limits.h> | |||
17 | #endif /* _KERNEL */ | 18 | #endif /* _KERNEL */ | |
18 | 19 | |||
19 | #include "lua.h" | 20 | #include "lua.h" | |
20 | 21 | |||
21 | #include "lobject.h" | 22 | #include "lobject.h" | |
22 | #include "lstate.h" | 23 | #include "lstate.h" | |
23 | #include "lundump.h" | 24 | #include "lundump.h" | |
24 | 25 | |||
25 | 26 | |||
26 | typedef struct { | 27 | typedef struct { | |
27 | lua_State *L; | 28 | lua_State *L; | |
28 | lua_Writer writer; | 29 | lua_Writer writer; | |
29 | void *data; | 30 | void *data; | |
@@ -49,28 +50,37 @@ static void dumpBlock (DumpState *D, con | @@ -49,28 +50,37 @@ static void dumpBlock (DumpState *D, con | |||
49 | } | 50 | } | |
50 | } | 51 | } | |
51 | 52 | |||
52 | 53 | |||
53 | #define dumpVar(D,x) dumpVector(D,&x,1) | 54 | #define dumpVar(D,x) dumpVector(D,&x,1) | |
54 | 55 | |||
55 | 56 | |||
56 | static void dumpByte (DumpState *D, int y) { | 57 | static void dumpByte (DumpState *D, int y) { | |
57 | lu_byte x = (lu_byte)y; | 58 | lu_byte x = (lu_byte)y; | |
58 | dumpVar(D, x); | 59 | dumpVar(D, x); | |
59 | } | 60 | } | |
60 | 61 | |||
61 | 62 | |||
63 | #ifdef _KERNEL | |||
62 | /* dumpInt Buff Size */ | 64 | /* dumpInt Buff Size */ | |
63 | #define DIBS ((sizeof(size_t) * 8 / 7) + 1) | 65 | #define DIBS ((sizeof(size_t) * 8 / 7) + 1) | |
66 | #endif /* _KERNEL */ | |||
67 | #ifndef _KERNEL | |||
68 | /* | |||
69 | ** 'dumpSize' buffer size: each byte can store up to 7 bits. (The "+6" | |||
70 | ** rounds up the division.) | |||
71 | */ | |||
72 | #define DIBS ((sizeof(size_t) * CHAR_BIT + 6) / 7) | |||
73 | #endif /* _KERNEL */ | |||
64 | 74 | |||
65 | static void dumpSize (DumpState *D, size_t x) { | 75 | static void dumpSize (DumpState *D, size_t x) { | |
66 | lu_byte buff[DIBS]; | 76 | lu_byte buff[DIBS]; | |
67 | int n = 0; | 77 | int n = 0; | |
68 | do { | 78 | do { | |
69 | buff[DIBS - (++n)] = x & 0x7f; /* fill buffer in reverse order */ | 79 | buff[DIBS - (++n)] = x & 0x7f; /* fill buffer in reverse order */ | |
70 | x >>= 7; | 80 | x >>= 7; | |
71 | } while (x != 0); | 81 | } while (x != 0); | |
72 | buff[DIBS - 1] |= 0x80; /* mark last byte */ | 82 | buff[DIBS - 1] |= 0x80; /* mark last byte */ | |
73 | dumpVector(D, buff + DIBS - n, n); | 83 | dumpVector(D, buff + DIBS - n, n); | |
74 | } | 84 | } | |
75 | 85 | |||
76 | 86 |
--- src/external/mit/lua/dist/src/lundump.c 2023/04/16 20:46:17 1.9
+++ src/external/mit/lua/dist/src/lundump.c 2023/04/17 21:17:57 1.10
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: lundump.c,v 1.9 2023/04/16 20:46:17 nikita Exp $ */ | 1 | /* $NetBSD: lundump.c,v 1.10 2023/04/17 21:17:57 nikita Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | ** Id: lundump.c | 4 | ** Id: lundump.c | |
5 | ** load precompiled Lua chunks | 5 | ** load precompiled Lua chunks | |
6 | ** See Copyright Notice in lua.h | 6 | ** See Copyright Notice in lua.h | |
7 | */ | 7 | */ | |
8 | 8 | |||
9 | #define lundump_c | 9 | #define lundump_c | |
10 | #define LUA_CORE | 10 | #define LUA_CORE | |
11 | 11 | |||
12 | #include "lprefix.h" | 12 | #include "lprefix.h" | |
13 | 13 | |||
14 | 14 | |||
@@ -244,26 +244,28 @@ static void loadDebug (LoadState *S, Pro | @@ -244,26 +244,28 @@ static void loadDebug (LoadState *S, Pro | |||
244 | f->abslineinfo[i].line = loadInt(S); | 244 | f->abslineinfo[i].line = loadInt(S); | |
245 | } | 245 | } | |
246 | n = loadInt(S); | 246 | n = loadInt(S); | |
247 | f->locvars = luaM_newvectorchecked(S->L, n, LocVar); | 247 | f->locvars = luaM_newvectorchecked(S->L, n, LocVar); | |
248 | f->sizelocvars = n; | 248 | f->sizelocvars = n; | |
249 | for (i = 0; i < n; i++) | 249 | for (i = 0; i < n; i++) | |
250 | f->locvars[i].varname = NULL; | 250 | f->locvars[i].varname = NULL; | |
251 | for (i = 0; i < n; i++) { | 251 | for (i = 0; i < n; i++) { | |
252 | f->locvars[i].varname = loadStringN(S, f); | 252 | f->locvars[i].varname = loadStringN(S, f); | |
253 | f->locvars[i].startpc = loadInt(S); | 253 | f->locvars[i].startpc = loadInt(S); | |
254 | f->locvars[i].endpc = loadInt(S); | 254 | f->locvars[i].endpc = loadInt(S); | |
255 | } | 255 | } | |
256 | n = loadInt(S); | 256 | n = loadInt(S); | |
257 | if (n != 0) /* does it have debug information? */ | |||
258 | n = f->sizeupvalues; /* must be this many */ | |||
257 | for (i = 0; i < n; i++) | 259 | for (i = 0; i < n; i++) | |
258 | f->upvalues[i].name = loadStringN(S, f); | 260 | f->upvalues[i].name = loadStringN(S, f); | |
259 | } | 261 | } | |
260 | 262 | |||
261 | 263 | |||
262 | static void loadFunction (LoadState *S, Proto *f, TString *psource) { | 264 | static void loadFunction (LoadState *S, Proto *f, TString *psource) { | |
263 | f->source = loadStringN(S, f); | 265 | f->source = loadStringN(S, f); | |
264 | if (f->source == NULL) /* no source in dump? */ | 266 | if (f->source == NULL) /* no source in dump? */ | |
265 | f->source = psource; /* reuse parent's source */ | 267 | f->source = psource; /* reuse parent's source */ | |
266 | f->linedefined = loadInt(S); | 268 | f->linedefined = loadInt(S); | |
267 | f->lastlinedefined = loadInt(S); | 269 | f->lastlinedefined = loadInt(S); | |
268 | f->numparams = loadByte(S); | 270 | f->numparams = loadByte(S); | |
269 | f->is_vararg = loadByte(S); | 271 | f->is_vararg = loadByte(S); |