Skip to content

pathchk: reject a 256-byte file name with -p, like GNU - #16312

Merged
sylvestre merged 3 commits into
uutils:mainfrom
sarankumar1325:pathchk-posix-path-max
Nov 28, 2026
Merged

sylvestre merged 3 commits into
uutils:mainfrom
sarankumar1325:pathchk-posix-path-max

Conversation

@sarankumar1325

Copy link
Copy Markdown
Contributor

pathchk -p accepted a 256-byte file name. _POSIX_PATH_MAX (256) counts the terminating null byte, so the longest portable name is 255 bytes, and GNU rejects 256. For longer names the error also said limit 256 and printed the name without quotes, unlike the default-mode message.

$ p=$(python3 -c "print(('abcdefgh/'*60)[:256])")
$ pathchk -p "$p"            # GNU 9.7
pathchk: limit 255 exceeded by length 256 of file name 'abcdefgh/…/abcd'
$ target/debug/pathchk -p "$p"   # main: exit 0, no output

The check is now >= POSIX_PATH_MAX, the reported limit is POSIX_PATH_MAX - 1 and the name is quoted, which matches GNU for 255, 256 and 257 byte names.

Test: test_posix_mode_path_max (255 bytes passes, 256 fails with the GNU message). It fails on main and passes with the fix; cargo fmt and cargo clippy -p uu_pathchk --all-targets -D warnings are clean.

I used an AI assistant to help find and write this change; I reviewed it and checked it against GNU pathchk.

Copilot AI balanced review requested due to automatic review settings November 9, 2026 18:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Comment thread src/uu/pathchk/src/pathchk.rs Outdated
// path length
if total_len > POSIX_PATH_MAX {
// path length: _POSIX_PATH_MAX counts the terminating null byte, so the
// longest portable file name is one byte shorter, as in GNU pathchk

This comment was marked as resolved.

Comment thread src/uu/pathchk/src/pathchk.rs Outdated
let total_len = joined_path.len();
// path length
if total_len > POSIX_PATH_MAX {
// path length: _POSIX_PATH_MAX counts the terminating null byte, so the

This comment was marked as resolved.

Comment thread tests/by-util/test_pathchk.rs Outdated

#[test]
#[cfg(unix)]
fn test_posix_mode_path_max() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might already have subset of this test which can be improved.

Copilot AI balanced review requested due to automatic review settings November 9, 2026 18:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Comment thread tests/by-util/test_pathchk.rs Outdated

// _POSIX_PATH_MAX (256) includes the terminating null byte, so 255 bytes
// is the longest portable file name
let path_of_len = |len: usize| {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this closure seems a bit complex for a test, something like format!("{}a", "a/".repeat(127)) would do, no?

Copilot AI balanced review requested due to automatic review settings November 9, 2026 19:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

_POSIX_PATH_MAX (256) counts the terminating null byte, so with -p the
longest portable file name is 255 bytes. A 256-byte name was accepted,
and a longer one was reported against limit 256 with the name unquoted.
Report limit 255 and quote the name, as GNU pathchk does.
@sylvestre
sylvestre force-pushed the pathchk-posix-path-max branch from a64003c to 2c8a795 Compare November 28, 2026 11:27
Copilot AI balanced review requested due to automatic review settings November 28, 2026 11:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@sylvestre
sylvestre merged commit 7b68df0 into uutils:main Nov 28, 2026
102 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

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.

4 participants