Skip to content

Commit 21ff8de

Browse files
committed
Bug: Tricky _PROMPT may trigger undefined behavior
1 parent 7eb1ed2 commit 21ff8de

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lua.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,13 @@ static void l_message (const char *pname, const char *msg) {
115115

116116
/*
117117
** Check whether 'status' is not OK and, if so, prints the error
118-
** message on the top of the stack. It assumes that the error object
119-
** is a string, as it was either generated by Lua or by 'msghandler'.
118+
** message on the top of the stack.
120119
*/
121120
static int report (lua_State *L, int status) {
122121
if (status != LUA_OK) {
123122
const char *msg = lua_tostring(L, -1);
123+
if (msg == NULL)
124+
msg = "(error message not a string)";
124125
l_message(progname, msg);
125126
lua_pop(L, 1); /* remove message */
126127
}

0 commit comments

Comments
 (0)