From 3f108aae75cdfaba68895d973ffeccf1c884506e Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Mon, 10 Apr 2023 03:02:51 -0700 Subject: [PATCH] Scripting: Re-fix some Lua string handling (fixes #2877) --- src/script/engines/lua.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/script/engines/lua.c b/src/script/engines/lua.c index 2a03ba052..c37bd607e 100644 --- a/src/script/engines/lua.c +++ b/src/script/engines/lua.c @@ -911,7 +911,11 @@ bool _luaLoad(struct mScriptEngineContext* ctx, const char* filename, struct VFi lastSlash = lastBackslash; } if (lastSlash) { - strlcpy(dirname, filename, lastSlash - filename); + size_t len = lastSlash - filename + 1; + if (sizeof(dirname) < len) { + len = sizeof(dirname); + } + strlcpy(dirname, filename, len); } snprintf(name, sizeof(name), "@%s", filename); }