Pádraig Brady [Sun, 10 Dec 2017 04:18:22 +0000 (20:18 -0800)]
tail: fix tailing non seekable files on certain systems
* src/tail.c (tail_bytes): On systems were blksize_t is unsigned
and the same size or wider than off_t (android for example),
our initialized (off_t) -1 would be promoted to unsigned before
comparison, and thus fail to follow the appropriate path.
* tests/tail-2/tail-c.sh: Add a test case.
* NEWS: Mention the fix.
This issue was introduced in commit v8.23-47-g2662702
Reported at https://github.com/termux/termux-app/issues/233
Pádraig Brady [Sun, 10 Dec 2017 03:05:32 +0000 (19:05 -0800)]
build: avoid build failure without sys/mtio.h
* m4/jm-macros.m4: Check for the header.
* src/dd.c: Avoid the workaround where the header
is not available (on non glibc systems).
* src/shred.c: Likewise.
Pádraig Brady [Sun, 3 Dec 2017 00:56:50 +0000 (16:56 -0800)]
doc: reorganize ls -k and --time-style help
* src/ls.c (usage): Clarify -k only applies to -s usage
and directory 'total' lines. Move the description
of TIME_STYLE out of the option section as it was awkward
to read and write there within 80 columns.
Pádraig Brady [Sun, 10 Dec 2017 02:26:56 +0000 (18:26 -0800)]
doc: clarify numeric setuid handling in chmod man page
* man/chmod.x: Update the information to state one can
clear the setuid and setgid bits for directories numerically
using an additional leading '0' or a leading '='.
That has been supported since v8.15-64-g8931cdb.
Fixes https://bugs.gnu.org/29390
Pádraig Brady [Sun, 10 Dec 2017 00:18:00 +0000 (16:18 -0800)]
doc: clarify that cp --force may recreate files
* doc/coreutils.texi (cp invocation): The language used
to describe recreating the file was a little confusing
as it mentioned opening a removed file.
Fixes https://bugs.gnu.org/29315
Kamil Dudka [Mon, 4 Dec 2017 16:06:38 +0000 (17:06 +0100)]
doc: fix default QUOTING_STYLE for %N format of stat(1)
* doc/coreutils.texi (stat invocation): The default value
of QUOTING_STYLE for the %N format of 'stat --printf' is
'shell-escape-always'.
Fixes https://bugs.gnu.org/29563
Reported by Christian Groessler at
https://bugzilla.redhat.com/1520399#c3
Bernhard Voelker [Tue, 28 Nov 2017 16:32:29 +0000 (17:32 +0100)]
all: use consistent diagnostics for unknown long options
Previously, e.g. cksum failed to output the offending unknown long
option:
$ cksum --unknown-opt
cksum: invalid option -- '-'
Try 'cksum --help' for more information.
i.e., it tried to diagnose '-' as short option.
Instead, it should diagnose the unknown long option:
$ cksum --unknown-opt
cksum: unrecognized option '--unknown-opt'
Try 'cksum --help' for more information.
Pádraig Brady [Wed, 29 Nov 2017 05:54:12 +0000 (21:54 -0800)]
test: fix issues with tests/cp/preserve-mode.sh
* tests/cp/preserve-mode.sh: This was the only use of awk,
which may not be available on the system resulting
in an ineffective test. Also the permissions bits for
directories were not being checked at all.
Bernhard Voelker [Mon, 27 Nov 2017 10:25:39 +0000 (11:25 +0100)]
timeout: also support short -v option
* src/timeout.c (main): Add short option character 'v' to getopt_long
call.
* tests/misc/timeout.sh: Run the test both for the long and the short
option.
Pádraig Brady [Mon, 16 Oct 2017 06:54:29 +0000 (23:54 -0700)]
dd: support iflag=direct with arbitrary sized files
* src/dd.c (iread): Handle read error with a non-aligned
file offset in the O_DIRECT case. This is not an issue
on XFS at least, but on EXT4 the final read will return
EINVAL rather than the expected 0 to indicate EOF.
* tests/dd/direct.sh: Test the iflag=direct case also.
* NEWS: Mention the improvement.
Pádraig Brady [Thu, 23 Nov 2017 22:30:59 +0000 (14:30 -0800)]
timeout: add --verbose to diagnose timeouts
This is useful as handling in shell is complicated
with the varying exit status in the --kill-after case.
* src/timeout.c (main): Handle '-v' and store
COMMAND for the diagnostic.
(cleanup): Diagnose the signal name before sending.
(usage): Document -v, --verbose.
* doc/coreutils.texi (timeout invocation): Likewise.
* tests/misc/timeout.sh: Add a test case.
* NEWS: Mention the new feature
Fixes https://bugs.gnu.org/21760
Pádraig Brady [Mon, 13 Nov 2017 07:06:08 +0000 (23:06 -0800)]
tail: seek to the end of block devices
* src/tail.c (tail_bytes): Try lseek(..., SEEK_END) when
we can't determine the file size.
* tests/tail-2/end-of-device.sh: Add a new root only test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the improvement.
Paul Eggert suggested using lseek() (rather than ioctl(BLKGETSIZE64)).
Fixes https://bugs.gnu.org/29259
Assaf Gordon [Thu, 9 Nov 2017 22:09:45 +0000 (15:09 -0700)]
doc: add github issue/pull-request templates
These templates instruct contributors not to use github, and instead
use the upstream GNU development resources. Discussed in
http://lists.gnu.org/archive/html/coreutils/2017-11/msg00007.html .
* .github/ISSUE_TEMPLATE.txt,
.github/PULL_REQUEST_TEMPLATE.txt: New files.
tests: avoid false failure with inaccessible mount points
* tests/ls/readdir-mountpoint-inode.sh: Skip the test
if any mount points are inaccessible by the current user.
Fixes https://bugs.gnu.org/29167
Reported at: https://bugs.gentoo.org/353164
Older versions of 'makeinfo' choke on a missing reference:
./doc/coreutils.texi:14177: `Realpath usage examples' has no Up field\
(perhaps incorrect sectioning?).
makeinfo: Removing output file `doc/coreutils.info' due to errors; \
use --force to preserve.
* doc/coreutils.texi (realpath invocation): Add a menu referencing
the usage examples - introduced in v8.27-91-g7449f0d.
Assaf Gordon [Wed, 11 Oct 2017 20:33:28 +0000 (22:33 +0200)]
stat: output default formats for --terse in usage
Suggested by L A Walsh in https://bugs.gnu.org/28763 .
* src/stat.c (fmt_terse_fs): Define format for --terse -f here.
(fmt_terse_regular): Define format for --terse here.
(fmt_terse_selinux): Likewise for when SELinux is enabled.
(default_format): Use the above constants.
(usage): Output the formats for the terse modes.
Pádraig Brady [Sun, 29 Oct 2017 22:29:05 +0000 (15:29 -0700)]
df: fix hang with fifo argument
* src/df.c (main): stat() before open(), and avoid
the optional open when given a fifo argument.
* tests/df/unreadable.sh: Add a test case.
* NEWS: Mention the fix.
Fixes https://bugs.gnu.org/29038
Jim Meyering [Sat, 28 Oct 2017 04:14:37 +0000 (21:14 -0700)]
build: ls.c: apply _GL_ATTRIBUTE_PURE to more functions
* src/ls.c (DEFINE_SORT_FUNCTIONS): Apply _GL_ATTRIBUTE_PURE
to each strcmp-derived function definition, since GCC8 with
-Wsuggest-attribute=pure now warns it is needed.
Vincent Lefevre [Thu, 26 Oct 2017 04:34:21 +0000 (21:34 -0700)]
doc: reference statfs(2) in the stat(1) man page
* man/stat.x (SEE ALSO): Mention statfs(2) in addition to stat(2).
Note statfs() is generally used rather than statvfs(),
so we'll defer that reference to the SEE ALSO section of statfs(2).
Fixes https://bugs.gnu.org/28989
Pádraig Brady [Wed, 25 Oct 2017 02:54:16 +0000 (19:54 -0700)]
tests: avoid false failure when O_DIRECT isn't supported
* tests/dd/nocache_eof.sh: Only run the O_DIRECT tests
when 512 byte alignment is supported. Otherwise with older
XFS on systems with > 1MiB pages, or on file systems not
supporting O_DIRECT, there would have been false failures.
* tests/dd/direct.sh: Clarify the skip message.
Pádraig Brady [Wed, 11 Oct 2017 06:29:08 +0000 (23:29 -0700)]
dd: fix nocache regions passed to posix_fadvise()
Previously with oflag=direct the call to invalidate_cache()
was not passed to the kernel, as it was less than a page size,
and a subsequent call was not made to invalidate the pending space.
Similarly with oflag=nocache the pending space at EOF was
not invalidated. Even though these amount to only a single page
in the page cache it can be significant. For example on
XFS before kernel patch v4.9-rc1-4-g0ee7a3f, O_DIRECT files
would have been read inefficiently if any pages were cached,
even if they were already synced to storage.
* src/dd.c (i_nocache_eof, o_nocache_eof): New bools used
to control when we want invalidate_cache(,0) to clear to EOF.
(cache_round): Use IO_BUFSIZE (currently 132KiB) to minimize
calls to the relatively expensive advise function, rather
than page_size. This also makes it clear that while the
kernel function operates on pages, this size is chosen for
performance reasons.
(invalidate_cache): Refactor to share more code between
input and output paths. Use i_nocache_eof and o_nocache_eof
rather than proxying off max_records. Ensure we
invalidate full pages when clearing to EOF as the kernel
will ignore any non complete pages. Fix the offset used
for the output path.
(dd_copy): Invalidate the cache of the input after the
offset is updated, for consistency and so we don't try to
invalidate before the start of the file. When we read
EOF on input, set flags so that we invalidate to EOF.
(main): Invalidate to EOF in more cases, by depending
on the i_nocache_eof and o_nocache_eof flags.
* doc/coreutils.texi (dd invocation): Clarify the alignment
and persisted caveats on the example applying "nocache"
to part of a file.
* tests/dd/nocache_eof.sh: A new test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the bug fix.
Issue reported by Eric Bergen.
Pádraig Brady [Tue, 24 Oct 2017 06:26:33 +0000 (23:26 -0700)]
maint: apply suggested cleanup to recent stty.c change
This should have been part of commit v8.28-17-gf926f7c
* src/stty.c (check_argument): Align line continuation chars,
and ensure the function macro is immune to usage with if/else.
Suggested by Jim Meyering and Paul Eggert.
Pádraig Brady [Mon, 16 Oct 2017 09:17:34 +0000 (02:17 -0700)]
stty: fix processing of options when -F is specified
This was a latent issue that became significant with
the addition of the -F option in FILEUTILS-3_16n-56-ge46a424
* src/stty.c (apply_settings): Refactor argument checking
to a function macro. Augment the argument check to ignore
NULLed out arguments (already processed -F).
* NEWS: Mention the fix.
* tests/misc/stty-invalid.sh: Add a test case.
Fixes https://bugs.gnu.org/28859
* src/timeout.c (block_cleanup_and_chld): Rename from block_cleanup
to indicate we also block SIGCHLD to avoid the race where SIGCHLD
fires between waitpid() polling and sigsuspend() waiting for a signal.
* NEWS: Mention the fix.
Pádraig Brady [Sun, 1 Oct 2017 00:08:02 +0000 (17:08 -0700)]
build: reinstate distribution of man pages
man pages change little between systems,
so falling back to distributed pages make sense
when cross compiling or lacking perl.
* man/local.mk: Add all man pages to EXTRA_DIST
so that they're distributed in the generated tarball.
Use the dummy-man page generator if cross compiling.
Set TZ to avoid a distcheck failure where man pages
used a diffent month than those rebuilt (with a .timestamp).
* man/dummy-man: Only fall back to generating a stub
if copying an existing man page fails.
* man/help2man: Sync portable TZ=UTC0 specification
from upstream help2man.
* NEWS: Mention the build-related change.
Fixes https://bugs.gnu.org/28574
tests: fix test hang on case insenitive file systems
* tests/split/filter.sh: Due to an invalid 'FILE = zero.in'
construct trying to initialize a FILE variable, it would
instead try to run the FILE command which is present on
macOS 10.13 with APFS.
We also remove a redundant duplicate test clause introduced
during a rebase, and simplify the piped timeout command,
to avoid requiring a subshell and associated quoting.
* THANKS.in: Add the reporter Jack Howarth.
Fixes https://bugs.gnu.org/28506
tests: avoid a false failure in expr test with UTF8
* tests/misc/expr.pl: Skip the quote varying tests in
the multi-byte locales as these tests aren't that interesting
in those locales. Also ERR_SUBST is already defined for
some tests so awkward to redefine to munge UTF8 quotes to ASCII.
Assaf Gordon [Fri, 15 Sep 2017 06:36:13 +0000 (00:36 -0600)]
expr: add detailed syntax error messages
Show offending argument instead of a generic 'syntax error' message.
Suggested by Bernhard Voelker in https://bugs.gnu.org/28461#13 .
* src/expr.c (syntax_error): Remove.
(required_more_args): New function.
(eval7, main): Replace syntax_error call with detailed die message.
* tests/misc/expr.pl: Add tests for new messages.
maint: fix new syntax check failures from copy restrictions
* doc/coreutils.texi: Remove doubled word.
* src/targetdir.c: Explicitly mark exported function.
* tests/local.mk: This is not a root only test.
* tests/mv/vulnerable-target.sh: Use returns_.
Introduced in v8.28-3-g44ccd1c
shred: reinstate --remove file name length obfuscation
This was unintentionally removed in v8.27-60-g2ae1460
* src/shred.c (wipename): Interate through all name lengths.
* tests/misc/shred-remove.sh: Add test cases.
* NEWS: Mention the bug fix.
Fixes https://bugs.gnu.org/28507
Paul Eggert [Tue, 19 Sep 2017 01:54:52 +0000 (18:54 -0700)]
copy: check for vulnerable target dirs
* NEWS, doc/coreutils.texi (Target directory): Document this.
* src/cp.c, src/install.c, src/ln.c, src/mv.c: Include targetdir.h.
(target_directory_operand): Use the new targetdir_operand_type
function to check for vulnerable target directories.
* src/cp.c (stat_target_operand): New function.
(target_directory_operand, do_copy): Use it.
* src/local.mk (noinst_HEADERS): Add src/targetdir.h.
(src_ginstall_SOURCES, src_cp_SOURCES, src_ln_SOURCES)
(src_mv_SOURCES): Add src/targetdir.c.
* src/targetdir.c, src/targetdir.h: New files.
* tests/mv/vulnerable-target.sh: New test.
* tests/local.mk (all_root_tests): Add it.
Bernhard Voelker [Wed, 13 Sep 2017 21:37:20 +0000 (23:37 +0200)]
ptx: avoid infloop due to zero-length matches with -S regex
* src/ptx.c (find_occurs_in_text): Die with an appropriate error
diagnostic when the given regular expression returns a match of
length 0.
* tests/misc/ptx.pl (S-infloop): Add a test.
* NEWS (Bug fixes): Mention the fix.
Fixes https://bugs.gnu.org/28417 which was detected using
Symbolic Execution techniques developed in the course of the
SYMBIOSYS research project at COMSYS, RWTH Aachen University.
tests: fix false failure in recent ls --hyperlink test
* tests/ls/hyperlink.sh: If the hostname or any part of
the absolute path would be changed due to URL encoding,
the test would fail. Therefore simplify to remove
these components of the URL from consideration.
Pádraig Brady [Thu, 31 Aug 2017 05:49:24 +0000 (22:49 -0700)]
tests: exclude the expensive gnulib fts-tests
* gnulib: The only change in this gnulib update
is the tagging of the fts-tests module as longrunning,
which gnulib-tool currently implicitly excludes.
This test was seen to take about 20s and 285MB.
Reported by Assaf Gordon on space restricted VMs.
Pádraig Brady [Thu, 31 Aug 2017 03:14:22 +0000 (20:14 -0700)]
tty: don't distinguish input errors
* src/tty.c (main): Don't distinguish ENOTTY from other errors,
because isatty() doesn't portably distinguish errors.
Solaris returns ENOENT for all input errors for example.
Musl also returns ENOENT, and ENODEV may be returned as disscussed at:
http://openwall.com/lists/musl/2017/04/06/6
* tests/misc/tty.sh: Adjust accordingly.
Pádraig Brady [Thu, 31 Aug 2017 00:16:23 +0000 (17:16 -0700)]
tests: skip tests upon failure to set SELinux context
On some setups the root:object_r:tmp_t context is invalid.
This does indicate a limitation in the test framework,
but for now we'll relax this to skipping the tests.
The tests still run on a Fedora 25 system for example.
* tests/cp/cp-a-selinux.sh: Upon chcon error, skip rather than ERROR.
* tests/install/install-Z-selinux.sh: Likewise.
* tests/misc/chcon.sh: Likewise.
* tests/misc/runcon-no-reorder.sh: Likewise.
* tests/misc/selinux.sh: Likewise.
* tests/mkdir/restorecon.sh: Likewise.
Pádraig Brady [Wed, 30 Aug 2017 07:55:34 +0000 (00:55 -0700)]
tty: fix exit code with EINVAL
* src/tty.c (main): All systems mention that isatty()
man return EINVAL as well as (the POSIX compliant) ENOTTY.
Also Centos 6 was seen to return EINVAL from ttyname().
* tests/misc/tty.sh: Fix a test issue where we assume
standard input is always a valid tty.
Reported by Assaf Gordon on OpenSolaris 5.10 and 5.11,
and Centos 6.5
Pádraig Brady [Wed, 30 Aug 2017 07:27:41 +0000 (00:27 -0700)]
runcon: revert "disable use of the TIOCSTI ioctl"
This reverts commit v8.27-97-g8cb06d4 because
the setsid() fallback was not implemented correctly
and disabling the ioctl was not a complete solution
to the security issue of the child being passed
the tty of the parent.
Given runcon is not really a sandbox command,
the advice is to use `runcon ... setsid ...`
to avoid this particular issue.
Pádraig Brady [Wed, 30 Aug 2017 06:42:54 +0000 (23:42 -0700)]
stat: fix determination of max name length on BSD systems
We only use one of statfs or statvfs for `stat -f`
and on the BSDs we use statfs which doesn't have the
f_namelen member. However on OpenBSD and later FreeBSD
systems statfs does provide f_namemax, so use that.
* NEWS: Mention the improvement for OpenBSD and FreeBSD.
* m4/stat-prog.m4: Check for f_namemax in the statfs struct.
* src/stat.c: Return '?' rather than '*' when we can't
determine the max length of the file system.
* tests/ln/sf-1.sh: This test was failing on all BSDs
due to '*' being returned for the max length which
caused the test to attempt to create 1Mi+1 names.
The test now uses a short name when we can't determine
the max name length to use.
Reported by Assaf Gordon on various BSD based systems.
Pádraig Brady [Mon, 28 Aug 2017 08:57:54 +0000 (01:57 -0700)]
runcon: disable use of the TIOCSTI ioctl
Similar to the issue with SELinux sandbox (CVE-2016-7545),
children of runcon can inject arbitrary input to the terminal
that would be run at the originating terminal privileges.
The new libseccomp dependency is widely available and used
on modern SELinux systems, but is not available by default
on older systems like RHEL6 etc.
* m4/jm-macros.m4: Check for libseccomp and
warn if unavailable on selinux supporting systems.
* src/local.mk: Link runcon with -lseccomp.
* src/runcon.c (disable_tty_inject): A new function to
disable use of the TIOCSTI using libseccomp, or with setsid()
where libseccomp is unavailable.
* tests/misc/runcon-no-inject.sh: A new test that uses
python to make the TIOCSTI call, and ensure that doesn't succeed.
* tests/local.mk: Reference the new test
* NEWS: Mention the fix.
Addresses http://bugs.gnu.org/24541
Pádraig Brady [Mon, 21 Aug 2017 10:53:36 +0000 (03:53 -0700)]
ls: support --hyperlink to output file:// URIs
Terminals such as iTerm2 and VTE based terminals
(as of version 0.49.1), support hyperlinks when
passed terminals codes as described at:
https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
* src/ls.c (gobble_file): Allocate an absolute file name to output.
(quote_name): Output the absolute name with the appropriate codes.
(file_escape): A new function to encode file names as per rfc8089.
(main): Handle the new option and call the file_escape_init() helper.
Disable --dired when --hyperlink is specified.
(print_dir): Get the absolute file name here too, so that the
directory name can be linkified.
* NEWS: Mention the new feature.
* tests/ls/hyperlink.sh: Add a new test.
* tests/local.mk: Reference the new test.
* doc/coreutils.texi (ls invocation): Describe --hyperlink.
Pádraig Brady [Tue, 29 Aug 2017 04:09:08 +0000 (21:09 -0700)]
doc: remove older ChangeLog items
This saves about 0.5MB uncompressed from the tarball.
* Makefile.am: Following on from v8.26-34-g2c64bc8
update the oldest documented version to 8.18 which
is now about 5 years old. Also remove older ChangeLogs
that were previously thought to be for changes not
in the git history, but are adequately recorded upon review.
* build-aux/ChangeLog-2007: Remove file.
* lib/ChangeLog-2007: Likewise.
* m4/ChangeLog-2007: Likewise.
Colin Watson [Sun, 27 Aug 2017 07:16:21 +0000 (08:16 +0100)]
env: add --chdir option
This is useful when chaining with other commands that run commands in a
different context, while avoiding using the shell to cd, and thus
having to consider shell quoting the chained command.
* NEWS (New features): Document the new option.
* doc/coreutils.texi (env invocation): Likewise.
* src/env.c (usage): Likewise.
(main): Implement the new option.
* tests/misc/env.sh: Test the new option.
Josef Cejka [Mon, 31 Jul 2017 23:50:34 +0000 (01:50 +0200)]
df: avoid stat() for dummy file systems with -l
When systemd is configured to automount a remote file system - see
'man systemd.automount(5)', then the mount point is initially
mounted by systemd with the file system type "autofs".
When the resource is used later on, then the wanted file system is
mounted over that mount point on demand.
'df -l' triggered systemd to mount the file system because it called
stat() on the mount point.
Instead of single-casing "autofs" targets, we can avoid stat()ing
all dummy file systems (which includes "autofs"), because those are
skipped later on in get_dev() anyway.
*src/df.c (filter_mount_list): Also skip dummy file systems unless
the -a option or a specific target are given.
* NEWS: Mention the fix.
Co-authored-by: Bernhard Voelker <mail@bernhard-voelker.de>
Fixes http://bugzilla.suse.com/show_bug.cgi?id=1043059
Assaf Gordon [Tue, 27 Jun 2017 23:53:58 +0000 (19:53 -0400)]
doc: fix realpath index entry
The 'readlink' node has '@findex realpath' in it. This results in
info doc/coreutils.info realpath
incorrectly jumping to the 'readlink' node (instead of the 'realpath'
node). Change it to @cindex instead.
* doc/coreutils.texi (readlink): Change '@findex realpath' to @cindex.
Assaf Gordon [Sat, 24 Jun 2017 23:47:26 +0000 (19:47 -0400)]
realpath: improve usage description for --relative-{to,base}
* src/realpath.c (usage): Explicitly say 'DIR' instead of 'FILE' for
--relative-{to,base} parameters, to avoid giving the impression
that regular files can be used as relative base.
* doc/coreutils.texi (realpath): Same.
Pádraig Brady [Thu, 24 Aug 2017 07:18:41 +0000 (00:18 -0700)]
ls: consistently quote symlink targets
* src/ls.c (gobble_file): Disable the optimization to avoid quoting
if the symlink target itself needs quoting. This was introduced
with the quoting alignment adjustments in v8.25-106-g01971c0
* tests/ls/symlink-quote.sh: Add a test.
* tests/local.mk: Reference the test.
* NEWS: Mention the fix.
Pádraig Brady [Tue, 22 Aug 2017 04:00:01 +0000 (21:00 -0700)]
tail: reinstate inotify use with FIFOs
commit v8.27-44-g18f6b22 was too aggressive in
only allowing inotify use with regular files. This will
support responsive processing of `tail -f fifo | ...`
* src/tail.c (any_non_regular): Adjust to allow FIFOs
since inotify supports these well.
* tests/tail-2/inotify-only-regular.sh: Adjust comment.
Pádraig Brady [Sat, 19 Aug 2017 22:36:54 +0000 (15:36 -0700)]
tests: fix issues on alpine linux
* tests/misc/seq-epipe.sh: Remove stale comment.
* tests/misc/sort-debug-warn.sh: musl doesn't indicate a set_locale()
failure with missing locales, so avoid a test portion in that case.
* tests/misc/wc-files0.sh: Avoid a bug on older ash implementations.
Addresses http://bugs.gnu.org/28054
Paul Eggert [Thu, 17 Aug 2017 19:02:16 +0000 (12:02 -0700)]
ptx: fix some integer overflow bugs
Problem reported by Lukas Zachar at:
http://bugzilla.redhat.com/1482445
* src/ptx.c (line_width, gap_size, maximum_word_length)
(reference_max_width, half_line_width, before_max_width)
(keyafter_max_width, truncation_string_length, compare_words)
(compare_occurs, search_table, find_occurs_in_text, print_spaces)
(fix_output_parameters, define_all_fields):
Use ptrdiff_t, not int, for object offsets and sizes.
(WORD, OCCURS): Use ptrdiff_t, not short int.
(WORD_TABLE, number_of_occurs, generate_all_output):
Prefer ptrdiff_t to size_t where either will do.
(total_line_count, file_line_count, OCCURS, fix_output_parameters)
(define_all_fields):
Use intmax_t, not int, for line counts.
(DELTA): Remove. All uses changed.
(OCCURS, find_occurs_in_text, fix_output_parameters):
Use int, not size_t, for file indexes.
(tail_truncation, before_truncation, keyafter_truncation)
(head_truncation, search_table, define_all_fields)
(generate_all_output):
Use bool for booleans.
(digest_word_file, find_occurs_in_text):
Use x2nrealloc instead of checking for overflow by hand.
(find_occurs_in_text, fix_output_parameters, define_all_fields):
Omit unnecessary cast.
(fix_output_parameters): Don’t assume integers fit in 11 digits.
(fix_output_parameters, define_all_fields):
Use sprintf return value rather than calling strlen.
(define_all_fields): Do not rely on sprintf to generate a string
that may contain more than INT_MAX bytes.
(main): Use xstrtoimax, not xstrtoul.
Use xnmalloc to catch integer overflow.
Paul Eggert [Thu, 17 Aug 2017 16:28:59 +0000 (09:28 -0700)]
sort: use pthread_sigmask, not sigprocmask
POSIX says sigprocmask has unspecified behavior in a multithreaded
program like ‘sort’.
* src/sort.c (pthread_sigmask) [GNULIB_defined_pthread_functions]:
New macro, for use when ‘sort’ is not multithreaded.
(cs_enter, cs_leave): Use it. Pass address, not value, as
this is typically a tad faster. All callers changed.
Paul Eggert [Thu, 17 Aug 2017 15:03:57 +0000 (08:03 -0700)]
sort: file descriptor discipline
Use O_CLOEXEC when creating file descriptors, so that subsidiary
processes do not inherit file descriptors that they do not need.
This is helpful for ‘sort’, as it is a multithreaded program that
forks and execs.
* bootstrap.conf (gnulib_modules): Add mkostemp, open, pipe2.
* src/sort.c (create_temp_file): Open temporary file with O_CLOEXEC.
(stream_open): Open the stream with O_CLOEXEC.
(pipe_fork): Create the pipe with O_CLOEXEC.
(check_output): Open the output file with O_CLOEXEC.
(main): Use xfopen/xfclose to handle --files0-from, so that
O_CLOEXEC is used properly. This is simpler anyway.
* tests/misc/sort-files0-from.pl: Adjust to change in diagnostic
wording.
* src/operand2sig.c (operand2sig): AIX uses a different bit pattern
in the returned status from the wait() functions and from shells.
Therefore hardcode the selection of the lower bits of the number.
* NEWS: Mention the fix.
Pádraig Brady [Fri, 4 Aug 2017 06:39:26 +0000 (23:39 -0700)]
build: use the appropriate single file include option with xlc
* configure.ac: Set USE_XLC_INCLUDE when __xlc__ is defined.
* src/local.mk: Use it to select the appropriate include option.
Reported by Michael Felt.
Pádraig Brady [Fri, 4 Aug 2017 04:20:08 +0000 (21:20 -0700)]
tests: avoid false failures on AIX
* tests/ln/sf-1.sh: Limit the symlink size to 1MiB
to avoid memory exhaustion seen on NFS on AIX, giving:
+ printf '%0*d' 4294967296 0
+ ./tests/ln/sf-1.sh: line 38: printf: warning: 0: Result too large
* tests/id/setgid.sh: Skip the test when the adjusted gid
would equal 4294967295, as that's reserved on AIX.
Reported by Michael Felt.
Pádraig Brady [Sun, 13 Aug 2017 07:45:32 +0000 (00:45 -0700)]
sort: handle musl locale differences in --debug reporting
* src/sort.c (main): Don't assume hard_LC_COLLATE implies
a successful setting of the locale as musl defaults to
UTF8 when failing to set the specified locale.
* tests/misc/sort-debug-warn.sh: Adjust for the now
separated locale debug info and map the musl specific
message back to the common case.
Addresses https://bugs.gnu.org/28054
Pádraig Brady [Sun, 13 Aug 2017 07:18:43 +0000 (00:18 -0700)]
seq: produce consistent error messages upon write error
* src/seq.c (io_error): Use the same error message as would
be generated at exit time when closing the stdout stream.
The inconsistency was added with commit v8.25-26-gc92585b.
This was noticed due to an inconsistency in the expected
error message generated by seq on musl libc.
Addresses https://bugs.gnu.org/28054
Pádraig Brady [Sun, 13 Aug 2017 06:53:33 +0000 (23:53 -0700)]
tests: fix false failure with large printf formats
* tests/misc/printf-surprise.sh: With musl libc the
large printf format does succeed, outputting data.
To avoid SIGPIPE being generated we ignore that signal
and then handle the subsequent EPIPE error.
Addresses https://bugs.gnu.org/28054
Jim Meyering [Sat, 12 Aug 2017 20:51:19 +0000 (13:51 -0700)]
build: adjust warning options to work with latest GCC
* configure.ac: Disable some new warnings to avoid false positives.
Building with warnings enabled and latest gcc would evoke build
failure without these changes. Disable the following in coreutils
proper: -Wformat-overflow=2 -Wformat-truncation=2, and
disable these for gnulib: -Wformat-truncation=2 -Wduplicated-branches
Pádraig Brady [Thu, 3 Aug 2017 03:20:22 +0000 (20:20 -0700)]
maint: avoid a syntax-check failure
* src/shred.c (wipename): As per the comment, the arguments
to error() are sufficiently quoted, so split the call over
multiple lines to avoid the syntax-check.