tr: Fix regression causing read error with sockets #8083
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request fixes a regression introduced in 3e4221a that causes
tr
to fail when used with ksh93 sockets (previous bug report: #7658).The test used for determining if a file descriptor tested with
fstat
points to a directory is traditionally done by using theS_IFMT
mask12, e.g.:In Rust, this translates to
m & libc::S_IFMT == libc::S_IFDIR
.is_stdin_directory()
useshas!(mode, S_IFDIR)
, which is not equivalent and causes non-directory sockets to be incorrectly recognized as directories. This causestr
to break when used with all sockets created withsocketpair
, including ksh93 pipes3. Below is an example Rust program demonstrating why the current check is bogus:Changes:
-
is_stdin_directory()
: Fix the regression introduced in 3e4221a by replacing the bogus check with one equivalent toS_ISDIR()
.- test_tr.rs: Add a regression test for this bug.
Fixes #7658
Footnotes
https://sourceware.org/git/?p=glibc.git;a=blob;f=io/sys/stat.h;h=4bea9e9a#l123 ↩
https://git.musl-libc.org/cgit/musl/tree/include/sys/stat.h?id=047a1639#n51 ↩
https://github.com/ksh93/ksh/blob/cc5e0692/src/cmd/ksh93/sh/io.c#L98-L102 ↩