From 052ee264c6108e10b28ac19d7c270d91d14a2947 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Sat, 20 Jun 2026 14:47:45 +0200 Subject: [PATCH] fix --- src/lua_rds.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/lua_rds.c b/src/lua_rds.c index aee4874..830ed19 100644 --- a/src/lua_rds.c +++ b/src/lua_rds.c @@ -43,20 +43,31 @@ static int my_searcher(lua_State *L) { #define PREFIX "/etc/rds95/" char path[512]; - snprintf(path, sizeof(path), - PREFIX "%s.lua", - name); + size_t prefix_len = strlen(PREFIX); - for (char *p = path + strlen(PREFIX); *p; p++) { - if (*p == '.') *p = '/'; + // copy prefix + snprintf(path, sizeof(path), "%s", PREFIX); + + // copy name into path, converting '.' to '/' + size_t name_len = strlen(name); + if (prefix_len + name_len + 4 >= sizeof(path)) { // +4 for ".lua" + lua_pushfstring(L, "\n\tmodule name too long: %s", name); + return 1; } + for (size_t i = 0; i < name_len; i++) { + path[prefix_len + i] = (name[i] == '.') ? '/' : name[i]; + } + path[prefix_len + name_len] = '\0'; + + // now append .lua + strcat(path, ".lua"); + FILE *f = fopen(path, "rb"); if (!f) { lua_pushfstring(L, "\n\tno file: %s", path); return 1; } - fclose(f); if (luaL_loadfile(L, path) == LUA_OK) { @@ -66,7 +77,6 @@ static int my_searcher(lua_State *L) { lua_pushfstring(L, "\n\terror loading: %s", path); return 1; } - uint8_t init_lua(RDSEncoder* _enc) { static int mutex_initialized = 0; enc = _enc;