diff mbox series

[10/13] run_lua_script: check input parms

Message ID 20240221082221.11997-11-stefano.babic@swupdate.org
State Accepted
Delegated to: Stefano Babic
Headers show
Series Extend Lua Environemnt and post-failure scripts | expand

Commit Message

Stefano Babic Feb. 21, 2024, 8:22 a.m. UTC
Moving the Lua state outside the function, parameters must be checked
for consistency.

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

--
2.34.1
diff mbox series

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index 72190383..78e27576 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -209,9 +209,14 @@  int run_lua_script(lua_State *L, const char *script, const char *function, char
 	int ret;
 	const char *output;

-	if (luaL_loadfile(L, script)) {
-		ERROR("ERROR loading %s", script);
-		return -1;
+	if (!function || !L)
+		return -EINVAL;
+
+	if (script) {
+		if (luaL_loadfile(L, script)) {
+			ERROR("ERROR loading %s", script);
+			return -1;
+		}
 	}

 	ret = lua_pcall(L, 0, 0, 0);