diff --git a/client/cmdscript.c b/client/cmdscript.c index f97e8fe9c..e506b1a37 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -142,9 +142,11 @@ static int CmdScriptRun(const char *Cmd) { bool found = false; int error; - if (get_my_executable_directory() != NULL) { - char script_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; - strcpy(script_path, get_my_executable_directory()); + const char* exec_path = get_my_executable_directory(); + + if (exec_path != NULL) { + char script_path[strlen(exec_path) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; + strcpy(script_path, exec_path); strcat(script_path, LUA_SCRIPTS_DIRECTORY); strcat(script_path, script_name); strcat(script_path, suffix); diff --git a/client/scripting.c b/client/scripting.c index 1c021e591..a823df8d7 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1133,38 +1133,41 @@ int set_pm3_libraries(lua_State *L) { //--add to the LUA_PATH (package.path in lua) // so we can load scripts from various places: - if (get_my_executable_directory() != NULL) { + const char *exec_path = get_my_executable_directory(); + if (exec_path != NULL) { // from the ./luascripts/ directory - char scripts_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(scripts_path, get_my_executable_directory()); + char scripts_path[strlen(exec_path) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(scripts_path, exec_path); strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); // from the ./lualib/ directory - char libraries_path[strlen(get_my_executable_directory()) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(libraries_path, get_my_executable_directory()); + char libraries_path[strlen(exec_path) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(libraries_path, exec_path); strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); } - char *userpath = getenv("HOME"); - if (userpath != NULL) { + char *user_path = getenv("HOME"); + if (user_path != NULL) { // from the ~/.proxmark3/luascripts/ directory - char scripts_path[strlen(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(scripts_path, userpath); + char scripts_path[strlen(user_path) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(scripts_path, user_path); strcat(scripts_path, LUA_PM3_USER_DIRECTORY); strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); - // from the ~/.proxmark3/lualib/ directory - char libraries_path[strlen(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(libraries_path, userpath); + + // from the ~/.proxmark3/lualib/ directory + char libraries_path[strlen(user_path) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(libraries_path, user_path); strcat(libraries_path, LUA_PM3_USER_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); } - { + + if (strlen(LUA_PM3_SYSTEM_DIRECTORY) != 0 || strlen(LUA_SCRIPTS_DIRECTORY) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0 ) { // from the /usr/local/share/proxmark3/luascripts/ directory char scripts_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, LUA_PM3_SYSTEM_DIRECTORY);