"attempt to index global 'base' (a nil value)" - Wireshark 3.6.2-2

asked 2024-10-15 00:02:02 +0000

gsram gravatar image

updated 2024-10-15 00:03:07 +0000

Hi!

I am using a custom dissector in conjunction with Nordic's nRF BLE Sniffer tooling. In my installation scripts, I have pinned the Wireshark version to 3.6.2-2 because of some of the differences between how Nordic's tooling operates and some differences between Lua 5.2 and 5.4. On Ubuntu 22.04 I keep getting the error "attempt to index global 'base' (a nil value)" when using base.DEC, base.HEX in my dissector code.

To successfully install this version, I install the following packages from apt:

  • wireshark=3.6.2-2
  • wireshark-qt=3.6.2-2
  • wireshark-dev=3.6.2-2
  • wireshark-common=3.6.2-2

Any ideas why the definition for "base" is missing from my installation?

Thanks!

edit retag flag offensive close merge delete

Comments

Do you have a small piece of code that shows the issue?

Chuckc gravatar imageChuckc ( 2024-10-15 00:17:56 +0000 )edit

Hi Chuck,

This code throws the error on my installation of 3.6.2-2:

local my_proto = Proto("my_dissector", "My Dissector")

my_proto.fields  = {
    device_type = ProtoField.uint8("test", "test", base.DEC),
} 

function my_proto.dissector(buffer, pinfo, tree)
    -- Custom dissector code here
end

local btatt_table = DissectorTable.get("btatt.handle")

btatt_table:add("0-200", my_proto)`

Here is the error:

Lua: Error during loading:
...rant/.local/lib/wireshark/plugins/ble_sram_dissector.lua:3: attempt to index global 'base' (a nil value)
stack traceback:
    ...rant/.local/lib/wireshark/plugins/ble_sram_dissector.lua:3: in main chunk

The same code does not have any issues loading in the latest apt version 4.4.0.

Thanks!

gsram gravatar imagegsram ( 2024-10-15 00:26:26 +0000 )edit

(sample capture attached to 18267: Assertion due to incorrect mask for btatt.battery_power_state.)
Works on Windows: Version 3.6.2 (v3.6.2-0-g626020d9b3c3)
Will need to build on Ubuntu to see if I can recreate issue.

local my_proto = Proto("my_dissector", "My Dissector")

local device_type = ProtoField.uint8("my_proto.test", "test", base.DEC)
local device_hex = ProtoField.uint8("my_proto.test_hex", "test", base.HEX)

my_proto.fields = { device_type, device_hex }

function my_proto.dissector(buffer, pinfo, tree)
    -- Custom dissector code here
    subtree = tree:add(my_proto)
    subtree:add(device_type, 10)
    subtree:add(device_hex, 10)
end

local btatt_table = DissectorTable.get("btatt.handle")

btatt_table:add("0-200", my_proto)
Chuckc gravatar imageChuckc ( 2024-10-15 01:38:00 +0000 )edit

I believe that 3.6 needs an init.lua file to load some of the globals, it was before this commit: https://gitlab.com/wireshark/wireshar...

If the difference between Lua 5.2 and 5.4 is the issue, can you use Wireshark 4.0 or 4.2, both of which use Lua 5.2. Wireshark 3.6 is no longer supported, but 4.2 is.

johnthacker gravatar imagejohnthacker ( 2024-10-15 01:38:36 +0000 )edit

btatt fails on 3.6.2 but the dissector works with register_postdissector(my_proto)

 ** (wireshark:113242) 08:00:04.863052 [Epan WARNING] -- Dissector bug, protocol BT ATT, in packet 17817: ./epan/proto.c:11686: failed assertion "hf->bitmask != 0" (btatt.battery_power_state.present)
My Dissector
    test: 10
    test: 0x0a


print("base[DEC]: " .. base["DEC"])
print("base[HEX]: " .. base["HEX"])

--[[  Evaluated --]]

Tue 15 Oct 2024 08:06:51 AM CDT Console opened
Tue 15 Oct 2024 08:07:12 AM CDT base[DEC]: 1
Tue 15 Oct 2024 08:07:12 AM CDT base[HEX]: 2

From init.lua:

-- Display Bases
base = {
        ["NONE"] = 0,  -- none
        ["DEC"] = 1,  -- decimal
        ["HEX"] = 2,  -- hexadecimal
        ["OCT"] = 3,  -- octal

Perhaps init.lua is not being loaded on your system per @johnthacker comment above?

Chuckc gravatar imageChuckc ( 2024-10-15 13:09:14 +0000 )edit