Project

General

Profile

Actions

Bug #9073

closed
VJ VJ

lua/flowint: set() silently truncates 64-bit Lua integers to int

Bug #9073: lua/flowint: set() silently truncates 64-bit Lua integers to int

Added by Victor Julien 2 months ago. Updated 8 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Affected Versions:
Effort:
Difficulty:
Label:

Description

  • Status: present in main (9b7938aec)
  • Class: silent integer truncation (semantics/robustness)
  • Component: src/util-lua-flowintlib.c:103 (LuaFlowintSet)

Description

const int value = (int)luaL_checkinteger(L, 2);
...
FlowVarAddInt(f, *flowvar_id, value);

luaL_checkinteger yields a signed 64-bit lua_Integer; the cast truncates to int, and the value is stored in the uint32_t fv->data.fv_int.value. Examples: set(0x100000000) stores 0, set(-1) stores 4294967295, set(2^31) stores 2147483648, set(2^63-1) stores 4294967295 (GCC). Non-integral floats and strings already error via luaL_checkinteger.

Impact: packet-derived counters wrap silently; Lua flowint semantics diverge from the rule keyword's (detect-flowint.c), and value()/incr()/decr() operate on the truncated value. No memory unsafety.

Fix direction

Pick and document one semantic: reject values outside 0..UINT32_MAX with luaL_error, or make the storage/semantics 64-bit. Add a test that pins set(2^31), set(2^32), set(-1), set(2^63-1) and set(1.5).

Test

lua-flowint-bounds.


Subtasks 1 (0 open — 1 closed)

Bug #9323: lua/flowint: set() silently truncates 64-bit Lua integers to int (8.0.x backport)ClosedVictor JulienActions
Actions

Also available in: PDF Atom