Skip to content

Commit 4d471a6

Browse files
committed
tweak: safe undump support
1 parent e5ffeec commit 4d471a6

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

lua.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060

6161
typedef struct lua_State lua_State;
6262

63+
typedef int (*lua_UndumpHook) (const char* p, size_t n);
64+
6365

6466
/*
6567
** basic types

lundump.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "lundump.h"
2525
#include "lzio.h"
2626

27+
lua_UndumpHook pUndumpHook = NULL;
2728

2829
#if defined(LUA_NO_BYTECODE)
2930
LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {
@@ -367,6 +368,8 @@ LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {
367368
S.name = name;
368369
S.L = L;
369370
S.Z = Z;
371+
if (!pUndumpHook || !pUndumpHook(Z->p, Z->n))
372+
error(&S, "forbidden");
370373
checkHeader(&S);
371374
cl = luaF_newLclosure(L, loadByte(&S));
372375
setclLvalue2s(L, L->top, cl);

lundump.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626

2727
#define LUAC_FORMAT 0 /* this is the official format */
2828

29+
extern
30+
#if defined(IS_FXSERVER)
31+
#if defined(_WIN32)
32+
__declspec(dllexport)
33+
#else
34+
__attribute__((visibility("default")))
35+
#endif
36+
#endif
37+
lua_UndumpHook pUndumpHook;
38+
2939
/* load one chunk; from lundump.c */
3040
LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name);
3141

0 commit comments

Comments
 (0)