Skip to content

Harden dir commands - #112

Merged
DrPitre merged 2 commits into
nitros9project:mainfrom
tlindner:harden-dir-commands
Nov 9, 2026
Merged

DrPitre merged 2 commits into
nitros9project:mainfrom
tlindner:harden-dir-commands

Conversation

@tlindner

@tlindner tlindner commented Nov 9, 2026

Copy link
Copy Markdown
Member

Harden dir in decb, os9, cecb and dgndos against damaged images
decb dir: a FAT chain that loops back on itself hung the listing. The new
_decb_gs_chain() stops after 256 links with EOS_WT; dir shows "?" for that
file and lists the rest, and _decb_gs_size uses it too. Over-long paths are
refused instead of overflowing a buffer, a disk name that fills its sector
is printed without reading past it, unprintable characters are escaped, an
unreadable directory sector no longer hides the entries after it, and the
image is closed.

os9 dir: paths are bounded, and an empty one is refused instead of being
read before its start. A 29-byte name without an ending is copied with a
limit. With -r every directory is listed once per argument: one reached
through several entries was listed again for each way to it, which grew
exponentially. Directory read errors are reported.

cecb dir: any error but a bad checksum ends the listing, where only the end
of the tape did. The flag column shows the flag byte, and names are
escaped. In libcecb, a 16, 24 or 32-bit WAV shorter than its header says
now ends where it is cut instead of hanging, and a block read stops at its
first error.

dgndos dir already stopped on looped chains; it gains a regression test.

unittest/commandrun.h runs a command with a time limit, so a hang or crash
fails a test instead of stopping the suite. Against the old code the new
decb and os9 tests time out or crash, and cecb dir hangs on every cut
16, 24 and 32-bit WAV tried.

tlindner and others added 2 commits November 9, 2026 09:39
decb dir: a FAT chain that loops back on itself hung the listing. The new
_decb_gs_chain() stops after 256 links with EOS_WT; dir shows "?" for that
file and lists the rest, and _decb_gs_size uses it too. Over-long paths are
refused instead of overflowing a buffer, a disk name that fills its sector
is printed without reading past it, unprintable characters are escaped, an
unreadable directory sector no longer hides the entries after it, and the
image is closed.

os9 dir: paths are bounded, and an empty one is refused instead of being
read before its start. A 29-byte name without an ending is copied with a
limit. With -r every directory is listed once per argument: one reached
through several entries was listed again for each way to it, which grew
exponentially. Directory read errors are reported.

cecb dir: any error but a bad checksum ends the listing, where only the end
of the tape did. The flag column shows the flag byte, and names are
escaped. In libcecb, a 16, 24 or 32-bit WAV shorter than its header says
now ends where it is cut instead of hanging, and a block read stops at its
first error.

dgndos dir already stopped on looped chains; it gains a regression test.

unittest/commandrun.h runs a command with a time limit, so a hang or crash
fails a test instead of stopping the suite. Against the old code the new
decb and os9 tests time out or crash, and cecb dir hangs on every cut
16, 24 and 32-bit WAV tried.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GCC on Linux couldn't tell that a pathlist from the 20-level array fits the
512-byte command, and -Werror failed the build. Every length in the loop is
now checked, which also fails the test if one is cut off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@DrPitre
DrPitre merged commit 8b8d608 into nitros9project:main Nov 9, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants