5 Commits

Author SHA1 Message Date
Paul Eggert
6f357cfa9f diff: fix some behavior on unreadable input
This fixes a bug I recently introduced.
* src/diff.c (compare_files): Set and use openerr to avoid
the need for a doomed second attempt at openat.
Don’t insist on openat succeeding before trying fstatat.
Unless openat fails with ENOENT, ENOTDIR, ELOOP, EOVERFLOW, ENAMETOOLONG
it’s possible for it to fail even when fstatat would succeed.
ENOTDIR also means the file does not exist.
However, do not worry about EBADF as that is no longer possible
now that diff uses xstdopen.  When checking whether a file should
be considered to be nonexistent, do not require the other file
desc to be UNOPENED or STDIN_FILENO; all that is needed is
for the other file to not have an ENOENT or ENOTDIR failure.
* src/diff.h (struct file_data): New member openerr.
(OPEN_FAILED): New constant.
* tests/new-file: Add a regression test to catch the bug
fixed by the above.

diff: fix recent -N regression
* src/diff.c (compare_files): Fix recent regression, by
looking at cmp.file[1 - f].err rather than cmp.file[1 - f].desc.
Also, do not bother checking for EBADF, as that’s no longer
possible now that diff uses xstdopen.
2023-08-06 00:30:03 -07:00
Paul Eggert
2c9d956aac diff: remove unportable ‘diff -N - f <&-’ feature
* NEWS: Mention this.
* bootstrap.conf (gnulib_modules): Add stdopen.
* doc/diffutils.texi (Comparing Directories):
Do not document behavior if stdin is closed.
* src/diff.c: Include stdopen.h.
(main): Call stdopen early.
(compare_files) [__hpux]: Remove recently-introduced
special case for HP-UX exec with stdin closed.
* tests/new-file: Remove tests of the removed feature.
2019-01-05 19:20:36 -08:00
Jim Meyering
20b31314c3 tests: new-file: closed-stdin: also ensure stdout was empty
* tests/new-file: Also require that "out" be empty.
2017-05-09 11:55:46 -07:00
Jim Meyering
a9cc55101c tests: use "returns_" rather than explicit comparison with "$?"
* tests/colors: Use "returns_ 1" rather than testing $? = 1
* tests/basic: Likewise.
* tests/binary: Likewise.
* tests/filename-quoting: Likewise.
* tests/function-line-vs-leading-space: Likewise.
* tests/ignore-matching-lines: Likewise.
* tests/label-vs-func: Likewise.
* tests/new-file: Likewise.
* tests/no-dereference: Likewise.
* tests/no-newline-at-eof: Likewise.
* tests/stdin: Likewise.
2016-11-08 18:28:04 -08:00
Paul Eggert
7f2f4bb365 diff: -N, --unidirectional-new-file now compare to "-" too
* NEWS: Document this.
* doc/diffutils.texi (Comparing Directories): Likewise.
Also, document that these options work at the top level.
* src/diff.c (compare_files): Treat EBADF like ENOENT, to handle
the case where "-" is closed.  Allow the other file to be
STDIN_FILENO, in case it's "-".
* tests/Makefile.am (TESTS): Add new-file.
* tests/new-file: New file.
2012-02-04 22:13:48 -08:00