|
| 1 | +--[[ |
| 2 | +SPDX-License-Identifier: ISC |
| 3 | +Copyright (c) 2023-2025, Sergey Bronnikov. |
| 4 | +
|
| 5 | +Parameter 'what' of 'debug.getinfo' cannot start with '>', |
| 6 | +https://www.lua.org/bugs.html#5.4.2-2 |
| 7 | +
|
| 8 | +Access to debug information in line hook of stripped function, |
| 9 | +https://github.com/lua/lua/commit/ae5b5ba529753c7a653901ffc29b5ea24c3fdf3a |
| 10 | +
|
| 11 | +Return hook may not see correct values for active local variables when function returns, |
| 12 | +https://www.lua.org/bugs.html#5.3.0-4 |
| 13 | +
|
| 14 | +The PC out-of-range in lj_debug_frameline(), |
| 15 | +https://github.com/LuaJIT/LuaJIT/issues/1369 |
| 16 | +
|
| 17 | +LuaJIT segfault in debug.getinfo(), |
| 18 | +https://github.com/LuaJIT/LuaJIT/issues/509 |
| 19 | +
|
| 20 | +Synopsis: debug.getinfo([thread,] function [, what]) |
| 21 | +]] |
| 22 | + |
| 23 | +local luzer = require("luzer") |
| 24 | + |
| 25 | +local what = { |
| 26 | + "n", -- fills in the field name and namewhat. |
| 27 | + "S", -- fills in the fields source, short_src, linedefined, |
| 28 | + -- lastlinedefined, and what. |
| 29 | + "l", -- fills in the field currentline. |
| 30 | + "u", -- fills in the field nups. |
| 31 | + "f", -- pushes onto the stack the function that is running at |
| 32 | + -- the given level. |
| 33 | + "L", -- pushes onto the stack a table whose indices are the |
| 34 | + -- numbers of the lines that are valid on the function. |
| 35 | +} |
| 36 | + |
| 37 | +local what_modes |
| 38 | + |
| 39 | +local hook_mask = { |
| 40 | + "c", -- the hook is called every time Lua calls a function. |
| 41 | + "r", -- the hook is called every time Lua returns from a function. |
| 42 | + "l", -- the hook is called every time Lua enters a new line of code. |
| 43 | +} |
| 44 | + |
| 45 | +local loadstring = type(loadstring) == "function" and loadstring or load |
| 46 | + |
| 47 | +local function debug_hook() |
| 48 | + debug.getinfo(1, table.concat(what_modes)) |
| 49 | +end |
| 50 | + |
| 51 | +local function TestOneInput(buf) |
| 52 | + local fdp = luzer.FuzzedDataProvider(buf) |
| 53 | + |
| 54 | + -- Generate a random 'what'. |
| 55 | + what_modes = {} |
| 56 | + local n_modes = fdp:consume_integer(0, #what) |
| 57 | + for _ = 0, n_modes do |
| 58 | + table.insert(what_modes, fdp:oneof(what)) |
| 59 | + end |
| 60 | + |
| 61 | + -- Generate a random hook mask. |
| 62 | + local n_hook_mask = fdp:consume_integer(0, #hook_mask) |
| 63 | + local mask = {} |
| 64 | + for _ = 0, n_hook_mask do |
| 65 | + table.insert(mask, fdp:oneof(hook_mask)) |
| 66 | + end |
| 67 | + |
| 68 | + debug.sethook(debug_hook, table.concat(mask)) |
| 69 | + assert(loadstring(buf))() |
| 70 | + debug.sethook() -- Turn off the hook. |
| 71 | +end |
| 72 | + |
| 73 | +local args = { |
| 74 | + artifact_prefix = "debug_getinfo_", |
| 75 | +} |
| 76 | +luzer.Fuzz(TestOneInput, nil, args) |
0 commit comments