summaryrefslogtreecommitdiff
path: root/external/mit
diff options
context:
space:
mode:
authornikita <nikita@NetBSD.org>2023-04-17 21:17:57 +0000
committernikita <nikita@NetBSD.org>2023-04-17 21:17:57 +0000
commitec0fc2537c3b236d3445dab271d9b967959ab4b5 (patch)
treea6d08046b29f2daca55f5cf19a9326d9fb752d17 /external/mit
parent8a34e137b90fcb2b3cc411075d0aa5937b4173e0 (diff)
lua: apply upstream bugfix for "Loading a corrupted binary file can segfault."
Diffstat (limited to 'external/mit')
-rw-r--r--external/mit/lua/dist/src/ldump.c12
-rw-r--r--external/mit/lua/dist/src/lundump.c4
2 files changed, 14 insertions, 2 deletions
diff --git a/external/mit/lua/dist/src/ldump.c b/external/mit/lua/dist/src/ldump.c
index 42a8efc0f33..2bbf9a30b9c 100644
--- a/external/mit/lua/dist/src/ldump.c
+++ b/external/mit/lua/dist/src/ldump.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ldump.c,v 1.10 2023/04/16 20:46:17 nikita Exp $ */
+/* $NetBSD: ldump.c,v 1.11 2023/04/17 21:17:57 nikita Exp $ */
/*
** Id: ldump.c
@@ -14,6 +14,7 @@
#ifndef _KERNEL
#include <stddef.h>
+#include <limits.h>
#endif /* _KERNEL */
#include "lua.h"
@@ -59,8 +60,17 @@ static void dumpByte (DumpState *D, int y) {
}
+#ifdef _KERNEL
/* dumpInt Buff Size */
#define DIBS ((sizeof(size_t) * 8 / 7) + 1)
+#endif /* _KERNEL */
+#ifndef _KERNEL
+/*
+** 'dumpSize' buffer size: each byte can store up to 7 bits. (The "+6"
+** rounds up the division.)
+*/
+#define DIBS ((sizeof(size_t) * CHAR_BIT + 6) / 7)
+#endif /* _KERNEL */
static void dumpSize (DumpState *D, size_t x) {
lu_byte buff[DIBS];
diff --git a/external/mit/lua/dist/src/lundump.c b/external/mit/lua/dist/src/lundump.c
index 1ceb2106674..6e4533c7375 100644
--- a/external/mit/lua/dist/src/lundump.c
+++ b/external/mit/lua/dist/src/lundump.c
@@ -1,4 +1,4 @@
-/* $NetBSD: lundump.c,v 1.9 2023/04/16 20:46:17 nikita Exp $ */
+/* $NetBSD: lundump.c,v 1.10 2023/04/17 21:17:57 nikita Exp $ */
/*
** Id: lundump.c
@@ -254,6 +254,8 @@ static void loadDebug (LoadState *S, Proto *f) {
f->locvars[i].endpc = loadInt(S);
}
n = loadInt(S);
+ if (n != 0) /* does it have debug information? */
+ n = f->sizeupvalues; /* must be this many */
for (i = 0; i < n; i++)
f->upvalues[i].name = loadStringN(S, f);
}