Project

General

Profile

Actions

Bug #9079

closed
VJ VJ

lua: API/doc inconsistencies (thread_info, file.tx_id, tuple arity, app_layer_proto, get availability)

Bug #9079: lua: API/doc inconsistencies (thread_info, file.tx_id, tuple arity, app_layer_proto, get availability)

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); code-confirmed
  • Class: API/documentation inconsistencies and minor behavior bugs
  • Components: src/util-lua-util.c, src/util-lua.c, src/util-lua-filelib.c, src/util-lua-packetlib.c, src/util-lua-flowlib.c, docs

Items

  1. util.thread_info() always fails for buffer- and tx-hook rules. DetectLuaMatchBuffer (detect-lua.c:238-293) and DetectLuaAppMatchCommon (:341-382) never call LuaStateSetThreadVars (only the packet path :325 does), so thread_info returns "internal error: no tv" (util-lua-util.c:31), contradicting the user guide.
  2. file:tx_id() silently returns 0 when no tx is set. LuaStateGetTxId() returns 0 for an unset registry entry (util-lua.c:143-149), consumed by util-lua-filelib.c:62; rule/streaming-without-transaction contexts get 0 instead of an error/nil.
  3. tuple() arity depends on the packet/flow. packet:tuple() and flow:tuple() return 1 value for non-IP/unknown-L3 and 6 otherwise (util-lua-packetlib.c:138-156, util-lua-flowlib.c:205-220); undocumented, scripts destructuring 6 get nils and may error in formatting.
  4. flow:app_layer_proto() returns nil for unknown alproto while the documentation promises "unknown" (util-lua-flowlib.c:94-98).
  5. packet.get()/flow.get() availability is context-dependent (buffer/app-layer/transform contexts return nil,msg; detect-lua.c:260,359 pass NULL and transform states never set the keys) while the docs describe them as returning the current packet/flow.

Fix direction

Document the real contracts and, where inexpensive, make the behavior match the docs: set ThreadVars in the buffer/app paths, return "unknown" for unknown alproto, document tuple arity, decide tx_id semantics (error vs 0). No memory-safety impact.

Tests

lua-util-thread-info, lua-file-get-txid-no-tx, lua-packet-tuple-nonip, lua-flow-tuple-l3unknown, lua-flow-app-proto-unknown, lua-packet-get-no-packet.


Subtasks 1 (0 open — 1 closed)

Bug #9329: lua: API/doc inconsistencies (thread_info, file.tx_id, tuple arity, app_layer_proto, get availability) (8.0.x backport)ClosedVictor JulienActions

JI Updated by Jason Ish about 1 month ago Actions #1

  • Status changed from New to In Review
  • Assignee set to Victor Julien

MR1382

JI Updated by Jason Ish 27 days ago Actions #2

  • Subtask #9329 added

JI Updated by Jason Ish 26 days ago Actions #3

  • Status changed from In Review to Closed

JI Updated by Jason Ish 8 days ago Actions #4

  • Private changed from Yes to No
Actions

Also available in: PDF Atom