Page MenuHomeFreeBSD

ls: check fts_children() for errors that may not surface otherwise
ClosedPublic

Authored by kevans on Jun 26 2025, 5:59 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Feb 15, 3:01 AM
Unknown Object (File)
Sun, Feb 15, 12:00 AM
Unknown Object (File)
Jan 26 2026, 5:44 PM
Unknown Object (File)
Jan 26 2026, 3:11 PM
Unknown Object (File)
Jan 25 2026, 10:20 AM
Unknown Object (File)
Jan 21 2026, 1:05 AM
Unknown Object (File)
Dec 30 2025, 1:08 PM
Unknown Object (File)
Dec 27 2025, 4:52 AM
Subscribers

Details

Summary

In particular, if one simply does a non-recursive ls on a directory
that is not accessible, there are some classes of errors that may cause
it to fail that wouldn't be surfaced unless we do an fts_read() that
will recurse into the inaccessible directory. Catch those kinds of
errors here since we cannot expect to an FTS_ERR/FTS_DNR entry to follow
up on them.

PR: 287451

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Jun 26 2025, 9:21 PM
bin/ls/ls.c
710

The errno check is redundant, chp == NULL && errno == 0 can only happen if a) ftsp is not of type FTS_D or b) FTS_STOP is set on ftsp. Neither is possible here.

bin/ls/tests/ls_tests.sh
505

why not simply use -o match and -e match here?

bin/ls/ls.c
710

The manpage claims it returns NULL and errno will be set to 0 if the directory is empty. I don't see how that is falls within your two cases, because an empty directory would otherwise get an FTS_D + FTD_DP pair just like a non-empty.

bin/ls/ls.c
710

Ah, I failed to consider that the directory might be empty.

kevans added inline comments.
bin/ls/tests/ls_tests.sh
505

Incorporated along with other discussed improvements

This revision was automatically updated to reflect the committed changes.
kevans marked an inline comment as done.