Skip to content

Commit 3aca611

Browse files
committed
Fix OOB read vulnerability in kname() in lua/ldebug.c
1 parent cf7f930 commit 3aca611

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/lua/src/ldebug.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,16 @@ static const char *getobjname (Proto *p, int lastpc, int reg,
354354
*/
355355
static void kname (Proto *p, int pc, int c, const char **name) {
356356
if (ISK(c)) { /* is 'c' a constant? */
357-
TValue *kvalue = &p->k[INDEXK(c)];
358-
if (ttisstring(kvalue)) { /* literal constant? */
359-
*name = svalue(kvalue); /* it is its own name */
360-
return;
357+
int idx = INDEXK(c);
358+
/* is 'idx' a valid index?
359+
* fix for potential oob read via loading malicious binary chunk
360+
*/
361+
if (idx >= 0 && idx < p->sizek) {
362+
TValue *kvalue = &p->k[idx];
363+
if (ttisstring(kvalue)) { /* literal constant? */
364+
*name = svalue(kvalue); /* it is its own name */
365+
return;
366+
}
361367
}
362368
/* else no reasonable name found */
363369
}

0 commit comments

Comments
 (0)