Paul Eggert [Wed, 2 Dec 2020 22:25:43 +0000 (14:25 -0800)]
canonicalize: refactor can_mode flag
* lib/canonicalize.c (MULTIPLE_BITS_SET): Remove, replacing with ...
(multiple_bits_set): ... this new static function. Uses changed.
(canonicalize_filename_mode): Refactor for clarity to avoid
modifying the CAN_MODE argument.
Paul Eggert [Wed, 2 Dec 2020 22:25:43 +0000 (14:25 -0800)]
canonicalize: prefer signed integer types
* lib/canonicalize.c: Include stddef.h, for ptrdiff_t.
(seen_triple, canonicalize_filename_mode): Prefer signed to
unsigned types where either will do, as they avoid some glitches
in comparisons and can trap on overflow when debugging.
Paul Eggert [Wed, 2 Dec 2020 22:25:42 +0000 (14:25 -0800)]
canonicalize: fix most of another EOVERFLOW issue
* lib/canonicalize.c (canonicalize_filename_mode):
Do not call stat if fewer than 20 symlinks have been traversed.
This avoids EOVERFLOW failure in the common case where there
are not that many symlinks, while continuing to catch loops
(or fail due to EOVERFLOW) in the unusual case when there
are many symlinks to traverse.
Paul Eggert [Wed, 2 Dec 2020 22:25:42 +0000 (14:25 -0800)]
canonicalize: do not assume symlinks have st_ino
* lib/canonicalize.c (canonicalize_filename_mode):
When checking for loops, use st_dev and st_ino from the parent
directory not from the symlink, as pre-2017 POSIX says these
members are not reliable for symlinks. Couple this with START
(the remaining file name to be resolved), not NAME (the whole file
name with START as its suffix).
* modules/canonicalize (Depends-on): Depend on stat, not lstat.
Paul Eggert [Wed, 2 Dec 2020 22:25:41 +0000 (14:25 -0800)]
canonicalize: fix EOVERFLOW bug
* lib/canonicalize.c (canonicalize_filename_mode):
When testing whether a directory entry is a symbolic link, or a
directory or other, do not use lstat or stat or
areadlink_with_size. Just use areadlink, as this suffices and it
avoids the EOVERFLOW problem that lstat and stat have.
* modules/canonicalize (Depends-on): Depend on areadlink instead
of areadlink-with-size and stat.
Paul Eggert [Wed, 2 Dec 2020 22:25:41 +0000 (14:25 -0800)]
canonicalize-lgpl: fix EOVERFLOW bug
* lib/canonicalize-lgpl.c: Do not include <sys/stat.h>.
(__realpath): Do not use lstat. Just use readlink, as this
suffices and it avoids the EOVERFLOW problem that lstat has.
* modules/canonicalize-lgpl (Depends-on): Remove lstat, sys_stat.
Bruno Haible [Tue, 1 Dec 2020 18:57:17 +0000 (19:57 +0100)]
vma-iter: Add support for macOS11/arm64.
Patch suggested by Hill Ma <maahiuzeon@gmail.com> in
<https://gitlab.com/gnu-clisp/clisp/-/issues/27>
and by Martin Storsjö <martin@martin.st> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00003.html>.
* lib/vma-iter.c (vma_iterate): On arm64, use 64-bit type definitions.
Akim Demaille [Sun, 29 Nov 2020 14:59:22 +0000 (15:59 +0100)]
bitset: style: use consistent names
* bitset/list.c (lbitset_list_reverse): Rename 'bcount' as 'bitcnt',
and 'boffset' as 'bitoff', for consistency with the other
implementations.
* bitset/table.c (tbitset_list_reverse): Likewise.
Bruno Haible [Sun, 29 Nov 2020 22:14:56 +0000 (23:14 +0100)]
spawn-pipe tests: Fix test failure with MSVC.
* tests/test-spawn-pipe-child.c: Include <stdint.h>.
(gl_msvc_invalid_parameter_handler): New function.
(main): Set a global invalid-parameter handler.
* modules/spawn-pipe-tests (Depends-on): Add msvc-inval, stdint.
Bruno Haible [Sun, 29 Nov 2020 20:13:33 +0000 (21:13 +0100)]
fcntl: Work around NetBSD bug with F_DUPFD_CLOEXEC.
* m4/fcntl.m4 (gl_FUNC_FCNTL): Test whether F_DUPFD_CLOEXEC actually
works.
* lib/fcntl.c (rpl_fcntl_DUPFD_CLOEXEC): On NetBSD, use the same
fallback implementation as on Haiku.
* tests/test-fcntl.c (main): Add a test whether F_DUPFD_CLOEXEC is
effective.
* doc/posix-functions/fcntl.texi: Mention the NetBSD bug.
Bruno Haible [Sun, 29 Nov 2020 17:37:33 +0000 (18:37 +0100)]
spawn-pipe: Fix build on OS/2 kLIBC (regression 2020-11-28).
* lib/os2-spawn.h: New file, based on lib/windows-spawn.h.
* lib/os2-spawn.c: New file, based on lib/windows-spawn.c.
* lib/spawn-pipe.c: On OS/2 kLIBC, include "os2-spawn.h".
* lib/windows-spawn.c: Remove modifications for kLIBC.
* modules/spawn-pipe (Files): Add the new files.
(configure.ac): Arrange to compile os2-spawn.c on OS/2.
* lib/stdio.in.h (_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD,
_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM): New macros.
(_GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD): Renamed from
_GL_ATTRIBUTE_FORMAT_PRINTF. Use _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD.
(_GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM): Use
_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM.
* modules/vasnprintf (Depends-on): Add stdio.
* lib/vasnprintf.h: Include <stdio.h>.
(asnprintf, vasnprintf): Use the standard printf format attribute.
* modules/xvasprintf (Depends-on): Add stdio.
* lib/xvasprintf.h: Include <stdio.h>.
(xasprintf, xvasprintf): Use the standard printf format attribute.
* modules/xprintf (Depends-on): List stdio first.
* lib/xprintf.h (xprintf, xvprintf): Use a printf format attribute that
depends on GNULIB_VPRINTF_POSIX.
(xfprintf, xvfprintf): Use a printf format attribute that depends on
GNULIB_VFPRINTF_POSIX.
* modules/c-vasnprintf (Depends-on): Add stdio.
* lib/c-vasnprintf.h: Include <stdio.h>.
(c_vasnprintf): Use the standard printf format attribute.
* modules/c-vasprintf (Depends-on): Add stdio.
* lib/c-vasprintf.h: Include <stdio.h>.
(c_asprintf, c_vasprintf): Use the standard printf format attribute.
* modules/c-vsnprintf (Depends-on): Add stdio.
* lib/c-vsnprintf.h: Include <stdio.h>.
(c_vsnprintf): Use the standard printf format attribute.
* modules/c-snprintf (Depends-on): Add stdio.
* lib/c-snprintf.h: Include <stdio.h>.
(c_snprintf): Use the standard printf format attribute.
* modules/c-xvasprintf (Depends-on): Add stdio.
* lib/c-xvasprintf.h: Include <stdio.h>.
(c_xasprintf, c_xvasprintf): Use the standard printf format attribute.
* modules/error (Depends-on): Depend on stdio always.
* lib/error.h: Include <stdio.h>.
(_GL_ATTRIBUTE_SPEC_PRINTF): Remove macro.
(error, error_at_line): Use a printf format attribute that depends on
GNULIB_VFPRINTF_POSIX.
* lib/error.c (_GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD): Renamed from
_GL_ATTRIBUTE_FORMAT_PRINTF.
* modules/verror (Depends-on): Add stdio.
* lib/verror.h: Include <stdio.h>. Don't include "error.h".
(verror, verror_at_line): Use the standard printf format attribute.
* lib/verror.c: Include "error.h".
* modules/argp (Depends-on): Add stdio.
* lib/argp.h (argp_error, __argp_error, argp_failure, __argp_failure):
Use a printf format attribute that depends on GNULIB_VFPRINTF_POSIX.
* modules/libtextstyle-optional (Depends-on): Add stdio.
* lib/textstyle.in.h (ostream_printf, ostream_vprintf): Use the standard
printf format attribute.
* tests/test-nonblocking-misc.h (dbgfprintf): Use the standard printf
format attribute.
Pádraig Brady [Mon, 23 Nov 2020 15:14:50 +0000 (15:14 +0000)]
selinux-at, selinux-h: use const correct declarations
* lib/se-selinux.in.h: Use const for "set" functions,
to match current selinux, and support cleaner user code.
* lib/selinux-at.c: Likewise.
* lib/selinux-at.h: Likewise.
Paul Eggert [Mon, 23 Nov 2020 07:37:57 +0000 (23:37 -0800)]
canonicalize-lgpl: fix memory leak
* lib/canonicalize-lgpl.c (__realpath): Fix unlikely memory leak,
which could have occurred if BUF was so large that malloc was
called. Do this by allocating EXTRA_BUF and BUF at the same time;
this eliminates the need to free BUF separately.
Paul Eggert [Sun, 22 Nov 2020 03:04:10 +0000 (19:04 -0800)]
parse-datetime: fix printf format typo
* lib/parse-datetime.y (parse_datetime2): Fix format typo in
previous patch to this file. Problem reported by Chris Elvidge in
<https://bugs.gnu.org/44763#32>.
Paul Eggert [Sun, 22 Nov 2020 02:09:29 +0000 (18:09 -0800)]
nl_langinfo-tests: work around GCC bug 44511
* tests/test-nl_langinfo-mt.c: Ignore -Wreturn-type, to work
around a GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44511>.
Problem reported for GNU grep by Andreas Schwab
<https://bugs.gnu.org/44535>.
Paul Eggert [Sat, 21 Nov 2020 20:54:22 +0000 (12:54 -0800)]
selinux-h: add stubs for selabel_open etc.
Coreutils with --enable-gcc-warnings does not build on Ubuntu 20.10
because matchpathcon is deprecated in favor of selabel_open etc.,
so this patch adds stubs for these functions.
* lib/se-label.c, lib/se-label.in.h, m4/selinux-label-h.m4: New files.
* lib/se-selinux.in.h (struct selinux_opt): Add incomplete decl,
as it is needed for selabel_open and selinux/selinux.h declares
this type here.
* modules/selinux-h (Files): Add the new files.
(configure.ac): Add gl_HEADERS_SELINUX_LABEL_H.
(lib_SOURCES): Add se-label.in.h, se-label.c.
(BUILT_SOURCES): Add $(SELINUX_LABEL_H).
(selinux/label.h): New rule, mimicking selinux/context.h.
(MOSTLYCLEANFILES): Add selinux/label.h, selinux/label.h-t.
(Include): Add selinux/label.h.
Akim Demaille [Thu, 19 Nov 2020 05:42:58 +0000 (06:42 +0100)]
bitset: tests: exercise the stats too
* tests/test-bitset.c: Display the stats at the end of the test.
* lib/bitset/stats.c (bitset_log_histogram_print): When diplaying the
last bin, display "256-..." rather that "256-511", since the last bin
does count item greater than or equal to 256.
Akim Demaille [Wed, 18 Nov 2020 20:37:34 +0000 (21:37 +0100)]
bitset: tests: try harder to break it
bitset_list (used in bitset_first, bitset_next, bitset_count,
BITSET_FOR_EACH, etc.) uses a cache of size BITSET_LIST_SIZE (1024).
None of our tests current try bitsets bigger than this.
* tests/test-bitset.c (compare): Be ready to use bitsets larger than
BITSET_LIST_SIZE.
(main): Likewise.
While at it, also exercise super small bitsets.
Akim Demaille [Tue, 17 Nov 2020 06:29:05 +0000 (07:29 +0100)]
bitset: strengthen tests
* tests/test-bitset.c (compare): Also check count.
Deal only with random values, move the one-bit tests to...
(check_one_bit): this new function.
(check_attributes): Call it.
Akim Demaille [Tue, 17 Nov 2020 06:40:01 +0000 (07:40 +0100)]
bitset: rename internal details for consistency
The "table" implementation used to called "expandable" (see
https://lists.gnu.org/archive/html/bug-gnulib/2018-11/msg00096.html).
Clean up remaining traces of "expandable".
* lib/bitset/table.c: Rename all the EBITSET_ symbols as TBITSET_.
Bruno Haible [Wed, 18 Nov 2020 01:33:33 +0000 (02:33 +0100)]
Fix error when GNULIB_POSIXCHECK is enabled (regression 2019-06-04).
* lib/unistd.in.h (copy_file_range): Don't assume that copy_file_range
is always declared.
* m4/unistd_h.m4 (gl_UNISTD_H): Test whether copy_file_range is
declared.
Bruno Haible [Tue, 17 Nov 2020 22:24:12 +0000 (23:24 +0100)]
Fix link errors on AIX.
* modules/clean-temp (Link): Link with $(LIBTHREAD).
* modules/getumask (Link): Link with $(LIBTHREAD).
* modules/getumask-tests (Makefile.am): Link test-getumask with
$(LIBTHREAD).
* modules/supersede (Link): Link with $(LIBTHREAD).
* modules/supersede-tests (Makefile.am): Link test-supersede with
$(LIBTHREAD).
* modules/fatal-signal (Link): New section.
* modules/execute (Link): New section.
* modules/csharpexec (Link): Link with $(LIBTHREAD).
* modules/javaexec (Link): Link with $(LIBTHREAD).
* modules/spawn-pipe (Link): New section.
* modules/spawn-pipe-tests (Makefile.am): Link test-spawn-pipe-main with
$(LIBTHREAD).
* modules/csharpcomp (Link): Link with $(LIBTHREAD).
* modules/javacomp (Link): Link with $(LIBTHREAD).
* modules/javaversion (Link): Link with $(LIBTHREAD).
* modules/pipe-filter-gi (Link): New section.
* modules/pipe-filter-gi-tests (Makefile.am): Link test-pipe-filter-gi1,
test-pipe-filter-gi2-main with $(LIBTHREAD).
* modules/pipe-filter-ii (Link): New section.
* modules/pipe-filter-ii-tests (Makefile.am): Link test-pipe-filter-ii1,
test-pipe-filter-ii2-main with $(LIBTHREAD).
* modules/term-style-control (Link): New section.
* modules/term-style-control-tests (Makefile.am): Link
test-term-style-control-hello, test-term-style-control-yes with
$(LIBTHREAD).
* modules/wait-process (Link): New section.
* modules/nonblocking-pipe-tests (Makefile.am): Link
test-nonblocking-pipe-main with $(LIBTHREAD).
* modules/nonblocking-socket-tests (Makefile.am): Link
test-nonblocking-socket-main with $(LIBTHREAD).
Bruno Haible [Tue, 17 Nov 2020 01:51:29 +0000 (02:51 +0100)]
Fix link errors on platforms with libunistring.
* modules/c32isalnum (Link): New section.
* modules/c32isalnum-tests (Makefile.am): Link test-c32isalnum with
$(LIBUNISTRING).
* modules/c32isalpha (Link): New section.
* modules/c32isalpha-tests (Makefile.am): Link test-c32isalpha with
$(LIBUNISTRING).
* modules/c32isblank (Link): New section.
* modules/c32isblank-tests (Makefile.am): Link test-c32isblank with
$(LIBUNISTRING).
* modules/c32iscntrl (Link): New section.
* modules/c32iscntrl-tests (Makefile.am): Link test-c32iscntrl with
$(LIBUNISTRING).
* modules/c32isdigit (Link): New section.
* modules/c32isdigit-tests (Makefile.am): Link test-c32isdigit with
$(LIBUNISTRING).
* modules/c32isgraph (Link): New section.
* modules/c32isgraph-tests (Makefile.am): Link test-c32isgraph with
$(LIBUNISTRING).
* modules/c32islower (Link): New section.
* modules/c32islower-tests (Makefile.am): Link test-c32islower with
$(LIBUNISTRING).
* modules/c32isprint (Link): New section.
* modules/c32isprint-tests (Makefile.am): Link test-c32isprint with
$(LIBUNISTRING).
* modules/c32ispunct (Link): New section.
* modules/c32ispunct-tests (Makefile.am): Link test-c32ispunct with
$(LIBUNISTRING).
* modules/c32isspace (Link): New section.
* modules/c32isspace-tests (Makefile.am): Link test-c32isspace with
$(LIBUNISTRING).
* modules/c32isupper (Link): New section.
* modules/c32isupper-tests (Makefile.am): Link test-c32isupper with
$(LIBUNISTRING).
* modules/c32isxdigit (Link): New section.
* modules/c32isxdigit-tests (Makefile.am): Link test-c32isxdigit with
$(LIBUNISTRING).
* modules/unicodeio (Link): Mention $(LIBUNISTRING).
* modules/unicodeio-tests (Makefile.am): Link test-unicodeio with
$(LIBUNISTRING).
Bruno Haible [Tue, 17 Nov 2020 01:30:29 +0000 (02:30 +0100)]
Fix link errors on platforms with libintl (e.g. Solaris and AIX).
Reported by Tom G. Christensen <tgc@jupiterrise.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-11/msg00062.html>.
* modules/getumask-tests (Makefile.am): Link test-getumask with
$(LIBINTL).
* modules/stack-tests (Makefile.am): Link test-stack with $(LIBINTL).
* modules/supersede-tests (Makefile.am): Link test-supersede with
$(LIBINTL).
* modules/unicodeio-tests (Makefile.am): Link test-unicodeio with
$(LIBINTL).
Paul Eggert [Mon, 16 Nov 2020 03:54:33 +0000 (19:54 -0800)]
getumask-tests: port to Solaris 10 etc.
Problem reported by Tom Christensen in:
https://lists.gnu.org/r/bug-gnulib/2020-11/msg00062.html
* modules/getumask-tests (test_getumask_LDADD):
Add $(LIB_CLOCK_GETTIME).
Paul Eggert [Sat, 14 Nov 2020 18:27:50 +0000 (10:27 -0800)]
careadlinkat: warn better about GCC bug 93644
* lib/careadlinkat.c (readlink_stk): When --enable-gcc-warnings is
not in effect, use "#warning" to let builders know more clearly
about GCC bug 93644, because the bug triggers even if no -W option
is given to GCC.
Jim Meyering [Fri, 13 Nov 2020 15:34:28 +0000 (07:34 -0800)]
hard-locale-tests: avoid a -Wstrict-prototypes warning
* tests/locale.c (main): Placate gcc's -Wstrict-prototypes by
changing "main ()" to "main (void)". This was the only case that
triggered a warning when building grep with --enable-gcc-warnings.
Paul Eggert [Thu, 12 Nov 2020 03:20:42 +0000 (19:20 -0800)]
time_rz: simplify CVE-2017-7476 fix
* lib/time_rz.c: Do not include limits.h; I think it was included
under the mistaken impression that limits.h defines SIZE_MAX.
(SIZE_MAX): Remove.
(save_abbr): Put string length into a ptrdiff_t variable,
so that the size comparison works naturally. This
fixes CVE-2017-7476 in a cleaner way.
Paul Eggert [Thu, 12 Nov 2020 03:16:23 +0000 (19:16 -0800)]
parse-datetime: streamline overflow checking
When parse-datetime.y’s overflow code was written, INT_ADD_WRAPV
did not work for unsigned destinations, and since time_t might
be unsigned that meant it did not work for time_t destinations.
This limitation of INT_ADD_WRAPV has been fixed, so we can
now streamline parse-datetime.y a bit.
* lib/parse-datetime.y: Do not include limits.h, as LONG_MAX
has not been used for a while.
(yylex, parse_datetime2): Assume C99 declarations after statements.
(yyles): Use INT_SUBTRACT_WRAPV instead of an explicit comparison
to TYPE_MINIMUM.
(parse_datetime2): No need for time_overflow now that
INT_ADD_WRAPV works for unsigned results.
Paul Eggert [Thu, 12 Nov 2020 03:08:27 +0000 (19:08 -0800)]
parse-datetime-tests: port to Alpine Linux 3.12.1
* tests/test-parse-datetime.c: Include errno.h for errno,
and unistd.h for _SC_TZNAME_MAX and sysconf.
(main): In the outlandishly-long time zone abbreviation test,
do not exceed TZNAME_MAX as this has undefined behavior,
and on Alpine Linux 3.12.1 it makes the test fail.
Bruno Haible [Sat, 7 Nov 2020 20:07:04 +0000 (21:07 +0100)]
gnulib-tool: Fix link error with 'version-etc' (regression 2020-05-29).
Reported by Simon Josefsson in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-11/msg00032.html>.
* gnulib-tool (func_emit_tests_Makefile_am): Add libtests.a to
LDADD a third time, after the second occurrence of ../lib/libgnu.a.
* pygnulib/GLEmiter.py (tests_Makefile_am): Likewise.
Paul Eggert [Wed, 4 Nov 2020 22:51:38 +0000 (14:51 -0800)]
tests: port better to XLC 12.01
* tests/test-argmatch.c (CHECK): Do not use -1 as a subscript,
even in code that is not executed, as IBM XLC 12.01 complains "The
subscript -1 is less than zero."
* tests/test-stdint.c (verify_width): Pass an (unused) 3rd
argument to _GL_VERIFY, as ISO C requires. Otherwise, IBM XLC
12.01 complains "The invocation of macro _GL_VERIFY contains fewer
arguments than are required by the macro definition."