From 257bcd1f7a590aff9b26d17aa83f04eaeab897d3 Mon Sep 17 00:00:00 2001 From: dmiller Date: Fri, 9 Oct 2026 14:41:47 +0000 Subject: [PATCH] Exert more control over NSE library search path --- nse_main.cc | 7 +++++++ nse_main.lua | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/nse_main.cc b/nse_main.cc index 9a9b721f7..fb45359dc 100644 --- a/nse_main.cc +++ b/nse_main.cc @@ -957,6 +957,13 @@ void open_nse (void) lua_atpanic(L_NSE, panic); lua_settop(L_NSE, 0); + /* Do not allow environment variables to override the module search path. + * We do this here instead of in init_main to ensure we control all + * standard library loads as well. + */ + lua_pushboolean(L_NSE, 1); + lua_setfield(L_NSE, LUA_REGISTRYINDEX, "LUA_NOENV"); + lua_pushcfunction(L_NSE, nseU_traceback); lua_pushcfunction(L_NSE, init_main); lua_pushlightuserdata(L_NSE, &o.chosenScripts); diff --git a/nse_main.lua b/nse_main.lua index 1c172189e..a1b5d990c 100644 --- a/nse_main.lua +++ b/nse_main.lua @@ -144,7 +144,11 @@ do -- Add loader to look in nselib/?.lua (nselib/ can be in multiple places) return "\n\tNSE failed to find "..name.." in search paths."; end end - insert(package.searchers, 1, loader); + -- Replace all file-path searchers with our fetchfile searcher + package.searchers = { + package.searchers[1], -- Original preload searcher + loader, -- Our fetchfile searcher + } end local lpeg = require "lpeg";