|
| 1 | +--[[ |
| 2 | +SPDX-License-Identifier: ISC |
| 3 | +Copyright (c) 2023-2025, Sergey Bronnikov. |
| 4 | +
|
| 5 | +6.4 – String Manipulation |
| 6 | +https://www.lua.org/manual/5.3/manual.html#6.4 |
| 7 | +
|
| 8 | +stack-buffer-overflow in lj_strfmt_wfnum, |
| 9 | +https://github.com/LuaJIT/LuaJIT/issues/1149 |
| 10 | +string.format("%7g",0x1.144399609d407p+401) |
| 11 | +
|
| 12 | +string.format %c bug, |
| 13 | +https://github.com/LuaJIT/LuaJIT/issues/378 |
| 14 | +
|
| 15 | +string.format doesn't take current locale decimal separator into account, |
| 16 | +https://github.com/LuaJIT/LuaJIT/issues/673 |
| 17 | +
|
| 18 | +string.format("%f") can cause a buffer overflow (only when |
| 19 | +'lua_Number' is long double!), |
| 20 | +https://www.lua.org/bugs.html#5.3.0-1 |
| 21 | +
|
| 22 | +string.format may get buffer as an argument when there are missing |
| 23 | +arguments and format string is too long, |
| 24 | +https://www.lua.org/bugs.html#5.1.4-7 |
| 25 | +
|
| 26 | +string.format("%") may read past the string, |
| 27 | +https://www.lua.org/bugs.html#5.1.1-3 |
| 28 | +
|
| 29 | +Option '%q' in string.formatE does not handle '\r' correctly, |
| 30 | +https://www.lua.org/bugs.html#5.1-4 |
| 31 | +
|
| 32 | +FFI: Support FFI numbers in string.format() and buf:putf(), |
| 33 | +https://github.com/LuaJIT/LuaJIT/commit/1b7171c3 |
| 34 | +
|
| 35 | +[0014] CRASH detected in lj_ir_kgc due to a fault at or |
| 36 | +near 0x00007ff7f3274008 leading to SIGSEGV, |
| 37 | +https://github.com/LuaJIT/LuaJIT/issues/1203 |
| 38 | +
|
| 39 | +Synopsis: string.format (formatstring, ···) |
| 40 | +]] |
| 41 | + |
| 42 | +-- q: booleans, nil, numbers, and strings. |
| 43 | +-- A, a, E, e, f, G, and g: number. |
| 44 | +-- c, d, i, o, u, X, and x: integer. |
| 45 | +-- A and a (hexadecimal floats) do not support modifiers. |
| 46 | +-- s: string |
| 47 | +-- p: pointer returned by lua_topointer |
| 48 | + |
| 49 | +local luzer = require("luzer") |
| 50 | +local test_lib = require("lib") |
| 51 | + |
| 52 | +local function TestOneInput(buf, _size) |
| 53 | + local fdp = luzer.FuzzedDataProvider(buf) |
| 54 | + os.setlocale(test_lib.random_locale(fdp), "all") |
| 55 | + local len = fdp:consume_number(0, test_lib.MAX_INT) |
| 56 | + local formatstring = fdp:consume_string(len) |
| 57 | + local values = {} -- FIXME |
| 58 | + assert((formatstring):format(unpack(values)) == |
| 59 | + string.format(formatstring, unpack(values))) |
| 60 | +end |
| 61 | + |
| 62 | +local args = { |
| 63 | + max_len = 4096, |
| 64 | + artifact_prefix = "string_format_", |
| 65 | +} |
| 66 | +luzer.Fuzz(TestOneInput, nil, args) |
0 commit comments