• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 22550902417

01 Mar 2026 07:32PM UTC coverage: 68.401% (-5.3%) from 73.687%
22550902417

Pull #14922

github

web-flow
github-actions: bump actions/upload-artifact from 6.0.0 to 7.0.0

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 6.0.0 to 7.0.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: 7.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #14922: github-actions: bump actions/upload-artifact from 6.0.0 to 7.0.0

218243 of 319063 relevant lines covered (68.4%)

3284926.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.86
/src/util-lua.c
1
/* Copyright (C) 2014-2022 Open Information Security Foundation
2
 *
3
 * You can copy, redistribute or modify this Program under the terms of
4
 * the GNU General Public License version 2 as published by the Free
5
 * Software Foundation.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * version 2 along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
 * 02110-1301, USA.
16
 */
17

18
/**
19
 * \file
20
 *
21
 * \author Victor Julien <victor@inliniac.net>
22
 *
23
 * Common function for Lua
24
 */
25

26
#include "suricata-common.h"
27
#include "detect.h"
28
#include "pkt-var.h"
29
#include "conf.h"
30

31
#include "threads.h"
32
#include "threadvars.h"
33
#include "tm-threads.h"
34

35
#include "util-print.h"
36
#include "util-unittest.h"
37

38
#include "util-debug.h"
39

40
#include "output.h"
41
#include "app-layer-htp.h"
42
#include "app-layer.h"
43
#include "app-layer-parser.h"
44
#include "util-privs.h"
45
#include "util-buffer.h"
46
#include "util-proto-name.h"
47
#include "util-logopenfile.h"
48
#include "util-time.h"
49

50
#include "lua.h"
51
#include "lualib.h"
52
#include "lauxlib.h"
53

54
#include "util-lua.h"
55
#include "util-lua-sandbox.h"
56

57
lua_State *LuaGetState(void)
58
{
×
59
    lua_State *s = NULL;
×
60
    s = luaL_newstate();
×
61
    return s;
×
62
}
×
63

64
void LuaReturnState(lua_State *s)
65
{
×
66
    if (s != NULL) {
×
67
        /* clear the stack */
68
        while (lua_gettop(s) > 0) {
×
69
            lua_pop(s, 1);
×
70
        }
×
71
        lua_close(s);
×
72
    }
×
73
}
×
74

75
/* key for tv (threadvars) pointer */
76
const char lua_ext_key_tv[] = "suricata:lua:tv:ptr";
77
/* key for tx pointer */
78
const char lua_ext_key_tx[] = "suricata:lua:tx:ptr";
79
/* key for tx id */
80
const char lua_ext_key_tx_id[] = "suricata:lua:tx_id";
81
/* key for p (packet) pointer */
82
const char lua_ext_key_p[] = "suricata:lua:pkt:ptr";
83
/* key for f (flow) pointer */
84
const char lua_ext_key_flow[] = "suricata:lua:flow:ptr";
85
/* key for flow lock hint bool */
86
const char lua_ext_key_flow_lock_hint[] = "suricata:lua:flow:lock_hint";
87
/* key for direction */
88
const char lua_ext_key_direction[] = "suricata:lua:direction";
89

90
/* key for pa (packet alert) pointer */
91
const char lua_ext_key_pa[] = "suricata:lua:pkt:alert:ptr";
92
/* key for s (signature) pointer */
93
const char lua_ext_key_s[] = "suricata:lua:signature:ptr";
94
/* key for file pointer */
95
const char lua_ext_key_file[] = "suricata:lua:file:ptr";
96
/* key for DetectEngineThreadCtx pointer */
97
const char lua_ext_key_det_ctx[] = "suricata:lua:det_ctx:ptr";
98
/* key for streaming buffer pointer */
99
const char lua_ext_key_streaming_buffer[] = "suricata:lua:streaming_buffer:ptr";
100

101
/** \brief get tv pointer from the lua state */
102
ThreadVars *LuaStateGetThreadVars(lua_State *luastate)
103
{
×
104
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_tv);
×
105
    lua_gettable(luastate, LUA_REGISTRYINDEX);
×
106
    void *tv = lua_touserdata(luastate, -1);
×
107
    return (ThreadVars *)tv;
×
108
}
×
109

110
void LuaStateSetThreadVars(lua_State *luastate, ThreadVars *tv)
111
{
8✔
112
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_tv);
8✔
113
    lua_pushlightuserdata(luastate, (void *)tv);
8✔
114
    lua_settable(luastate, LUA_REGISTRYINDEX);
8✔
115
}
8✔
116

117
/** \brief get packet pointer from the lua state */
118
Packet *LuaStateGetPacket(lua_State *luastate)
119
{
×
120
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_p);
×
121
    lua_gettable(luastate, LUA_REGISTRYINDEX);
×
122
    void *p = lua_touserdata(luastate, -1);
×
123
    return (Packet *)p;
×
124
}
×
125

126
void LuaStateSetPacket(lua_State *luastate, Packet *p)
127
{
8✔
128
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_p);
8✔
129
    lua_pushlightuserdata(luastate, (void *)p);
8✔
130
    lua_settable(luastate, LUA_REGISTRYINDEX);
8✔
131
}
8✔
132

133
/** \brief get tx pointer from the lua state */
134
void *LuaStateGetTX(lua_State *luastate)
135
{
×
136
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_tx);
×
137
    lua_gettable(luastate, LUA_REGISTRYINDEX);
×
138
    void *tx = lua_touserdata(luastate, -1);
×
139
    return tx;
×
140
}
×
141

142
/** \brief get tx id from the lua state */
143
uint64_t LuaStateGetTxId(lua_State *luastate)
144
{
×
145
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_tx_id);
×
146
    lua_gettable(luastate, LUA_REGISTRYINDEX);
×
147
    uint64_t tx_id = lua_tointeger(luastate, -1);
×
148
    return tx_id;
×
149
}
×
150
void LuaStateSetTX(lua_State *luastate, void *txptr, const uint64_t tx_id)
151
{
16✔
152
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_tx);
16✔
153
    lua_pushlightuserdata(luastate, (void *)txptr);
16✔
154
    lua_settable(luastate, LUA_REGISTRYINDEX);
16✔
155

156
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_tx_id);
16✔
157
    lua_pushinteger(luastate, tx_id);
16✔
158
    lua_settable(luastate, LUA_REGISTRYINDEX);
16✔
159
}
16✔
160

161
Flow *LuaStateGetFlow(lua_State *luastate)
162
{
50✔
163
    Flow *f = NULL;
50✔
164

165
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_flow);
50✔
166
    lua_gettable(luastate, LUA_REGISTRYINDEX);
50✔
167
    f = lua_touserdata(luastate, -1);
50✔
168

169
    /* need flow lock hint */
170
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_flow_lock_hint);
50✔
171
    lua_gettable(luastate, LUA_REGISTRYINDEX);
50✔
172

173
    return f;
50✔
174
}
50✔
175

176
void LuaStateSetFlow(lua_State *luastate, Flow *f)
177
{
24✔
178
    /* flow */
179
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_flow);
24✔
180
    lua_pushlightuserdata(luastate, (void *)f);
24✔
181
    lua_settable(luastate, LUA_REGISTRYINDEX);
24✔
182

183
    /* flow lock status hint */
184
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_flow_lock_hint);
24✔
185
    /* locking is not required, set to 0 for backwards compatibility */
186
    lua_pushboolean(luastate, 0);
24✔
187
    lua_settable(luastate, LUA_REGISTRYINDEX);
24✔
188
}
24✔
189

190
/** \brief get packet alert pointer from the lua state */
191
PacketAlert *LuaStateGetPacketAlert(lua_State *luastate)
192
{
×
193
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_pa);
×
194
    lua_gettable(luastate, LUA_REGISTRYINDEX);
×
195
    void *pa = lua_touserdata(luastate, -1);
×
196
    return (PacketAlert *)pa;
×
197
}
×
198

199
void LuaStateSetPacketAlert(lua_State *luastate, PacketAlert *pa)
200
{
×
201
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_pa);
×
202
    lua_pushlightuserdata(luastate, (void *)pa);
×
203
    lua_settable(luastate, LUA_REGISTRYINDEX);
×
204
}
×
205

206
/** \brief get signature pointer from the lua state */
207
Signature *LuaStateGetSignature(lua_State *luastate)
208
{
×
209
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_s);
×
210
    lua_gettable(luastate, LUA_REGISTRYINDEX);
×
211
    void *s = lua_touserdata(luastate, -1);
×
212
    return (Signature *)s;
×
213
}
×
214

215
void LuaStateSetSignature(lua_State *luastate, const Signature *s)
216
{
24✔
217
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_s);
24✔
218
    lua_pushlightuserdata(luastate, (void *)s);
24✔
219
    lua_settable(luastate, LUA_REGISTRYINDEX);
24✔
220
}
24✔
221

222
/** \brief get file pointer from the lua state */
223
File *LuaStateGetFile(lua_State *luastate)
224
{
×
225
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_file);
×
226
    lua_gettable(luastate, LUA_REGISTRYINDEX);
×
227
    void *file = lua_touserdata(luastate, -1);
×
228
    return (File *)file;
×
229
}
×
230

231
void LuaStateSetFile(lua_State *luastate, File *file)
232
{
×
233
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_file);
×
234
    lua_pushlightuserdata(luastate, (void *)file);
×
235
    lua_settable(luastate, LUA_REGISTRYINDEX);
×
236
}
×
237

238
/** \brief get DetectEngineThreadCtx pointer from the lua state */
239
DetectEngineThreadCtx *LuaStateGetDetCtx(lua_State *luastate)
240
{
×
241
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_det_ctx);
×
242
    lua_gettable(luastate, LUA_REGISTRYINDEX);
×
243
    void *det_ctx = lua_touserdata(luastate, -1);
×
244
    return (DetectEngineThreadCtx *)det_ctx;
×
245
}
×
246

247
void LuaStateSetDetCtx(lua_State *luastate, DetectEngineThreadCtx *det_ctx)
248
{
24✔
249
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_det_ctx);
24✔
250
    lua_pushlightuserdata(luastate, (void *)det_ctx);
24✔
251
    lua_settable(luastate, LUA_REGISTRYINDEX);
24✔
252
}
24✔
253

254
LuaStreamingBuffer *LuaStateGetStreamingBuffer(lua_State *luastate)
255
{
×
256
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_streaming_buffer);
×
257
    lua_gettable(luastate, LUA_REGISTRYINDEX);
×
258
    void *b = lua_touserdata(luastate, -1);
×
259
    return (LuaStreamingBuffer *)b;
×
260
}
×
261

262
void LuaStateSetStreamingBuffer(lua_State *luastate, LuaStreamingBuffer *b)
263
{
×
264
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_streaming_buffer);
×
265
    lua_pushlightuserdata(luastate, (void *)b);
×
266
    lua_settable(luastate, LUA_REGISTRYINDEX);
×
267
}
×
268

269
/** \brief get packet pointer from the lua state */
270
int LuaStateGetDirection(lua_State *luastate)
271
{
×
272
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_direction);
×
273
    lua_gettable(luastate, LUA_REGISTRYINDEX);
×
274
    int dir = lua_toboolean(luastate, -1);
×
275
    return dir;
×
276
}
×
277

278
void LuaStateSetDirection(lua_State *luastate, int direction)
279
{
24✔
280
    lua_pushlightuserdata(luastate, (void *)&lua_ext_key_direction);
24✔
281
    lua_pushboolean(luastate, direction);
24✔
282
    lua_settable(luastate, LUA_REGISTRYINDEX);
24✔
283
}
24✔
284

285
/** \brief dump stack from lua state to screen */
286
void LuaPrintStack(lua_State *state) {
×
287
    int size = lua_gettop(state);
×
288
    int i;
×
289

290
    for (i = 1; i <= size; i++) {
×
291
        int type = lua_type(state, i);
×
292
        printf("Stack size=%d, level=%d, type=%d, ", size, i, type);
×
293

294
        switch (type) {
×
295
            case LUA_TFUNCTION:
×
296
                printf("function %s", lua_tostring(state, i) ? "true" : "false");
×
297
                break;
×
298
            case LUA_TBOOLEAN:
×
299
                printf("bool %s", lua_toboolean(state, i) ? "true" : "false");
×
300
                break;
×
301
            case LUA_TNUMBER:
×
302
                printf("number %g", lua_tonumber(state, i));
×
303
                break;
×
304
            case LUA_TSTRING:
×
305
                printf("string `%s'", lua_tostring(state, i));
×
306
                break;
×
307
            case LUA_TTABLE:
×
308
                printf("table `%s'", lua_tostring(state, i));
×
309
                break;
×
310
            default:
×
311
                printf("other %s", lua_typename(state, type));
×
312
                break;
×
313

314
        }
×
315
        printf("\n");
×
316
    }
×
317
}
×
318

319
int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len)
320
{
6✔
321
    lua_pushlstring(luastate, (char *)input, input_len);
6✔
322
    return 1;
6✔
323
}
6✔
324

325
int LuaPushInteger(lua_State *luastate, lua_Integer n)
326
{
×
327
    lua_pushinteger(luastate, n);
×
328
    return 1;
×
329
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc