libbsd: Branch 'main' - 18 commits
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Apr 17 02:19:45 UTC 2023
configure.ac | 83 +++++++++++++++++++++++++++++++++++++++--------
include/Makefile.am | 14 ++++++-
include/bsd/grp.h | 2 +
include/bsd/pwd.h | 2 +
include/bsd/stdlib.h | 2 +
include/bsd/string.h | 4 ++
man/Makefile.am | 59 ++++++++++++++++++++++++++-------
src/Makefile.am | 88 ++++++++++++++++++++++++++++++++++++++++----------
src/flopen.c | 29 +++++++++++++---
src/fpurge.c | 2 +
src/funopen.c | 2 -
src/local-link.h | 16 ++++++++-
src/pwcache.c | 8 ++++
src/readpassphrase.c | 9 +++++
src/setproctitle.c | 10 +++--
test/Makefile.am | 34 +++++++++++++++----
test/closefrom.c | 30 ++++++++++++++---
test/explicit_bzero.c | 2 -
test/fpurge.c | 31 +++++++++++------
test/overlay.c | 2 +
test/pwcache.c | 34 ++++++++++++++++---
21 files changed, 380 insertions(+), 83 deletions(-)
New commits:
commit 21d12b02112097f0c195dceb1892c95b7b957b36
Author: Guillem Jover <guillem at hadrons.org>
Date: Tue Apr 4 23:59:05 2023 +0200
build: On macOS do not build functions provided by the system
We have never built before on macOS, so we can exclude all the functions
that are currently provided in the system.
Closes: #1
Closes: !3
diff --git a/configure.ac b/configure.ac
index c2bd521..d6446a0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -148,9 +148,6 @@ AC_SEARCH_LIBS([SHA512Update], [md], [
])
LIBS="$saved_LIBS"
-AM_CONDITIONAL([NEED_TRANSPARENT_LIBMD],
- [test "x$need_transparent_libmd" = "xyes"])
-
AS_CASE([$host_os],
[*-gnu*], [
# In old glibc versions (< 2.17) clock_gettime() is in librt.
@@ -305,8 +302,19 @@ AC_CHECK_FUNCS([\
open_memstream \
pstat_getproc \
sysconf \
+ uid_from_user \
+ gid_from_group \
+ user_from_uid \
+ group_from_gid \
])
+need_arc4random=yes
+need_md5=yes
+need_nlist=yes
+need_strl=yes
+need_strmode=yes
+need_pwcache=yes
+need_fpurge=yes
need_funopen=yes
AS_CASE([$host_os],
[*-musl*], [
@@ -319,12 +327,31 @@ AS_CASE([$host_os],
need_funopen=yes
],
[darwin*], [
+ # On macOS these are provided by the system, and libbsd has never built
+ # there, so we can avoid providing these with no ABI breakage.
+ need_arc4random=no
+ need_transparent_libmd=no
+ need_md5=no
+ need_nlist=no
+ need_strl=no
+ need_strmode=no
+ need_pwcache=no
+ need_fpurge=no
# On macOS we do not have fopencookie(), and cannot implement it.
need_funopen=no
],
)
AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xyes"])
+
+AM_CONDITIONAL([NEED_ARC4RANDOM], [test "x$need_arc4random" = "xyes"])
+AM_CONDITIONAL([NEED_TRANSPARENT_LIBMD], [test "x$need_transparent_libmd" = "xyes"])
+AM_CONDITIONAL([NEED_MD5], [test "x$need_md5" = "xyes"])
+AM_CONDITIONAL([NEED_NLIST], [test "x$need_nlist" = "xyes"])
+AM_CONDITIONAL([NEED_STRL], [test "x$need_strl" = "xyes"])
+AM_CONDITIONAL([NEED_STRMODE], [test "x$need_strmode" = "xyes"])
+AM_CONDITIONAL([NEED_PWCACHE], [test "x$need_pwcache" = "xyes"])
+AM_CONDITIONAL([NEED_FPURGE], [test "x$need_fpurge" = "xyes"])
AM_CONDITIONAL([NEED_FUNOPEN], [test "x$need_funopen" = "xyes"])
AS_IF([test "x$need_funopen" = "xno" && \
test "x$ac_cv_func_funopen" != "xyes" && \
diff --git a/include/Makefile.am b/include/Makefile.am
index ca0d06f..31d86b4 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -17,8 +17,6 @@ nobase_include_HEADERS = \
bsd/grp.h \
bsd/inttypes.h \
bsd/libutil.h \
- bsd/md5.h \
- bsd/nlist.h \
bsd/pwd.h \
bsd/readpassphrase.h \
bsd/stdio.h \
@@ -30,3 +28,15 @@ nobase_include_HEADERS = \
bsd/vis.h \
bsd/wchar.h \
# EOL
+
+if NEED_MD5
+nobase_include_HEADERS += \
+ bsd/md5.h \
+ # EOL
+endif
+
+if NEED_NLIST
+nobase_include_HEADERS += \
+ bsd/nlist.h \
+ # EOL
+endif
diff --git a/include/bsd/grp.h b/include/bsd/grp.h
index b2705e5..acf3d25 100644
--- a/include/bsd/grp.h
+++ b/include/bsd/grp.h
@@ -44,8 +44,10 @@
__BEGIN_DECLS
int
gid_from_group(const char *, gid_t *);
+#ifndef __APPLE__
const char *
group_from_gid(gid_t, int);
+#endif
__END_DECLS
#endif
diff --git a/include/bsd/pwd.h b/include/bsd/pwd.h
index 798af4b..38214ae 100644
--- a/include/bsd/pwd.h
+++ b/include/bsd/pwd.h
@@ -44,8 +44,10 @@
__BEGIN_DECLS
int
uid_from_user(const char *, uid_t *);
+#ifndef __APPLE__
const char *
user_from_uid(uid_t, int);
+#endif
__END_DECLS
#endif
diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index 5732fd1..bba13af 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -51,6 +51,7 @@
#include <stdint.h>
__BEGIN_DECLS
+#if !defined(__APPLE__)
#if !defined(__GLIBC__) || \
!__GLIBC_PREREQ(2, 36) || \
!defined(_DEFAULT_SOURCE)
@@ -60,6 +61,7 @@ uint32_t arc4random_uniform(uint32_t upper_bound);
#endif
void arc4random_stir(void);
void arc4random_addrandom(unsigned char *dat, int datlen);
+#endif
int dehumanize_number(const char *str, int64_t *size);
diff --git a/include/bsd/string.h b/include/bsd/string.h
index 4f2b71c..1996697 100644
--- a/include/bsd/string.h
+++ b/include/bsd/string.h
@@ -41,10 +41,14 @@
#include <sys/types.h>
__BEGIN_DECLS
+#ifndef __APPLE__
size_t strlcpy(char *dst, const char *src, size_t siz);
size_t strlcat(char *dst, const char *src, size_t siz);
+#endif
char *strnstr(const char *str, const char *find, size_t str_len);
+#ifndef __APPLE__
void strmode(mode_t mode, char *str);
+#endif
#if !defined(__GLIBC__) || \
!__GLIBC_PREREQ(2, 25) || \
diff --git a/man/Makefile.am b/man/Makefile.am
index 6d1c86a..bc30c87 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -177,13 +177,10 @@ dist_man_MANS = \
freezero.3bsd \
fmtcheck.3bsd \
fparseln.3bsd \
- fpurge.3bsd \
getbsize.3bsd \
getmode.3bsd \
getpeereid.3bsd \
getprogname.3bsd \
- gid_from_group.3bsd \
- group_from_gid.3bsd \
heapsort.3bsd \
humanize_number.3bsd \
le16dec.3bsd \
@@ -193,15 +190,12 @@ dist_man_MANS = \
le64dec.3bsd \
le64enc.3bsd \
libbsd.7 \
- md5.3bsd \
mergesort.3bsd \
- nlist.3bsd \
pidfile.3bsd \
pidfile_close.3bsd \
pidfile_open.3bsd \
pidfile_remove.3bsd \
pidfile_write.3bsd \
- pwcache.3bsd \
queue.3bsd \
radixsort.3bsd \
readpassphrase.3bsd \
@@ -219,9 +213,6 @@ dist_man_MANS = \
sl_init.3bsd \
sradixsort.3bsd \
stringlist.3bsd \
- strlcat.3bsd \
- strlcpy.3bsd \
- strmode.3bsd \
strnstr.3bsd \
strnunvis.3bsd \
strnvis.3bsd \
@@ -244,14 +235,53 @@ dist_man_MANS = \
timespecsub.3bsd \
timeval.3bsd \
tree.3bsd \
- uid_from_user.3bsd \
unvis.3bsd \
- user_from_uid.3bsd \
vis.3bsd \
wcslcat.3bsd \
wcslcpy.3bsd \
# EOL
+if NEED_MD5
+dist_man_MANS += \
+ md5.3bsd \
+ # EOL
+endif
+
+if NEED_NLIST
+dist_man_MANS += \
+ nlist.3bsd \
+ # EOL
+endif
+
+if NEED_STRL
+dist_man_MANS += \
+ strlcat.3bsd \
+ strlcpy.3bsd \
+ # EOL
+endif
+
+if NEED_STRMODE
+dist_man_MANS += \
+ strmode.3bsd \
+ # EOL
+endif
+
+if NEED_PWCACHE
+dist_man_MANS += \
+ pwcache.3bsd \
+ uid_from_user.3bsd \
+ user_from_uid.3bsd \
+ gid_from_group.3bsd \
+ group_from_gid.3bsd \
+ # EOL
+endif
+
+if NEED_FPURGE
+dist_man_MANS += \
+ fpurge.3bsd \
+ # EOL
+endif
+
if NEED_FUNOPEN
dist_man_MANS += \
funopen.3bsd \
diff --git a/src/Makefile.am b/src/Makefile.am
index 4781bdb..c02561e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -75,14 +75,7 @@ EXTRA_libbsd_la_DEPENDENCIES += \
# EOL
endif
libbsd_la_SOURCES = \
- arc4random.c \
- arc4random.h \
- arc4random_linux.h \
- arc4random_uniform.c \
- arc4random_unix.h \
- arc4random_win.h \
bsd_getopt.c \
- chacha_private.h \
closefrom.c \
dehumanize_number.c \
err.c \
@@ -94,7 +87,6 @@ libbsd_la_SOURCES = \
flopen.c \
fmtcheck.c \
fparseln.c \
- fpurge.c \
getbsize.c \
getpeereid.c \
heapsort.c \
@@ -102,12 +94,9 @@ libbsd_la_SOURCES = \
inet_net_pton.c \
local-elf.h \
local-link.h \
- md5.c \
merge.c \
- nlist.c \
pidfile.c \
progname.c \
- pwcache.c \
radixsort.c \
readpassphrase.c \
reallocarray.c \
@@ -115,10 +104,7 @@ libbsd_la_SOURCES = \
recallocarray.c \
setmode.c \
setproctitle.c \
- strlcat.c \
- strlcpy.c \
stringlist.c \
- strmode.c \
strnstr.c \
strtoi.c \
strtonum.c \
@@ -130,11 +116,59 @@ libbsd_la_SOURCES = \
wcslcpy.c \
# EOL
+if NEED_ARC4RANDOM
if !HAVE_GETENTROPY
libbsd_la_SOURCES += \
getentropy.c \
# EOL
endif
+libbsd_la_SOURCES += \
+ arc4random.c \
+ arc4random.h \
+ arc4random_linux.h \
+ arc4random_uniform.c \
+ arc4random_unix.h \
+ arc4random_win.h \
+ chacha_private.h \
+ # EOL
+endif
+
+if NEED_MD5
+libbsd_la_SOURCES += \
+ md5.c \
+ # EOL
+endif
+
+if NEED_NLIST
+libbsd_la_SOURCES += \
+ nlist.c \
+ # EOL
+endif
+
+if NEED_STRL
+libbsd_la_SOURCES += \
+ strlcat.c \
+ strlcpy.c \
+ # EOL
+endif
+
+if NEED_STRMODE
+libbsd_la_SOURCES += \
+ strmode.c \
+ # EOL
+endif
+
+if NEED_PWCACHE
+libbsd_la_SOURCES += \
+ pwcache.c \
+ # EOL
+endif
+
+if NEED_FPURGE
+libbsd_la_SOURCES += \
+ fpurge.c \
+ # EOL
+endif
if NEED_FUNOPEN
libbsd_la_SOURCES += \
diff --git a/src/pwcache.c b/src/pwcache.c
index d54daa0..99609d9 100644
--- a/src/pwcache.c
+++ b/src/pwcache.c
@@ -103,6 +103,7 @@ st_hash(const char *name, size_t len, int tabsz)
return key % tabsz;
}
+#ifndef HAVE_USER_FROM_UID
/*
* uidtb_start
* creates an an empty uidtb
@@ -124,7 +125,9 @@ uidtb_start(void)
}
return 0;
}
+#endif
+#ifndef HAVE_GROUP_FROM_GID
/*
* gidtb_start
* creates an an empty gidtb
@@ -146,6 +149,7 @@ gidtb_start(void)
}
return 0;
}
+#endif
/*
* usrtb_start
@@ -191,6 +195,7 @@ grptb_start(void)
return 0;
}
+#ifndef HAVE_USER_FROM_UID
/*
* user_from_uid()
* caches the name (if any) for the uid. If noname clear, we always
@@ -251,7 +256,9 @@ user_from_uid(uid_t uid, int noname)
}
return ptr->name;
}
+#endif
+#ifndef HAVE_GROUP_FROM_GID
/*
* group_from_gid()
* caches the name (if any) for the gid. If noname clear, we always
@@ -312,6 +319,7 @@ group_from_gid(gid_t gid, int noname)
}
return ptr->name;
}
+#endif
/*
* uid_from_user()
diff --git a/test/Makefile.am b/test/Makefile.am
index 985e3e1..7d220f7 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -40,30 +40,46 @@ check_PROGRAMS = \
humanize \
fgetln \
fparseln \
- fpurge \
- md5 \
- nlist \
proctitle-init \
progname \
- pwcache \
setmode \
- strl \
- strmode \
strnstr \
strtonum \
vis \
vis-openbsd \
# EOL
+if NEED_NLIST
+check_PROGRAMS += nlist
+endif
+
+if NEED_STRL
+check_PROGRAMS += strl
+endif
+
+if NEED_STRMODE
+check_PROGRAMS += strmode
+endif
+
+if NEED_PWCACHE
+check_PROGRAMS += pwcache
+endif
+
+if NEED_FPURGE
+check_PROGRAMS += fpurge
+endif
+
if NEED_FUNOPEN
check_PROGRAMS += funopen
endif
+if NEED_ARC4RANDOM
if HAVE_LIBTESTU01
arc4random_LDADD = $(LDADD) $(TESTU01_LIBS)
check_PROGRAMS += arc4random
endif
+endif
if BUILD_LIBBSD_CTOR
proctitle_LDFLAGS = \
@@ -75,10 +91,14 @@ proctitle_LDFLAGS = \
check_PROGRAMS += proctitle
endif
+if NEED_MD5
+check_PROGRAMS += md5
+
if NEED_TRANSPARENT_LIBMD
# On the installed system this is handled via the ld script.
md5_LDADD = $(LDADD) $(MD5_LIBS)
endif
+endif
fgetln_SOURCES = test-stream.c test-stream.h fgetln.c
fgetln_CFLAGS = -Wno-deprecated-declarations
diff --git a/test/overlay.c b/test/overlay.c
index d82f14e..af83232 100644
--- a/test/overlay.c
+++ b/test/overlay.c
@@ -28,12 +28,14 @@
* other headers through magic macros, to check that the overlay is working
* properly. */
#include <errno.h>
+#ifndef __APPLE__
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#ifdef HAVE_GRP_H
#include <grp.h>
#endif
+#endif
#include <stdint.h>
/* Include libbsd overlayed headers that might get partially included. */
commit bc65806ce22a6f838c8788435aea298e1a499c75
Author: Guillem Jover <guillem at hadrons.org>
Date: Thu Apr 6 23:05:27 2023 +0200
build: Select whether to include funopen() in the build system
This makes sure we include it when expected, alongside the man pages,
and the test cases, and do not accidentally break the ABI if the system
starts providing such interface.
diff --git a/configure.ac b/configure.ac
index 44717c2..c2bd521 100644
--- a/configure.ac
+++ b/configure.ac
@@ -297,6 +297,7 @@ AC_CHECK_FUNCS([\
flock \
fopencookie \
__fpurge \
+ funopen \
getauxval \
getentropy \
getexecname \
@@ -305,8 +306,31 @@ AC_CHECK_FUNCS([\
pstat_getproc \
sysconf \
])
+
+need_funopen=yes
+AS_CASE([$host_os],
+ [*-musl*], [
+ # On musl >= 1.1.19, fopencookie() got implemented, and because we were
+ # checking for its presence to decide whether to build funopen(), it got
+ # included in builds even when previously it had not been included, which
+ # is partially an ABI issue, but given that disabling it now would be
+ # worse, we'll ignore this as this is only a problem with downgrades. And
+ # enable it explicitly
+ need_funopen=yes
+ ],
+ [darwin*], [
+ # On macOS we do not have fopencookie(), and cannot implement it.
+ need_funopen=no
+ ],
+)
+
AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xyes"])
-AM_CONDITIONAL([HAVE_FOPENCOOKIE], [test "x$ac_cv_func_fopencookie" = "xyes"])
+AM_CONDITIONAL([NEED_FUNOPEN], [test "x$need_funopen" = "xyes"])
+AS_IF([test "x$need_funopen" = "xno" && \
+ test "x$ac_cv_func_funopen" != "xyes" && \
+ test "x$ac_cv_func_fopencookie" = "xyes"], [
+ AC_MSG_WARN([[can implement funopen() now based on newly added fopencooke(), report upstream]])
+])
AC_SUBST([MD5_LIBS])
AC_SUBST([LIBBSD_LIBS])
diff --git a/man/Makefile.am b/man/Makefile.am
index 961d2f5..6d1c86a 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -178,7 +178,6 @@ dist_man_MANS = \
fmtcheck.3bsd \
fparseln.3bsd \
fpurge.3bsd \
- funopen.3bsd \
getbsize.3bsd \
getmode.3bsd \
getpeereid.3bsd \
@@ -252,3 +251,9 @@ dist_man_MANS = \
wcslcat.3bsd \
wcslcpy.3bsd \
# EOL
+
+if NEED_FUNOPEN
+dist_man_MANS += \
+ funopen.3bsd \
+ # EOL
+endif
diff --git a/src/Makefile.am b/src/Makefile.am
index bc1add6..4781bdb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -95,7 +95,6 @@ libbsd_la_SOURCES = \
fmtcheck.c \
fparseln.c \
fpurge.c \
- funopen.c \
getbsize.c \
getpeereid.c \
heapsort.c \
@@ -137,6 +136,12 @@ libbsd_la_SOURCES += \
# EOL
endif
+if NEED_FUNOPEN
+libbsd_la_SOURCES += \
+ funopen.c \
+ # EOL
+endif
+
if NEED_TRANSPARENT_LIBMD
CLEANFILES += \
format.ld \
diff --git a/src/funopen.c b/src/funopen.c
index 0513e38..fdcdcba 100644
--- a/src/funopen.c
+++ b/src/funopen.c
@@ -138,5 +138,5 @@ funopen(const void *cookie,
return fopencookie(cookiewrap, mode, funcswrap);
}
#else
-#warning "Function funopen() is not provided on this platform."
+#error "Function funopen() needs to be ported."
#endif
diff --git a/test/Makefile.am b/test/Makefile.am
index 458a4e9..985e3e1 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -55,7 +55,7 @@ check_PROGRAMS = \
vis-openbsd \
# EOL
-if HAVE_FOPENCOOKIE
+if NEED_FUNOPEN
check_PROGRAMS += funopen
endif
commit 8b7a4d9d3b444681e14cdb085c25d5217da82c8b
Author: Guillem Jover <guillem at hadrons.org>
Date: Fri Apr 7 23:43:55 2023 +0200
build: Move Windows OS detection to the OS features section
This was placed here to make use of the same AS_CASE, but it does not
really fit with the section. Move it to the more appropriate place, and
detangle the AS_CASE.
diff --git a/configure.ac b/configure.ac
index 068bd92..44717c2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,6 +55,14 @@ int symbol(void) { return 0; }
AM_CONDITIONAL([HAVE_LINKER_VERSION_SCRIPT],
[test "x$libbsd_cv_version_script" = "xyes"])
+is_windows=no
+AS_CASE([$host_os],
+ [mingw*], [
+ is_windows=yes
+ ],
+)
+AM_CONDITIONAL([OS_WINDOWS], [test "x$is_windows" = "xyes"])
+
# Checks for programs.
AC_CHECK_TOOL([OBJDUMP], [objdump])
AC_PROG_CC
@@ -143,7 +151,6 @@ LIBS="$saved_LIBS"
AM_CONDITIONAL([NEED_TRANSPARENT_LIBMD],
[test "x$need_transparent_libmd" = "xyes"])
-is_windows=no
AS_CASE([$host_os],
[*-gnu*], [
# In old glibc versions (< 2.17) clock_gettime() is in librt.
@@ -155,11 +162,7 @@ AS_CASE([$host_os],
])
LIBS="$saved_LIBS"
],
- [mingw*], [
- is_windows=yes
- ],
)
-AM_CONDITIONAL([OS_WINDOWS], [test "x$is_windows" = "xyes"])
# Checks for header files.
AC_CHECK_HEADERS([\
commit ccbfd1c2414d8351a22f3f890994404c50a4b8df
Author: Guillem Jover <guillem at hadrons.org>
Date: Fri Apr 7 23:40:22 2023 +0200
build: Remove __MUSL__ definition from configure
We stopped relying on this macro when we turned the funopen() cpp error
into a warning in commit e50896286cc5718898194edb73fa7262ad9a22db.
diff --git a/configure.ac b/configure.ac
index 7588a3b..068bd92 100644
--- a/configure.ac
+++ b/configure.ac
@@ -155,10 +155,6 @@ AS_CASE([$host_os],
])
LIBS="$saved_LIBS"
],
- [*-musl*], [
- # Upstream refuses to define this, we will do it ourselves then.
- AC_DEFINE([__MUSL__], [1], [Define to 1 if we are building for musl])
- ],
[mingw*], [
is_windows=yes
],
commit e0976d7e909382fa4924879f3bdfd9ee1b4549a3
Author: Guillem Jover <guillem at hadrons.org>
Date: Sun Apr 2 22:33:25 2023 +0200
build: Add a new libbsd_strong_alias() macro and switch users to it
We had several cases of code needing a strong alias, so we switch those
to use the new macro. This covers systems that support the alias
attribute and others such as macOS where we need to use assembler
directives to add the alias as the attribute is not supported.
diff --git a/src/local-link.h b/src/local-link.h
index 7e9053b..a05d5ed 100644
--- a/src/local-link.h
+++ b/src/local-link.h
@@ -37,6 +37,16 @@
#define libbsd_link_warning(symbol, msg)
#endif
+#if defined(__APPLE__)
+#define libbsd_strong_alias(alias, symbol) \
+ __asm__(".globl _" #alias); \
+ __asm__(".set _" #alias ", _" #symbol); \
+ extern __typeof(symbol) alias
+#elif !defined(_MSC_VER)
+#define libbsd_strong_alias(alias, symbol) \
+ extern __typeof__(symbol) alias __attribute__((__alias__(#symbol)))
+#endif
+
#ifdef __ELF__
# if __has_attribute(symver)
/* The symver attribute is supported since gcc 10.x. */
@@ -64,7 +74,7 @@
# endif
#else
#define libbsd_symver_default(alias, symbol, version) \
- extern __typeof__(symbol) alias __attribute__((__alias__(#symbol)))
+ libbsd_strong_alias(alias, symbol)
#define libbsd_symver_variant(alias, symbol, version)
diff --git a/src/setproctitle.c b/src/setproctitle.c
index 64ff92a..3aff064 100644
--- a/src/setproctitle.c
+++ b/src/setproctitle.c
@@ -295,10 +295,8 @@ libbsd_symver_default(setproctitle, setproctitle_impl, LIBBSD_0.5);
* in 0.5, make the implementation available in the old version as an alias
* for code linking against that version, and change the default to use the
* new version, so that new code depends on the implemented version. */
-#ifdef HAVE_TYPEOF
-extern __typeof__(setproctitle_impl)
-setproctitle_stub
- __attribute__((__alias__("setproctitle_impl")));
+#if defined(libbsd_strong_alias)
+libbsd_strong_alias(setproctitle_stub, setproctitle_impl);
#else
void
setproctitle_stub(const char *fmt, ...)
commit 49c7dd1ca487e71cfb3c324fe76562424213b4bc
Author: Guillem Jover <guillem at hadrons.org>
Date: Sun Apr 2 22:32:11 2023 +0200
build: Only emit link warnings for ELF objects
diff --git a/src/local-link.h b/src/local-link.h
index 6782d9a..7e9053b 100644
--- a/src/local-link.h
+++ b/src/local-link.h
@@ -29,9 +29,13 @@
#include <sys/cdefs.h>
+#ifdef __ELF__
#define libbsd_link_warning(symbol, msg) \
static const char libbsd_emit_link_warning_##symbol[] \
__attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg
+#else
+#define libbsd_link_warning(symbol, msg)
+#endif
#ifdef __ELF__
# if __has_attribute(symver)
commit 8622767a8abff67877d0989131e64254a9a505bf
Author: Guillem Jover <guillem at hadrons.org>
Date: Tue Apr 11 00:24:13 2023 +0200
build: Use an export symbols file if there is no version script support
We generate the symbol list from the version script to avoid repeating
ourselves and potentially getting the lists out-of-sync.
diff --git a/src/Makefile.am b/src/Makefile.am
index b892ab8..bc1add6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -66,6 +66,13 @@ if HAVE_LINKER_VERSION_SCRIPT
libbsd_la_LDFLAGS += \
-Wl,--version-script=$(srcdir)/libbsd.map \
# EOL
+else
+libbsd_la_LDFLAGS += \
+ -export-symbols libbsd.sym \
+ # EOL
+EXTRA_libbsd_la_DEPENDENCIES += \
+ libbsd.sym \
+ # EOL
endif
libbsd_la_SOURCES = \
arc4random.c \
@@ -136,10 +143,19 @@ CLEANFILES += \
# EOL
endif
+DISTCLEANFILES = \
+ libbsd.sym \
+ # EOL
+
libbsd_ctor_a_SOURCES = \
setproctitle_ctor.c \
# EOL
+# Generate a simple libtool symbol export list to be used as a fallback if
+# there is no version script support.
+libbsd.sym: libbsd.map
+ $(AM_V_GEN) $(SED) -ne 's/^[[:space:]]\{1,\}\([A-Za-z0-9_]\{1,\}\);/\1/p' libbsd.map > $@
+
if NEED_TRANSPARENT_LIBMD
TRANSPARENT_LIBMD_DEPENDS = format.ld
commit 8f61036467428e6c00c0aef1943cd4e4b485a90a
Author: Guillem Jover <guillem at hadrons.org>
Date: Tue Apr 11 03:03:54 2023 +0200
build: Add -no-undefined libtool flag
We have no need for undefined symbols, so we can let the shared
library build even on systems without support for undefined symbols.
diff --git a/src/Makefile.am b/src/Makefile.am
index 64a8918..b892ab8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -59,6 +59,7 @@ libbsd_la_LIBADD = \
$(LIBBSD_LIBS) \
# EOL
libbsd_la_LDFLAGS = \
+ -no-undefined \
-version-number $(LIBBSD_ABI) \
# EOL
if HAVE_LINKER_VERSION_SCRIPT
commit ae7942ba6d4f09f084456dabddff04377f39bec9
Author: Guillem Jover <guillem at hadrons.org>
Date: Tue Apr 11 03:02:30 2023 +0200
build: Do not override the default DEPENDENCIES for libbsd
Extend it instead via EXTRA_*_DEPENDENCIES, to make sure that we
preserve the builtin library dependencies generated from LIBADD.
diff --git a/src/Makefile.am b/src/Makefile.am
index 5f803bb..64a8918 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -50,7 +50,7 @@ pkgconfig_DATA += libbsd-ctor.pc
lib_LIBRARIES += libbsd-ctor.a
endif
-libbsd_la_DEPENDENCIES = \
+EXTRA_libbsd_la_DEPENDENCIES = \
$(libbsd_la_included_sources) \
libbsd.map \
# EOL
commit a5faf17090b031b49bb8105d77b7f8b9f1ad671d
Author: Guillem Jover <guillem at hadrons.org>
Date: Sat Apr 1 12:46:49 2023 +0200
Only use <stdio_ext.h> if present
diff --git a/configure.ac b/configure.ac
index 4a3c8b0..7588a3b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -173,6 +173,7 @@ AC_CHECK_HEADERS([\
dirent.h \
pwd.h \
grp.h \
+ stdio_ext.h \
])
# Checks for typedefs, structures, and compiler characteristics.
diff --git a/src/fpurge.c b/src/fpurge.c
index 350f364..4a20c51 100644
--- a/src/fpurge.c
+++ b/src/fpurge.c
@@ -26,7 +26,9 @@
#include <errno.h>
#include <stdio.h>
+#if HAVE_STDIO_EXT_H
#include <stdio_ext.h>
+#endif
#ifdef HAVE___FPURGE
int
commit 06e8a1b29bea85fb3daeb1e3c7393bc78a8dffdb
Author: Guillem Jover <guillem at hadrons.org>
Date: Sat Apr 1 12:45:04 2023 +0200
Define _NSIG if it is not defined by the system
At least on macOS this macro is not defined.
diff --git a/src/readpassphrase.c b/src/readpassphrase.c
index f9f6195..0082c82 100644
--- a/src/readpassphrase.c
+++ b/src/readpassphrase.c
@@ -36,6 +36,15 @@
#define TCSASOFT 0
#endif
+#ifndef _NSIG
+#if defined(NSIG)
+#define _NSIG NSIG
+#else
+/* The SIGRTMAX define might be set to a function such as sysconf(). */
+#define _NSIG (SIGRTMAX + 1)
+#endif
+#endif
+
static volatile sig_atomic_t signo[_NSIG];
static void handler(int);
commit 44824aca3cae1a3908f80216ff8e53f859d16dc4
Author: Guillem Jover <guillem at hadrons.org>
Date: Sat Apr 1 12:41:42 2023 +0200
Declare environ if the system does not do so
The environ variable is supposed to be defined by the code using it, but
on glibc-based systems it will get defined if we request it, by including
<unistd.h> and defining _GNU_SOURCE.
diff --git a/configure.ac b/configure.ac
index 17978b1..4a3c8b0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -194,6 +194,10 @@ AC_CHECK_DECL([F_CLOSEM], [
#include <fcntl.h>
]])
+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([
diff --git a/src/setproctitle.c b/src/setproctitle.c
index d3e1087..64ff92a 100644
--- a/src/setproctitle.c
+++ b/src/setproctitle.c
@@ -33,6 +33,10 @@
#include <string.h>
#include "local-link.h"
+#if !HAVE_DECL_ENVIRON
+extern char **environ;
+#endif
+
static struct {
/* Original value. */
const char *arg0;
commit 1fb6c3f4ce2ebd43312f182a77ee407408002cc8
Author: Guillem Jover <guillem at hadrons.org>
Date: Mon Apr 10 23:10:40 2023 +0200
Use lockf() when flock() is not available
On Solaris flock() is not available, and we should use instead lockf()
or fcntl().
diff --git a/configure.ac b/configure.ac
index 78a4c97..17978b1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -290,6 +290,7 @@ __register_atfork(NULL, NULL, NULL, __dso_handle);
AC_CHECK_FUNCS([\
clearenv \
dirfd \
+ flock \
fopencookie \
__fpurge \
getauxval \
diff --git a/src/flopen.c b/src/flopen.c
index ff20d07..679445f 100644
--- a/src/flopen.c
+++ b/src/flopen.c
@@ -38,6 +38,27 @@
#include <libutil.h>
+static int
+lock_file(int fd, int flags)
+{
+ int operation;
+
+#if HAVE_FLOCK
+ operation = LOCK_EX;
+ if (flags & O_NONBLOCK)
+ operation |= LOCK_NB;
+
+ return flock(fd, operation);
+#else
+ if (flags & O_NONBLOCK)
+ operation = F_TLOCK;
+ else
+ operation = F_LOCK;
+
+ return lockf(fd, operation, 0);
+#endif
+}
+
/*
* Reliably open and lock a file.
*
@@ -49,7 +70,7 @@
static int
vflopenat(int dirfd, const char *path, int flags, va_list ap)
{
- int fd, operation, serrno, trunc;
+ int fd, serrno, trunc;
struct stat sb, fsb;
mode_t mode;
@@ -62,10 +83,6 @@ vflopenat(int dirfd, const char *path, int flags, va_list ap)
mode = (mode_t)va_arg(ap, int); /* mode_t promoted to int */
}
- operation = LOCK_EX;
- if (flags & O_NONBLOCK)
- operation |= LOCK_NB;
-
trunc = (flags & O_TRUNC);
flags &= ~O_TRUNC;
@@ -73,7 +90,7 @@ vflopenat(int dirfd, const char *path, int flags, va_list ap)
if ((fd = openat(dirfd, path, flags, mode)) == -1)
/* non-existent or no access */
return (-1);
- if (flock(fd, operation) == -1) {
+ if (lock_file(fd, flags) == -1) {
/* unsupported or interrupted */
serrno = errno;
(void)close(fd);
commit fe16f3863ec9be8d571d9e53701c9af40f399e4d
Author: Guillem Jover <guillem at hadrons.org>
Date: Mon Apr 10 23:11:33 2023 +0200
test: Use open_memstream() only if available
On Solaris this function is not yet available.
diff --git a/configure.ac b/configure.ac
index 1b7d182..78a4c97 100644
--- a/configure.ac
+++ b/configure.ac
@@ -296,6 +296,7 @@ AC_CHECK_FUNCS([\
getentropy \
getexecname \
getline \
+ open_memstream \
pstat_getproc \
sysconf \
])
diff --git a/test/fpurge.c b/test/fpurge.c
index 62d55da..784f32e 100644
--- a/test/fpurge.c
+++ b/test/fpurge.c
@@ -29,23 +29,36 @@
#include <string.h>
static int
-test_memstream(FILE *fp, size_t bufsz)
+test_memstream(void)
{
+ int rc = 0;
+#if HAVE_OPEN_MEMSTREAM
+ FILE *fp;
+ char *buf = NULL;
+ size_t bufsz = 0;
+
+ fp = open_memstream(&buf, &bufsz);
+ if (fp == NULL)
+ return 1;
+
fputs("World", fp);
if (fpurge(fp) < 0)
- return 1;
+ rc = 1;
fflush(fp);
if (bufsz != 0)
- return 1;
- return 0;
+ rc = 1;
+
+ fclose(fp);
+ free(buf);
+#endif
+
+ return rc;
}
int
main(int argc, char *argv[])
{
FILE *fp;
- char *buf = NULL;
- size_t bufsz = 0;
int rc;
if (fpurge(NULL) == 0)
@@ -54,13 +67,9 @@ main(int argc, char *argv[])
fp = fopen("/dev/zero", "r");
if (fpurge(fp) < 0)
return 1;
-
fclose(fp);
- fp = open_memstream(&buf, &bufsz);
- rc = test_memstream(fp, bufsz);
- fclose(fp);
- free(buf);
+ rc = test_memstream();
return rc;
}
commit 7c652a94ea429576b4c10869a7474d40f202b9f3
Author: Guillem Jover <guillem at hadrons.org>
Date: Mon Apr 10 20:57:14 2023 +0200
test: Do not hardcode root:root user and group names
On some systems the root group is named wheel, and there is no root
group.
diff --git a/test/pwcache.c b/test/pwcache.c
index d68ea4c..ac1e67b 100644
--- a/test/pwcache.c
+++ b/test/pwcache.c
@@ -1,5 +1,5 @@
/*
- * Copyright © 2021 Guillem Jover <guillem at hadrons.org>
+ * Copyright © 2021, 2023 Guillem Jover <guillem at hadrons.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,24 +26,48 @@
#include <assert.h>
#include <string.h>
+#include <stdlib.h>
#include <pwd.h>
#include <grp.h>
+#define TEST_SKIP 77
+
int
main(int argc, char **argv)
{
+ struct group *gr;
+ struct passwd *pw;
+ char *uname;
+ char *gname;
uid_t uid;
gid_t gid;
- assert(uid_from_user("root", &uid) == 0);
+ /* Do not hardcode user or group names. */
+ pw = getpwuid(0);
+ if (pw == NULL)
+ return TEST_SKIP;
+ uname = strdup(pw->pw_name);
+ assert(uname != NULL);
+
+ gr = getgrgid(0);
+ if (gr == NULL)
+ return TEST_SKIP;
+ gname = strdup(gr->gr_name);
+ assert(gname != NULL);
+
+ /* Test the functions. */
+ assert(uid_from_user(uname, &uid) == 0);
assert(uid == 0);
- assert(strcmp(user_from_uid(0, 0), "root") == 0);
+ assert(strcmp(user_from_uid(0, 0), uname) == 0);
- assert(gid_from_group("root", &gid) == 0);
+ assert(gid_from_group(gname, &gid) == 0);
assert(gid == 0);
- assert(strcmp(group_from_gid(0, 0), "root") == 0);
+ assert(strcmp(group_from_gid(0, 0), gname) == 0);
+
+ free(uname);
+ free(gname);
return 0;
}
commit ed2eb31da97331234bb12d70c1c16cae707d7f97
Author: Guillem Jover <guillem at hadrons.org>
Date: Sat Apr 1 02:46:22 2023 +0200
test: Fix closefrom() test on macOS
On macOS we do not close the file descriptors, and instead mark them all
as close-on-exec. So checking whether they are not valid does not work.
diff --git a/test/closefrom.c b/test/closefrom.c
index aa8d3b2..474c69f 100644
--- a/test/closefrom.c
+++ b/test/closefrom.c
@@ -55,7 +55,19 @@ main(int argc, char *argv[])
closefrom(4);
for (i = 4; i < fd_max; i++) {
- assert(fcntl(i, F_GETFL) == -1 && errno == EBADF);
+ int rc;
+
+ errno = 0;
+ rc = fcntl(i, F_GETFD);
+#ifdef __APPLE__
+ /* On macOS we only set close-on-exec. */
+ if ((i & (i - 1)) == 0)
+ assert(rc == FD_CLOEXEC);
+ else
+ assert(rc == -1 && errno == EBADF);
+#else
+ assert(rc == -1 && errno == EBADF);
+#endif
}
assert(fcntl(fd, F_GETFL) == -1 && errno == EBADF);
commit 0f8bcdfd92dc6342564192d707f339855c6fbc5f
Author: Guillem Jover <guillem at hadrons.org>
Date: Sat Apr 1 02:48:47 2023 +0200
test: Fix closefrom() test to handle open file descriptor limits
If the system has configured a lower limit (either soft or hard) on the
number of open file descriptors, the test will fail. Make sure to check
whether we have exceeded that limit and adapt the max number of file
descriptors appropriately.
diff --git a/test/closefrom.c b/test/closefrom.c
index 160e6b1..aa8d3b2 100644
--- a/test/closefrom.c
+++ b/test/closefrom.c
@@ -35,18 +35,28 @@ main(int argc, char *argv[])
{
int i;
int fd;
+ int fd_max;
fd = open("/dev/null", O_RDONLY);
- for (i = 4; i < 1024; i *= 2)
- assert(dup2(fd, i) == i);
+ fd_max = 1024;
+ for (i = 4; i < fd_max; i *= 2) {
+ int fd_new = dup2(fd, i);
+
+ if (fd_new < 0 && (errno == EMFILE || errno == EBADF)) {
+ fd_max = i - 1;
+ break;
+ }
+ assert(fd_new == i);
+ }
if (fd < 4)
close(fd);
closefrom(4);
- for (i = 4; i < 1024; i++)
+ for (i = 4; i < fd_max; i++) {
assert(fcntl(i, F_GETFL) == -1 && errno == EBADF);
+ }
assert(fcntl(fd, F_GETFL) == -1 && errno == EBADF);
return 0;
commit 07192b31e3cd4e541bc76b45788cf5e5e8faff9f
Author: Guillem Jover <guillem at hadrons.org>
Date: Wed Apr 5 00:01:42 2023 +0200
test: Disable blank_stack_side_effects() on non-Hurd systems
This code was added to cope with Hurd specific behavior, but it is
causing flakiness on containers on some Linux systems. Only enable
it where it is currently needed to try to get stability back on CI
systems.
Closes: #14
diff --git a/test/explicit_bzero.c b/test/explicit_bzero.c
index 5ec7592..031aa42 100644
--- a/test/explicit_bzero.c
+++ b/test/explicit_bzero.c
@@ -138,7 +138,7 @@ populate_secret(char *buf, ssize_t len)
static void __attribute__((__noinline__))
blank_stack_side_effects(char *buf, size_t len)
{
-#ifndef __SANITIZE_ADDRESS__
+#if defined(__GNU__) && !defined(__SANITIZE_ADDRESS__)
char scratch[SECRETBYTES * 4];
/* If the read(3) in populate_secret() wrote into the stack, as it
More information about the libbsd
mailing list