From 40638f24728a0685cba32d0254cdec3602c976ad Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Mon, 24 Apr 2023 15:18:59 +0200 Subject: [PATCH] use AC_CHECK_DECLS to avoid implicit function definition AC_CHECK_FUNCS is not safe, since implicit function definitions is just a warning. On 64-bit glibc systems where reallocarray is not defined or hidden behind macros that are not set, it gets implicitly defined to return an integer, which is a big problem given that it should return a pointer, and leads to immediate segfaults. --- configure.ac | 2 +- libpkgconf/bsdstubs.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index eef9f27..c9468d6 100644 --- a/configure.ac +++ b/configure.ac @@ -22,7 +22,7 @@ AX_CHECK_COMPILE_FLAG([-std=gnu99], [CFLAGS="$CFLAGS -std=gnu99"], [ AX_CHECK_COMPILE_FLAG([-std=c99], [CFLAGS="$CFLAGS -std=c99"]) ]) AC_CONFIG_HEADERS([libpkgconf/config.h]) -AC_CHECK_FUNCS([strlcpy strlcat strndup reallocarray]) +AC_CHECK_DECLS([strlcpy, strlcat, strndup, reallocarray]) AC_CHECK_HEADERS([sys/stat.h]) AM_INIT_AUTOMAKE([foreign dist-xz subdir-objects]) AM_SILENT_RULES([yes]) diff --git a/libpkgconf/bsdstubs.c b/libpkgconf/bsdstubs.c index f02c6ca..803c537 100644 --- a/libpkgconf/bsdstubs.c +++ b/libpkgconf/bsdstubs.c @@ -25,7 +25,7 @@ #include #include -#ifndef HAVE_STRLCPY +#if !HAVE_DECL_STRLCPY /* * Copy src to string dst of size siz. At most siz-1 characters * will be copied. Always NUL terminates (unless siz == 0). @@ -58,7 +58,7 @@ strlcpy(char *dst, const char *src, size_t siz) } #endif -#ifndef HAVE_STRLCAT +#if !HAVE_DECL_STRLCAT /* * Appends src to string dst of size siz (unlike strncat, siz is the * full size of dst, not space left). At most siz-1 characters @@ -107,7 +107,7 @@ strlcat(char *dst, const char *src, size_t siz) * from the use of this software. */ -#ifndef HAVE_STRNDUP +#if !HAVE_DECL_STRNDUP /* * Creates a memory buffer and copies at most 'len' characters to it. * If 'len' is less than the length of the source string, truncation occured. @@ -139,7 +139,7 @@ pkgconf_strndup(const char *src, size_t len) return strndup(src, len); } -#ifndef HAVE_REALLOCARRAY +#if !HAVE_DECL_REALLOCARRAY void * reallocarray(void *ptr, size_t m, size_t n) {