Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Luacov with Wireshark Lua plugin #55

Open
shakthimaan opened this issue Jan 31, 2018 · 4 comments
Open

Luacov with Wireshark Lua plugin #55

shakthimaan opened this issue Jan 31, 2018 · 4 comments

Comments

@shakthimaan
Copy link

I have installed luacov (version 0.12.0-1) using luarocks. I am trying to use the same with a Wireshark Lua dissector plugin.

I have included the following in the top of the Lua dissector plugin:

local luacov = require("luacov")

I start Wireshark as follows:

$ wireshark -r capture.pcapng -X lua_script:dissector.lua

But, the plugin fails to load with the message "~/.luarocks/share/lua/5.1/luacov/hook.lua:26:attempt to index global 'debug' (a function value)".

How to use luacov with Wireshark Lua plugins?

@ignacio
Copy link

ignacio commented Jan 31, 2018 via email

@shakthimaan
Copy link
Author

In hook.lua, when the local variable "name" is assigned the full path of the Lua plugin prefixed by "@", the coverage statistics get generated. Bascially, the following is used to retrieve the name:

  local name = debug.getinfo(level, "S").source -- returns "@dissector.lua"

So, the following hard-coded assginment works:

  local name = "@dissector.lua"
  local prefixed_name = string.match(name, "^@(.*)")

Why is the debug module or function used to retrieve the path to the Wireshark Lua plugin? Are there any other alternatives possible, or is there anything that can be set in the Wireshark Lua plugin to satisfy "debug"?

@Lekensteyn
Copy link

Lekensteyn commented Sep 6, 2018

Check wireshark documentation. They seem to be replacing the debug module with a debug function.
Probably for sandboxing reasons.

I don't think it was intentionally done. Someone added logger functions such as "critical", "warn", "message", "info" and "debug". I think that these should be removed or renamed. As a workaround, you can add this to your dissector:

_G.debug = require("debug")

Internally Wireshark uses plain lua_load. It seems that Lua only prepends a @ if the luaL_loadfilex function is used: https://github.com/lua/lua/blob/v5-2/lauxlib.c#L630-L644

Going back to the Lua manual we find this:

source: the source of the chunk that created the function. If source starts with a '@', it means that the function was defined in a file where the file name follows the '@'. If source starts with a '=', the remainder of its contents describe the source in a user-dependent manner. Otherwise, the function was defined in a string where source is that string.

It looks like Wireshark (and all other applications that use lua_load directly) need fixing.

Edit: proposed Wireshark patches
https://code.wireshark.org/review/29447 - fix for missing @
https://code.wireshark.org/review/29449 - do not overwrite the debug name

ghost pushed a commit to wireshark/wireshark that referenced this issue Sep 7, 2018
The source argument should start with a '@', otherwise it is treated as
actual source code instead of a filename. This is needed for luacov. See
https://www.lua.org/manual/5.2/manual.html#lua_Debug
lunarmodules/luacov#55

Change-Id: I0a3e2da65fb6b4aaabb9173a07fdea18a788f3e3
Reviewed-on: https://code.wireshark.org/review/29447
Petri-Dish: Peter Wu <[email protected]>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <[email protected]>
ghost pushed a commit to wireshark/wireshark that referenced this issue Sep 7, 2018
The "debug" logging function overwrites the "debug" package which breaks
luacov: lunarmodules/luacov#55

Change-Id: I9b6025c060733198bfff8ea959444c09d6e08709
Reviewed-on: https://code.wireshark.org/review/29449
Petri-Dish: Peter Wu <[email protected]>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <[email protected]>
ghost pushed a commit to wireshark/wireshark that referenced this issue Sep 7, 2018
The source argument should start with a '@', otherwise it is treated as
actual source code instead of a filename. This is needed for luacov. See
https://www.lua.org/manual/5.2/manual.html#lua_Debug
lunarmodules/luacov#55

Change-Id: I0a3e2da65fb6b4aaabb9173a07fdea18a788f3e3
Reviewed-on: https://code.wireshark.org/review/29447
Petri-Dish: Peter Wu <[email protected]>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <[email protected]>
(cherry picked from commit 46e71f9)
Reviewed-on: https://code.wireshark.org/review/29464
Reviewed-by: Peter Wu <[email protected]>
@Lekensteyn
Copy link

The @ issue and debug collision fixes are now merged as v2.9.0rc0-1690-g6fa2ad4922.
The fix for the @ issue is backported as v2.6.4rc0-25-gb407f7a945 (and will end up in a future Wireshark 2.6.4 release). For the debug collision, please apply the _G.debug = require("debug") workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants