Project

General

Profile

Actions

Bug #9072

closed
VJ VJ

lua: flowvar/flowint set() returns its argument (return 1 without pushing a result)

Bug #9072: lua: flowvar/flowint set() returns its argument (return 1 without pushing a result)

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: C-function stack-contract bug (misleading return value)
  • Component: src/util-lua-flowvarlib.c (LuaFlowvarSet), src/util-lua-flowintlib.c (LuaFlowintSet)

Description

Both setters end with return 1 but never push a result:

src/util-lua-flowvarlib.c:125

    FlowVarAddIdValue(f, *flowvar_id, buf, (uint16_t)len);
    return 1;

src/util-lua-flowintlib.c:112
    FlowVarAddInt(f, *flowvar_id, value);
    return 1;

Lua takes wanted results from the top of the stack, so the returned value is the function's last argument: fv:set("abc") returns "abc", fv:set("abc", 2) returns 2, fi:set(5) returns 5. The docs document no return value, and if fv:set(...) then is always true, so scripts cannot detect success and can silently store a bogus value.

Reachable in rule lua: and output lua scripts whenever a flow is present (luaxform errors earlier on a missing flow).

Fix direction

return 0; (or push a boolean/nil and return 1).

Tests

lua-flowvar-set-return / lua-flowint-set-return: assert set() yields no value (or nil), never the argument.


Subtasks 1 (0 open — 1 closed)

Bug #9322: lua: flowvar/flowint set() returns its argument (return 1 without pushing a result) (8.0.x backport)ClosedVictor JulienActions
Actions

Also available in: PDF Atom