libbsd: Branch 'main' - 13 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Jan 7 15:50:00 UTC 2024


 .gitlab-ci.yml        |    1 
 configure.ac          |   67 +-------------------------------------------------
 include/bsd/stdlib.h  |    2 -
 m4/libbsd-compiler.m4 |   50 ++++++++++++++++++++++++++++++++++++-
 m4/libbsd-linker.m4   |   27 ++++++++++++++++++++
 man/libbsd.7          |   24 ++++++++---------
 man/strtoi.3bsd       |    2 -
 man/strtonum.3bsd     |    8 ++---
 man/strtou.3bsd       |    2 -
 src/Makefile.am       |    7 ++++-
 src/fgetln.c          |    3 +-
 src/merge.c           |    3 --
 src/pwcache.c         |    4 ++
 src/setproctitle.c    |    2 -
 test/pwcache.c        |    4 ++
 15 files changed, 115 insertions(+), 91 deletions(-)

New commits:
commit ecb44e165514885648240c1b139c4ab0c212a0fa
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Nov 14 19:15:11 2023 +0100

    Do not add a pointer to the NULL constant
    
    Warned-by: cppcheck (nullPointerArithmetic)

diff --git a/src/merge.c b/src/merge.c
index c43866f..3f1b3fb 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -84,9 +84,8 @@ static void insertionsort(unsigned char *, size_t, size_t,
  */
 /* Assumption: PSIZE is a power of 2. */
 #define EVAL(p) (unsigned char **)					\
-	((unsigned char *)0 +						\
 	 (((unsigned char *)p + PSIZE - 1 -				\
-	   (unsigned char *)0) & ~(PSIZE - 1)))
+	   (unsigned char *)0) & ~(PSIZE - 1))
 
 /*
  * Arguments are as for qsort.
commit 459b7f7d24069674a63913d03e35586b484dbb95
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Nov 14 19:09:25 2023 +0100

    Do not confuse code analyzers with out-of-bounds array access look alike
    
    The code is only getting the address, but we might be performing an
    addressing that is out-of-bounds. Avoid it and use the address form
    instead.
    
    Warned-by: cppcheck (objectIndex)

diff --git a/src/setproctitle.c b/src/setproctitle.c
index 3aff064..d77d67f 100644
--- a/src/setproctitle.c
+++ b/src/setproctitle.c
@@ -284,7 +284,7 @@ setproctitle_impl(const char *fmt, ...)
 
 	if (nul < SPT.nul) {
 		*SPT.nul = '.';
-	} else if (nul == SPT.nul && &nul[1] < SPT.end) {
+	} else if (nul == SPT.nul && (nul + 1) < SPT.end) {
 		*SPT.nul = ' ';
 		*++nul = '\0';
 	}
commit a44f885cd476faee2154cbae1a1dc47bdeaea727
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Nov 14 19:08:15 2023 +0100

    test: Fix short-lived memory leak
    
    Warned-by: cppcheck

diff --git a/test/pwcache.c b/test/pwcache.c
index ac1e67b..458903f 100644
--- a/test/pwcache.c
+++ b/test/pwcache.c
@@ -50,8 +50,10 @@ main(int argc, char **argv)
 	assert(uname != NULL);
 
 	gr = getgrgid(0);
-	if (gr == NULL)
+	if (gr == NULL) {
+		free(uname);
 		return TEST_SKIP;
+	}
 	gname = strdup(gr->gr_name);
 	assert(gname != NULL);
 
commit 3f5ca0aae4ce26d0e2bb2a9f908ccdab84638574
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Oct 28 00:47:26 2023 +0200

    build: Add a coverage regex to the CI job
    
    This is needed so that gitlab can know where to extract the coverage
    percentage from in the output, to be able to track and report it.

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 9e117f2..737297c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -13,6 +13,7 @@
     - ./autogen && ./configure --disable-static
     - make check CFLAGS="--coverage -O0 -ggdb" LDFLAGS="--coverage -O0 -ggdb"
     - gcovr -s -e test/
+  coverage: /^TOTAL.*\s+(\d+\%)$/
 
 .debian:
   image: debian:latest
commit 9d3e59a01d612e311bdb96d16d436b4b7db9c691
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Oct 10 01:53:32 2023 +0200

    man: Use VARIANTS instead of ALTERNATIVES in libbsd(7)
    
    Using alternatives seems confusing in this context.

diff --git a/man/libbsd.7 b/man/libbsd.7
index 559eee4..d4a2d42 100644
--- a/man/libbsd.7
+++ b/man/libbsd.7
@@ -128,7 +128,7 @@ It only works in non-overlay mode.
 .Bl -tag -width 4m -compact
 .It In bsd/bsd.h
 .El
-.Sh ALTERNATIVES
+.Sh VARIANTS
 Some functions have different prototypes depending on the BSD where they
 originated from, and these various implementations provided are selectable
 at build-time.
commit f02562d64aeef86c607a5f876be7a71c5fa9f021
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Oct 10 01:52:37 2023 +0200

    man: Markup function references with Xr instead of Fn
    
    These references had man page sections in them, so using Fn meant that
    these appeared as function arguments.

diff --git a/man/libbsd.7 b/man/libbsd.7
index 676e130..559eee4 100644
--- a/man/libbsd.7
+++ b/man/libbsd.7
@@ -76,7 +76,7 @@ The package also provides a
 .Nm libbsd-ctor
 static library that can be used to inject automatic constructors into a
 program so that the
-.Fn setproctitle_init 3
+.Xr setproctitle_init 3
 function gets invoked automatically at startup time.
 This can be done with the
 .Xr pkgconf 1
@@ -140,9 +140,9 @@ This is the list of functions that provide multiple implementations:
 .It Fn strnunvis 3
 .Nx
 added
-.Fn strnvis 3
+.Xr strnvis 3
 and
-.Fn strnunvis 3
+.Xr strnunvis 3
 but unfortunately made it incompatible with the existing one in
 .Ox
 and Freedesktop's libbsd (the former having existed for over ten years).
@@ -184,7 +184,7 @@ An implementation has to choose between leaking buffers or being reentrant
 for a limited amount of streams (this implementation chose the latter with
 a limit of 32).
 Use
-.Fn getline 3
+.Xr getline 3
 instead, which is available in many systems and required by
 .St -p1003.1-2008 .
 .It Fn fgetwln 3
@@ -193,7 +193,7 @@ An implementation has to choose between leaking buffers or being reentrant
 for a limited amount of streams (this implementation chose the latter with
 a limit of 32).
 Use
-.Fn fgetwc 3
+.Xr fgetwc 3
 instead, which is available in many systems and required by
 .St -isoC-99
 and
@@ -201,7 +201,7 @@ and
 .It Fn funopen 3
 Unportable, requires assistance from the stdio layer or some hook framework.
 On GNU systems the
-.Fn fopencookie 3
+.Xr fopencookie 3
 function can be used.
 Otherwise the code needs to be prepared for neither of these functions being
 available.
@@ -240,16 +240,16 @@ This function is provided by
 2.26, and
 .Nm musl
 1.2.2.
-.It Fn arc4random 3
-.It Fn arc4random_buf 3
-.It Fn arc4random_uniform 3
+.It Xr arc4random 3
+.It Xr arc4random_buf 3
+.It Xr arc4random_uniform 3
 These functions are provided by
 .Nm glibc
 2.36.
 Note that it does not provide the
-.Fn arc4random_stir 3
+.Xr arc4random_stir 3
 and
-.Fn arc4random_addrandom 3
+.Xr arc4random_addrandom 3
 functions.
 .El
 .Sh SEE ALSO
diff --git a/man/strtoi.3bsd b/man/strtoi.3bsd
index 0e63da1..15102da 100644
--- a/man/strtoi.3bsd
+++ b/man/strtoi.3bsd
@@ -233,7 +233,7 @@ function first appeared in
 .Nx 7.0 .
 .Ox
 introduced the
-.Fn strtonum 3bsd
+.Xr strtonum 3bsd
 function for the same purpose, but the interface makes it impossible to
 properly differentiate illegal returns.
 .Sh BUGS
diff --git a/man/strtonum.3bsd b/man/strtonum.3bsd
index 1041782..a4ed2bb 100644
--- a/man/strtonum.3bsd
+++ b/man/strtonum.3bsd
@@ -154,9 +154,9 @@ function first appeared in
 was redesigned in
 .Nx 8.0
 as
-.Fn strtoi 3bsd
+.Xr strtoi 3bsd
 and
-.Fn strtou 3bsd .
+.Xr strtou 3bsd .
 .Sh CAVEATS
 The
 .Fn strtonum
@@ -186,6 +186,6 @@ To overcome the shortcomings of
 .Fn strtonum
 .Nx
 provides
-.Fn strtou 3bsd
+.Xr strtou 3bsd
 and
-.Fn strtoi 3bsd .
+.Xr strtoi 3bsd .
diff --git a/man/strtou.3bsd b/man/strtou.3bsd
index fe46bd1..d7e02eb 100644
--- a/man/strtou.3bsd
+++ b/man/strtou.3bsd
@@ -233,7 +233,7 @@ function first appeared in
 .Nx 7.0 .
 .Ox
 introduced the
-.Fn strtonum 3bsd
+.Xr strtonum 3bsd
 function for the same purpose, but the interface makes it impossible to
 properly differentiate illegal returns.
 .Sh BUGS
commit b7367c9ced9a0a69ce28bcaf319d50649a41a483
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Sep 5 03:02:44 2023 +0200

    build: Add missing dash to macro title bar

diff --git a/m4/libbsd-compiler.m4 b/m4/libbsd-compiler.m4
index dd8fbeb..135f38c 100644
--- a/m4/libbsd-compiler.m4
+++ b/m4/libbsd-compiler.m4
@@ -1,7 +1,7 @@
 # Copyright © 2021 Guillem Jover <guillem at hadrons.org>
 
 # LIBBSD_CHECK_COMPILER_FLAG
-# -------------------------
+# --------------------------
 AC_DEFUN([LIBBSD_CHECK_COMPILER_FLAG], [
   AS_VAR_PUSHDEF([libbsd_varname_cache], [libbsd_cv_cflags_$1])
   AC_CACHE_CHECK([whether $CC accepts $1], [libbsd_varname_cache], [
commit 6777eb62b8ee2b569454dc9b1d27e51a7dbf8764
Author: Guillem Jover <guillem at hadrons.org>
Date:   Thu Jul 27 13:57:51 2023 +0200

    pwcache: Do not declare uidtb and gidtb when not used
    
    When the system provides implementations for user_from_uid() or
    group_from_gid() we are not using these variables, so better not declare
    them.
    
    Fixes: commit 21d12b02112097f0c195dceb1892c95b7b957b36

diff --git a/src/pwcache.c b/src/pwcache.c
index 99609d9..8ed855c 100644
--- a/src/pwcache.c
+++ b/src/pwcache.c
@@ -83,8 +83,12 @@ typedef struct gidc {
  * cache both hits and misses.
  */
 
+#ifndef HAVE_USER_FROM_UID
 static UIDC **uidtb;	/* uid to name cache */
+#endif
+#ifndef HAVE_GROUP_FROM_GID
 static GIDC **gidtb;	/* gid to name cache */
+#endif
 static UIDC **usrtb;	/* user name to uid cache */
 static GIDC **grptb;	/* group name to gid cache */
 
commit d4e0cdc916476fb774b02a7da606e30e367f3f42
Author: Guillem Jover <guillem at hadrons.org>
Date:   Thu Jul 27 13:39:00 2023 +0200

    fgetln: Include <stdio.h> after <sys/*>
    
    The <sys/*> headers tend to define things that might be used by other
    headers, so while they should be self-contained, it is better to simply
    include them first.

diff --git a/src/fgetln.c b/src/fgetln.c
index b3b0a4b..3b62666 100644
--- a/src/fgetln.c
+++ b/src/fgetln.c
@@ -25,10 +25,11 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <stdio.h>
 #include <sys/cdefs.h>
 #include <sys/types.h>
+
 #include <string.h>
+#include <stdio.h>
 
 #include "local-link.h"
 
commit f41d6c12aacabc3dae5fdd45c50de6a967af8a88
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri May 26 23:55:40 2023 +0200

    build: Refactor GNU .init_array support check into a new m4 function

diff --git a/configure.ac b/configure.ac
index 40d25b9..8ff2bef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -184,49 +184,7 @@ AC_CHECK_DECLS([environ], [], [], [[
 #include <unistd.h>
 ]])
 
-AC_CACHE_CHECK([for GNU .init_array section support],
-  [libbsd_cv_gnu_init_array_support], [
-  AC_RUN_IFELSE([
-    AC_LANG_SOURCE([[
-static int rc = 1;
-static void init(int argc) { if (argc == 1) rc = 0; }
-void (*init_func)(int argc) __attribute__((__section__(".init_array"), __used__)) = init;
-int main() { return rc; }
-    ]])
-  ], [
-    libbsd_cv_gnu_init_array_support=yes
-  ], [
-    libbsd_cv_gnu_init_array_support=no
-  ], [
-    AC_PREPROC_IFELSE([
-      AC_LANG_SOURCE([[
-/* Look for a known libc that supports .init_array with the GNU extension
- * to pass main() arguments to the init functions. */
-#include <stdlib.h>
-#if defined __GLIBC_PREREQ
-#  if __GLIBC_PREREQ(2, 4)
-/* glibc supports GNU .init_array since 2.4. */
-#  else
-#    error glibc does not support GNU .init_array
-#  endif
-#else
-/*
- * Basic SysV ABI .init_array support, init functions do not get arguments:
- * - Bionic since its inception.
- * - uClibc since 0.9.29.
- */
-#  error unknown whether libc supports GNU .init_array
-#endif
-      ]])
-    ], [
-      libbsd_cv_gnu_init_array_support=yes
-    ], [
-      libbsd_cv_gnu_init_array_support=no
-    ])
-  ])
-])
-AM_CONDITIONAL([BUILD_LIBBSD_CTOR],
-  [test "$libbsd_cv_gnu_init_array_support" = yes])
+LIBBSD_HAS_GNU_INIT_ARRAY
 
 # Checks for library functions.
 AC_MSG_CHECKING([for program_invocation_short_name])
diff --git a/m4/libbsd-compiler.m4 b/m4/libbsd-compiler.m4
index b655b83..dd8fbeb 100644
--- a/m4/libbsd-compiler.m4
+++ b/m4/libbsd-compiler.m4
@@ -22,3 +22,51 @@ AC_DEFUN([LIBBSD_CHECK_COMPILER_FLAG], [
   ])
   AS_VAR_POPDEF([libbsd_varname_cache])
 ])
+
+# LIBBSD_HAS_GNU_INIT_ARRAY
+# -------------------------
+AC_DEFUN([LIBBSD_HAS_GNU_INIT_ARRAY], [
+  AC_CACHE_CHECK([for GNU .init_array section support],
+    [libbsd_cv_gnu_init_array_support], [
+    AC_RUN_IFELSE([
+      AC_LANG_SOURCE([[
+static int rc = 1;
+static void init(int argc) { if (argc == 1) rc = 0; }
+void (*init_func)(int argc) __attribute__((__section__(".init_array"), __used__)) = init;
+int main() { return rc; }
+      ]])
+    ], [
+      libbsd_cv_gnu_init_array_support=yes
+    ], [
+      libbsd_cv_gnu_init_array_support=no
+    ], [
+      AC_PREPROC_IFELSE([
+        AC_LANG_SOURCE([[
+/* Look for a known libc that supports .init_array with the GNU extension
+ * to pass main() arguments to the init functions. */
+#include <stdlib.h>
+#if defined __GLIBC_PREREQ
+#  if __GLIBC_PREREQ(2, 4)
+/* glibc supports GNU .init_array since 2.4. */
+#  else
+#    error glibc does not support GNU .init_array
+#  endif
+#else
+/*
+ * Basic SysV ABI .init_array support, init functions do not get arguments:
+ * - Bionic since its inception.
+ * - uClibc since 0.9.29.
+ */
+#  error unknown whether libc supports GNU .init_array
+#endif
+        ]])
+      ], [
+        libbsd_cv_gnu_init_array_support=yes
+      ], [
+        libbsd_cv_gnu_init_array_support=no
+      ])
+    ])
+  ])
+  AM_CONDITIONAL([BUILD_LIBBSD_CTOR],
+    [test "$libbsd_cv_gnu_init_array_support" = yes])
+])
commit 30b48ed9ea677e604bc47de421983410c3dcf714
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri May 26 23:50:10 2023 +0200

    build: Refactor linker script detection into a new m4 function

diff --git a/configure.ac b/configure.ac
index aabe28e..40d25b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,28 +32,7 @@ AC_SYS_LARGEFILE
 
 AM_PROG_AR
 LT_INIT
-
-AC_CACHE_CHECK([if ld supports --version-script flag],
-  [libbsd_cv_version_script], [
-  echo "{ global: symbol; local: *; };" >conftest.map
-  save_LDFLAGS=$LDFLAGS
-  LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
-  AC_LINK_IFELSE([
-    AC_LANG_PROGRAM([[
-extern int symbol(void);
-int symbol(void) { return 0; }
-]], [[
-]])
-  ], [
-    libbsd_cv_version_script=yes
-  ], [
-    libbsd_cv_version_script=no
-  ])
-  LDFLAGS="$save_LDFLAGS"
-  rm -f conftest.map
-])
-AM_CONDITIONAL([HAVE_LINKER_VERSION_SCRIPT],
-  [test "x$libbsd_cv_version_script" = "xyes"])
+LIBBSD_LINKER_VERSION_SCRIPT
 
 is_windows=no
 AS_CASE([$host_os],
diff --git a/m4/libbsd-linker.m4 b/m4/libbsd-linker.m4
new file mode 100644
index 0000000..394bac5
--- /dev/null
+++ b/m4/libbsd-linker.m4
@@ -0,0 +1,27 @@
+# Copyright © 2019, 2022 Guillem Jover <guillem at hadrons.org>
+
+# LIBBSD_LINKER_VERSION_SCRIPT
+# ----------------------------
+AC_DEFUN([LIBBSD_LINKER_VERSION_SCRIPT], [
+  AC_CACHE_CHECK([if ld supports --version-script flag],
+    [libbsd_cv_version_script], [
+    echo "{ global: symbol; local: *; };" >conftest.map
+    save_LDFLAGS=$LDFLAGS
+    LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
+    AC_LINK_IFELSE([
+      AC_LANG_PROGRAM([[
+extern int symbol(void);
+int symbol(void) { return 0; }
+]], [[
+]])
+    ], [
+      libbsd_cv_version_script=yes
+    ], [
+      libbsd_cv_version_script=no
+    ])
+    LDFLAGS="$save_LDFLAGS"
+    rm -f conftest.map
+  ])
+  AM_CONDITIONAL([HAVE_LINKER_VERSION_SCRIPT],
+    [test "x$libbsd_cv_version_script" = "xyes"])
+])
commit d0d8d0197f2d7bedaf02b5ef1ab0db20b61c9588
Author: Guillem Jover <guillem at hadrons.org>
Date:   Thu Jul 27 13:51:36 2023 +0200

    build: Do not provide prototypes for arc4random() on Solaris
    
    These functions are provided by the system.

diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index 51c58e8..e404bdb 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -51,7 +51,7 @@
 #include <stdint.h>
 
 __BEGIN_DECLS
-#if !defined(__APPLE__)
+#if !defined(__APPLE__) && !defined(__sun)
 #if !defined(__GLIBC__) || \
     !__GLIBC_PREREQ(2, 36) || \
     !defined(_DEFAULT_SOURCE)
commit cf61ebb8455aa96b69dde1d19b1d09b17c0bd1e7
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Apr 22 20:47:20 2023 +0200

    build: Do not build the progname module if it is not needed
    
    This was made conditional, but the code part was accidentally left
    untouched due to having ported it locally to use __progname, which
    caused build failures on the stock repo.
    
    Fixes: commit 046621d7967e7a0f08ae988bcf7e4cd1b6cf204c

diff --git a/src/Makefile.am b/src/Makefile.am
index 9d22b00..6f2325c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -95,7 +95,6 @@ libbsd_la_SOURCES = \
 	local-link.h \
 	merge.c \
 	pidfile.c \
-	progname.c \
 	pwcache.c \
 	radixsort.c \
 	readpassphrase.c \
@@ -114,6 +113,12 @@ libbsd_la_SOURCES = \
 	vis.c \
 	# EOL
 
+if NEED_PROGNAME
+libbsd_la_SOURCES += \
+	progname.c \
+	# EOL
+endif
+
 if NEED_BSD_GETOPT
 libbsd_la_SOURCES += \
 	bsd_getopt.c \


More information about the libbsd mailing list