Skip to content

Lua client fixes#1003

Merged
djungelorm merged 4 commits into
mainfrom
lua-client-fixes
Jul 21, 2026
Merged

Lua client fixes#1003
djungelorm merged 4 commits into
mainfrom
lua-client-fixes

Conversation

@djungelorm

Copy link
Copy Markdown
Member

Three unrelated defects in the Lua client, each fixed in its own commit.

Global leak when coercing an argument. The result of the pcall that coerces an argument was assigned to an undeclared ok, making it a global, so every call needing a coercion wrote to and left a value in the global namespace. Only ok is now declared local: the value it is assigned alongside is the loop variable holding the argument and has to stay that way, since declaring both would scope a new local to the branch and the coerced value is read after it — the argument would then be silently sent uncoerced. A comment records this.

Broken encoder.client_name. It padded a name to encoder.CLIENT_NAME_LENGTH, which is never defined, so the function raised an error whatever it was passed. It is a leftover from before the protocol used protocol buffers and nothing calls it, so it is removed.

Enumeration name never passed to its Lua type. set_values passed self._enum_name, which is never assigned; the field set when the type is constructed is _class_name, so the name reaching _create_enum_type was always nil. This is harmless today only because that function ignores the service and class names it is given and uses only the values, hence no changelog entry.

Testing. New test_coercion_does_not_leak_a_global in the Lua client tests passes a plain table where a list is expected, which is a coercion that succeeds, and asserts no global ok is left behind. Passing a list where a tuple is expected does not exercise this, as a tuple's Lua type is List, so the argument is already considered valid and no coercion is attempted.

encoder.client_name padded a name to encoder.CLIENT_NAME_LENGTH, which is not
defined anywhere, so calling it raised an error attempting arithmetic on a nil
value. It was left over from before the protocol used protocol buffers, when
the connection message carried a fixed length name; the name is now set
directly on the connection request message. Nothing called it.
The result of the pcall that coerces an argument was assigned to an undeclared
ok, which made it a global, so every call needing a coercion wrote to the
global namespace and left the value behind.

Only ok is declared local. The value it is assigned alongside is the loop
variable holding the argument, and has to stay that way: declaring both would
make a new local scoped to the branch, and the coerced value is read after it,
so the argument would silently be sent uncoerced.

The test passes a plain table where a list is expected, which is a coercion
that succeeds. Passing a list where a tuple is expected does not exercise
this, as a tuple's Lua type is List, so the argument is already considered
valid and no coercion is attempted.
set_values passed self._enum_name, which is never assigned; the field set when
the type is constructed is _class_name. The name reaching _create_enum_type was
therefore always nil. It is harmless today only because that function ignores
both the service and class names it is given, and uses only the values.
@djungelorm djungelorm added bug Something isn't working client:lua labels Jul 21, 2026
@djungelorm djungelorm added this to the 0.6.0 milestone Jul 21, 2026
@djungelorm
djungelorm merged commit 041c97f into main Jul 21, 2026
29 checks passed
@djungelorm
djungelorm deleted the lua-client-fixes branch July 21, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working client:lua

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant