On 15/09/2025 05:04, Collin Funk wrote:
Hi,
I mentioned this a few times in passing on other lists, but forgot to
bring it up here.
POSIX.1-2024 added the following change to many programs, using 'touch'
as an example [1]:
Austin Group Defect 251 is applied, encouraging implementations to
disallow the creation of filenames containing any bytes that have
the encoded value of a <newline> character.
With the FUTURE DIRECTIONS having the following text:
If this utility is directed to create a new directory entry that
contains any bytes that have the encoded value of a <newline>
character, implementations are encouraged to treat this as an error.
A future version of this standard may require implementations to
treat this as an error.
The goal seems to have been to avoid bugs like this example [2]:
$ for file in `find . -type f`; do if ! test -f "$file"; \
then echo "$file"; fi; done
./file
2
Here is a safe way to write that:
$ find . -type f -print0 | while IFS= read -r -d '' file; \
do if ! test -f "$file"; then echo "$file"; fi; done
My personal opinion is that that we shouldn't restrict a user from
creating a file with a name that their operating system and file system
support.
If a future POSIX release requires us to throw an error if a file name
has newline, I would propose only enforcing it if POSIXLY_CORRECT is
set. Probably with a function in Gnulib so that diffutils, patch, etc.
can use it.
Thoughts?
Collin
[1] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/touch.html
[2] https://www.austingroupbugs.net/view.php?id=251
Hmm.
I think there is little point in restricting characters unless it's done
completely,
because if not then you have to deal with the issue anyway.
So if the restriction is done, it should be done at a low level,
perhaps as a kernel option or something. Perhaps even a translation layer
in the kernel/libc to support older existing files with problematic characters,
while disallowing new files with those chars.
Doing this higher up in user space would only be playing
whac-a-mole with the issue I think.
cheers,
Padraig