Commit graph

35 commits

Author SHA1 Message Date
Sina Karvandi
625e75719e
Merge branch 'dev' into claude/code-audit-improvements-prdq23 2026-08-02 10:50:02 +02:00
Claude
1abdde7702
Fix memory-safety and robustness issues in script engine and PCI ID parser
Code audit of the script engine's scanner/token handling and of the PCI ID
database parser. Each of the issues below was reproduced against the current
code before the fix and re-checked afterwards.

script-engine/scanner.c

  * An unterminated string literal ("abc or L"abc) hung the scanner in an
    endless loop: sgetc() returns EOF without consuming input, and neither
    string loop tested for it, so the token grew until allocation failed.
    Both loops now stop at EOF and report the token as UNKNOWN.

script-engine/common.c

  * AppendByte()/AppendWchar() doubled Token->MaxLen before checking whether
    the larger buffer was actually allocated. After a failed allocation MaxLen
    described memory that did not exist and the next append wrote past the end
    of the old buffer. MaxLen is now committed only on success.

  * CopyToken() allocated strlen(Value) + 1 bytes but carried over the source
    token's Len and MaxLen, so the copy's advertised capacity did not match its
    allocation, and WSTRING payloads were truncated at their first embedded
    null byte. The copy is now sized from Len/MaxLen and copied by length, with
    a fallback to the string length for the grammar tokens in parse-table.c,
    which only initialize Type and Value.

  * NewToken() set MaxLen to the value length, which is zero for an empty
    value. The 'Len >= MaxLen - 1' test in the append routines is unsigned, so
    a zero MaxLen wrapped and disabled buffer growth entirely.

  * IsUnderscore() tested 'c >= '_'', which also accepted the backtick, the
    lowercase letters, '{', '|', '}', '~' and DEL. Register scanning uses it,
    so '@rax|1' was lexed as one malformed register name instead of a register,
    an operator and a number. The pseudo-register path already compared against
    '_' directly.

  * NewTokenList() did not check the allocation of its Head buffer.

  * NewTemp() kept the last handed-out id in a static, so an exhausted temp
    list produced a token aliasing a temporary still in use, and it derived
    MaxTempNumber from an out-of-range index. It also dereferenced the new
    token without a null check.

  * FreeTemp() indexed the MAX_TEMP_COUNT-entry map with an unchecked value
    parsed out of the token text.

  * RotateLeftStringOnce() wrote to str[-1] when handed an empty string.

libhyperdbg/debugger/misc/pci-id.cpp

  * The database file was read into a malloc(Length) buffer that was never
    null-terminated, while ReadLine() walks it with strchr(). Looking up an
    absent vendor scans to the end and reads past the allocation.

  * The matched Vendor was allocated with malloc() and its Devices list head
    was only assigned once a device line was parsed, so a vendor with no
    device entries left it uninitialized and FreeVendor() walked a garbage
    pointer.

  * FreeVendor() released the device and subdevice lists but never the Vendor
    itself, leaking one per lookup for every enumerated PCI device.

  * The file handle leaked when the buffer allocation failed, ftell() and
    fread() results were unused, and several error paths leaked the Vendor or
    the not-yet-linked Device/SubDevice.

  * strncmp() compared sizeof(VendorId) bytes, which is the size of the
    pointer rather than the length of a vendor id.

  * ReadLine() passed an unclamped count to strncpy_s(), which triggers the
    invalid parameter handler for a line longer than the destination.

  * GetVendorById() ignored the GetModuleFileName() result and overwrote the
    tail of the path buffer without checking the room left in it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W3C1DuhHtqK64eEkHjKCHM
2026-08-01 14:22:52 +00:00
xmaple555
d44c726dff update variable type and add float type in script enginr 2026-07-20 23:21:34 +08:00
xmaple555
ec5fe7cc8a add float in script engine 2026-07-20 15:03:45 +08:00
xmaple555
8b6d8181a5 add struct in script engine 2026-07-19 09:39:37 +08:00
sina
3bb181fb7d refactor doxygen, variables, function names 2 2026-05-31 03:17:53 +02:00
sina
5fb4c24fe4 refactor doxygen, variables, function names 2 2026-05-31 02:21:47 +02:00
xmaple21215
8bd8950514 add include file in script engine 2026-01-06 16:38:22 +08:00
sina
43b0245fa1
fix script variable type 2025-10-21 12:56:21 +02:00
xmaple555
8b4178d416 add array and pointer in script engine 2025-10-21 16:46:49 +08:00
xmaple555
4233ade781 update pointer variable type in script engine 2025-10-15 08:01:17 +08:00
xmaple555
3577876cac fix dd_pa in scrpt-engine 2025-10-14 00:09:58 +08:00
Enzo Berry
6a89a94496 Refactor token structures and related functions in the script engine 2025-07-07 11:46:10 -07:00
xmaple555
16c60bbe7e add assignment operator in script-engine 2024-08-22 00:30:23 +08:00
xmaple555
b05414a171 update user-defined function for boolean parser 2024-08-21 03:42:03 +08:00
xmaple555
f9ca713601 update script-engine 2 2024-07-25 01:52:58 +08:00
SinaKarvandi
7ed7972554 add support for hw_pinX and hw_portX in the script engine 2024-06-21 17:09:41 +09:00
Herman Semenov
7bcf1e5c71 fix bitwise extended type, fixed memleaks, remove excess else and cmp int with EOF 2024-04-05 16:13:13 +03:00
Sinaei
1f7c5ca835 fix script-engine warnings 2024-03-17 20:33:02 +09:00
xmaple555
29d79991e4 add user-defined function and variable type in script engine 2024-03-02 01:59:33 +08:00
xmaple555
e6dbc3f49e Add hexadecimal escape sequence as wstring parameter for wstring function in script engine 2023-11-24 04:53:30 +08:00
xmaple555
60fbec6936 Add hexadecimal escape sequence as string parameter for string function in script engine 2023-11-23 01:07:20 +08:00
xmaple555
5b017c2bf7 Support character underscore for pseudo register name 2023-11-13 15:01:54 +08:00
xmaple555
cb1908d4d0 Update wstring as parameter for wstring functions in script engine 2023-11-09 00:48:26 +08:00
unknown
01735cfd3e reshaping script side from hv to kd 2023-01-18 20:23:40 +09:00
mhgholamrezaei
e6814423ce fix Script Engine bugs 2022-05-19 22:02:19 +09:00
mhgholamrezaei
3ab464c117 fix Script Engine bug 2022-05-19 20:16:57 +09:00
SinaKarvandi
831b7e7071 add doxygen headers for script engine 2022-05-18 23:44:03 +04:30
mhgholamrezaei
5807943a12 Merge branch 'dev' of https://github.com/HyperDbg/HyperDbg into dev 2022-05-18 22:51:42 +09:00
mhgholamrezaei
5ecb671bda solve end of line space problem in Script Engine scanner 2022-05-18 22:51:04 +09:00
SinaKarvandi
571426e8e9 update script engine doxygens 2022-05-18 18:17:30 +04:30
mhgholamrezaei
95fda88ef8 avoid searching symbols without bang character 2022-05-18 22:00:18 +09:00
mhgholamrezaei
556f47b7f6 solve Script Engine scanner bug 2022-05-18 20:08:18 +09:00
mhgholamrezaei
e2c3a97e98 cleanup Script Engine 2022-05-18 16:00:16 +09:00
SinaKarvandi
e394346dc1 change script engine directory order 2022-05-10 15:27:06 +04:30
Renamed from hyperdbg/script-engine/scanner.c (Browse further)