Skip to content

Commit f7fd94e

Browse files
committed
Ensure empty error tables in scripts don't crash Valkey
1 parent 3b25c4d commit f7fd94e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/lua/script_lua.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,11 @@ void luaExtractErrorInformation(lua_State *lua, errorInfo *err_info) {
16681668
err_info->ignore_err_stats_update = lua_toboolean(lua, -1);
16691669
}
16701670
lua_pop(lua, 1);
1671+
1672+
if (err_info->msg == NULL) {
1673+
// Ensure we never return a NULL msg.
1674+
err_info->msg = sdsnew("ERR unknown error");
1675+
}
16711676
}
16721677

16731678
/* This is the core of our Lua debugger, called each time Lua is about

tests/unit/scripting.tcl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,4 +2464,21 @@ start_server {tags {"scripting"}} {
24642464
# Using a null byte never seemed to work with functions, so
24652465
# we don't have a test for that case.
24662466
}
2467+
2468+
test {EVAL - explicit error() call handling} {
2469+
# error("simple string error")
2470+
assert_error {ERR user_script:1: simple string error script: *} {
2471+
r eval "error('simple string error')" 0
2472+
}
2473+
2474+
# error({"err": "ERR table error"})
2475+
assert_error {ERR table error script: *} {
2476+
r eval "error({err='ERR table error'})" 0
2477+
}
2478+
2479+
# error({})
2480+
assert_error {ERR unknown error script: *} {
2481+
r eval "error({})" 0
2482+
}
2483+
}
24672484
}

0 commit comments

Comments
 (0)