Skip to content

Commit d668831

Browse files
authored
Merge pull request #1022 from KIMDONGYEON00/dev
Fix Redis Lua security vulnerabilities (CVE-2024-31449, CVE-2025-29844, CVE-2025-46817, CVE-2025-46819)
2 parents cb9b4d4 + 8418979 commit d668831

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

app/redis-6.2.6/deps/lua/src/lbaselib.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,14 @@ static int luaB_assert (lua_State *L) {
340340

341341

342342
static int luaB_unpack (lua_State *L) {
343-
int i, e, n;
343+
int i, e;
344+
unsigned int n;
344345
luaL_checktype(L, 1, LUA_TTABLE);
345346
i = luaL_optint(L, 2, 1);
346347
e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1));
347348
if (i > e) return 0; /* empty range */
348-
n = e - i + 1; /* number of elements */
349-
if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
349+
n = (unsigned int)e - (unsigned int)i; /* number of elements minus 1 */
350+
if (n >= INT_MAX || !lua_checkstack(L, ++n))
350351
return luaL_error(L, "too many results to unpack");
351352
lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
352353
while (i++ < e) /* push arg[i + 1...e] */

app/redis-6.2.6/deps/lua/src/llex.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ static void inclinenumber (LexState *ls) {
138138

139139

140140
void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
141+
ls->t.token = 0;
141142
ls->decpoint = '.';
142143
ls->L = L;
143144
ls->lookahead.token = TK_EOS; /* no look-ahead token */
@@ -207,20 +208,23 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) {
207208
}
208209

209210

210-
static int skip_sep (LexState *ls) {
211-
int count = 0;
211+
static size_t skip_sep (LexState *ls) {
212+
size_t count = 0;
212213
int s = ls->current;
213214
lua_assert(s == '[' || s == ']');
214215
save_and_next(ls);
215216
while (ls->current == '=') {
216217
save_and_next(ls);
217218
count++;
218219
}
219-
return (ls->current == s) ? count : (-count) - 1;
220+
221+
return (ls->current == s) ? count + 2
222+
: (count == 0) ? 1
223+
: 0;
220224
}
221225

222226

223-
static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
227+
static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) {
224228
int cont = 0;
225229
(void)(cont); /* avoid warnings when `cont' is not used */
226230
save_and_next(ls); /* skip 2nd `[' */
@@ -270,8 +274,8 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
270274
}
271275
} endloop:
272276
if (seminfo)
273-
seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),
274-
luaZ_bufflen(ls->buff) - 2*(2 + sep));
277+
seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep,
278+
luaZ_bufflen(ls->buff) - 2 * sep);
275279
}
276280

277281

@@ -346,9 +350,9 @@ static int llex (LexState *ls, SemInfo *seminfo) {
346350
/* else is a comment */
347351
next(ls);
348352
if (ls->current == '[') {
349-
int sep = skip_sep(ls);
353+
size_t sep = skip_sep(ls);
350354
luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */
351-
if (sep >= 0) {
355+
if (sep >= 2) {
352356
read_long_string(ls, NULL, sep); /* long comment */
353357
luaZ_resetbuffer(ls->buff);
354358
continue;
@@ -360,13 +364,14 @@ static int llex (LexState *ls, SemInfo *seminfo) {
360364
continue;
361365
}
362366
case '[': {
363-
int sep = skip_sep(ls);
364-
if (sep >= 0) {
367+
size_t sep = skip_sep(ls);
368+
if (sep >= 2) {
365369
read_long_string(ls, seminfo, sep);
366370
return TK_STRING;
367371
}
368-
else if (sep == -1) return '[';
369-
else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING);
372+
else if (sep == 0) /* '[=...' missing second bracket */
373+
luaX_lexerror(ls, "invalid long string delimiter", TK_STRING);
374+
return '[';
370375
}
371376
case '=': {
372377
next(ls);

app/redis-6.2.6/deps/lua/src/lparser.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,17 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
384384
struct LexState lexstate;
385385
struct FuncState funcstate;
386386
lexstate.buff = buff;
387-
luaX_setinput(L, &lexstate, z, luaS_new(L, name));
387+
TString *tname = luaS_new(L, name);
388+
setsvalue2s(L, L->top, tname);
389+
incr_top(L);
390+
luaX_setinput(L, &lexstate, z, tname);
388391
open_func(&lexstate, &funcstate);
389392
funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */
390393
luaX_next(&lexstate); /* read first token */
391394
chunk(&lexstate);
392395
check(&lexstate, TK_EOS);
393396
close_func(&lexstate);
397+
--L->top;
394398
lua_assert(funcstate.prev == NULL);
395399
lua_assert(funcstate.f->nups == 0);
396400
lua_assert(lexstate.fs == NULL);

app/redis-6.2.6/deps/lua/src/ltable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ static TValue *newkey (lua_State *L, Table *t, const TValue *key) {
434434
*/
435435
const TValue *luaH_getnum (Table *t, int key) {
436436
/* (1 <= key && key <= t->sizearray) */
437-
if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
437+
if (1 <= key && key <= t->sizearray)
438438
return &t->array[key-1];
439439
else {
440440
lua_Number nk = cast_num(key);

app/redis-6.2.6/deps/lua/src/lua_bit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ static int bit_tohex(lua_State *L)
131131
const char *hexdigits = "0123456789abcdef";
132132
char buf[8];
133133
int i;
134+
if (n == INT32_MIN) n = INT32_MIN+1;
134135
if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; }
135136
if (n > 8) n = 8;
136137
for (i = (int)n; --i >= 0; ) { buf[i] = hexdigits[b & 15]; b >>= 4; }

0 commit comments

Comments
 (0)