Skip to content

Commit 6624a18

Browse files
kadirerdoganzimmerle
authored andcommitted
Fixed inspectFile operator does not pass FILES_TMPNAMES
pass FILES_TMPNAMES variable to lua engine Fixed Lua engine should also be aware of the variable and pass it to the target lua script main function
1 parent 05e9e7c commit 6624a18

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

Diff for: CHANGES

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
v3.0.4 - YYYY-MMM-DD (to be released)
22
-------------------------------------
33

4+
- Fix: ModSecurity 3.x inspectFile operator does not pass
5+
FILES_TMPNAMES parameter to lua engine
6+
[Issue #2204, #2205 - @kadirerdogan]
47
- XML: Remove error messages from stderr
58
[Issue #2010 - @JaiHarpalani, @zimmerle]
69
- Filter comment or blank line for pmFromFile operator

Diff for: src/engine/lua.cc

+11-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ const char *Lua::blob_reader(lua_State *L, void *ud, size_t *size) {
121121
}
122122
#endif
123123

124-
int Lua::run(Transaction *t) {
124+
125+
int Lua::run(Transaction *t, const std::string &str) {
125126
#ifdef WITH_LUA
126127
std::string luaRet;
127128
const char *a = NULL;
@@ -184,7 +185,15 @@ int Lua::run(Transaction *t) {
184185
lua_setglobal(L, "modsec");
185186

186187
lua_getglobal(L, "main");
187-
if (lua_pcall(L, 0, 1, 0)) {
188+
189+
ms_dbg_a(t, 1, str);
190+
191+
/* Put the parameter on the stack. */
192+
if (!str.empty() ) {
193+
lua_pushlstring(L, str.c_str(), str.length());
194+
}
195+
196+
if (lua_pcall(L, ((!str.empty()) ? 1 : 0), 1, 0)) {
188197
std::string e;
189198
const char *luaerr = lua_tostring(L, -1);
190199
e.assign("Failed to execute lua script: " + m_scriptName + " (main)");

Diff for: src/engine/lua.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Lua {
6969
Lua() { }
7070

7171
bool load(std::string script, std::string *err);
72-
int run(Transaction *t);
72+
int run(Transaction *t, const std::string &str="");
7373
static bool isCompatible(std::string script, Lua *l, std::string *error);
7474

7575
#ifdef WITH_LUA

Diff for: src/operators/inspect_file.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bool InspectFile::init(const std::string &param2, std::string *error) {
5151

5252
bool InspectFile::evaluate(Transaction *transaction, const std::string &str) {
5353
if (m_isScript) {
54-
return m_lua.run(transaction);
54+
return m_lua.run(transaction, str);
5555
} else {
5656
FILE *in;
5757
char buff[512];

0 commit comments

Comments
 (0)