diff mbox series

lua: check for valid pointer before setting bootenv

Message ID 20240215151719.115580-1-stefano.babic@swupdate.org
State Accepted
Delegated to: Stefano Babic
Headers show
Series lua: check for valid pointer before setting bootenv | expand

Commit Message

Stefano Babic Feb. 15, 2024, 3:17 p.m. UTC
Check if the user data pointer pushed to the stack is valid before
accessing it.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 corelib/lua_interface.c | 3 +++
 1 file changed, 3 insertions(+)

--
2.34.1
diff mbox series

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index a9e30b33..2bd8e6cf 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -906,6 +906,9 @@  static int l_set_bootenv(lua_State *L) {
 	const char *name = luaL_checkstring(L, 1);
 	const char *value = luaL_checkstring(L, 2);

+	if (!bootenv)
+		return -1;
+
 	if (name && strlen(name))
 		dict_set_value(bootenv, name, value ? value : "");
 	lua_pop(L, 2);