Skip to content

Commit dd5c23d

Browse files
committed
Makes Lua::run const
1 parent 4fef318 commit dd5c23d

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/engine/lua.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const char *Lua::blob_reader(lua_State *L, void *ud, size_t *size) {
121121
#endif
122122

123123

124-
int Lua::run(Transaction *t, const std::string &str) {
124+
int Lua::run(Transaction *t, const std::string &str) const {
125125
#ifdef WITH_LUA
126126
std::string luaRet;
127127
const char *a = NULL;
@@ -138,10 +138,12 @@ int Lua::run(Transaction *t, const std::string &str) {
138138
luaL_setfuncs(L, mscLuaLib, 0);
139139
lua_setglobal(L, "m");
140140

141+
LuaScriptBlob blob(m_blob);
142+
141143
#ifdef WITH_LUA_5_1
142-
int rc = lua_load(L, Lua::blob_reader, &m_blob, m_scriptName.c_str());
144+
int rc = lua_load(L, Lua::blob_reader, &blob, m_scriptName.c_str());
143145
#else
144-
int rc = lua_load(L, Lua::blob_reader, &m_blob, m_scriptName.c_str(),
146+
int rc = lua_load(L, Lua::blob_reader, &blob, m_scriptName.c_str(),
145147
NULL);
146148
#endif
147149
if (rc != LUA_OK) {

src/engine/lua.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ class LuaScriptBlob {
4343
}
4444
}
4545

46+
LuaScriptBlob(const LuaScriptBlob &other) :
47+
m_data(NULL),
48+
m_len(other.m_len) {
49+
m_data = (unsigned char *)std::malloc(m_len);
50+
// FIXME: m_data NULL?
51+
std::memcpy(m_data, other.m_data, m_len);
52+
}
53+
4654

4755
void write(const void *data, size_t len) {
4856
unsigned char *d = (unsigned char *)realloc((unsigned char *)m_data, len + m_len);
@@ -68,7 +76,7 @@ class Lua {
6876
Lua() { }
6977

7078
bool load(const std::string &script, std::string *err);
71-
int run(Transaction *t, const std::string &str="");
79+
int run(Transaction *t, const std::string &str="") const;
7280
static bool isCompatible(const std::string &script, Lua *l, std::string *error);
7381

7482
#ifdef WITH_LUA

test/cppcheck_suppressions.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ functionStatic:headers/modsecurity/transaction.h:437
4646
duplicateBranch:src/audit_log/audit_log.cc:223
4747
unreadVariable:src/request_body_processor/multipart.cc:435
4848
stlcstrParam:src/audit_log/writer/parallel.cc:145
49-
functionStatic:src/engine/lua.h:70
50-
functionStatic:src/engine/lua.h:71
49+
functionStatic:src/engine/lua.h:78
50+
functionStatic:src/engine/lua.h:79
5151
functionConst:src/utils/geo_lookup.h:49
5252
useInitializationList:src/operators/rbl.h:69
5353
constStatement:test/common/modsecurity_test.cc:82

0 commit comments

Comments
 (0)