libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 45f0a3c4caf3f06e5801289b524f9e615b94ee87
parent ae4f7294f83ae13e01ce66552bed041abed89377
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun,  1 Nov 2026 19:03:32 +0100

ipc: use a portable POSIX name for the shared memory object

A shared memory name is not a file system path, and NetBSD enforces that:
it rejects any name with an embedded slash, so prefixing /tmp made every
shm_open() fail and all out-of-process extraction was dead there.

Fixes #11826.

Also, netBSD ships libgcc only as a static archive, which caused
libtool to silently fall back to static modules for exiv2 and pdf...

Diffstat:
Mconfigure.ac | 13+++++++++++++
Msrc/main/extractor_ipc_gnu.c | 19++++++++-----------
Msrc/main/extractor_logging.h | 10+++++++---
3 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -45,6 +45,19 @@ AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MAKE_SET AC_CANONICAL_HOST + +# NetBSD provides libgcc only as a static archive (/usr/lib/libgcc.a; the +# shared runtime is libgcc_s.so), yet the C++ compiler's libtool postdeps +# name plain -lgcc. With NetBSD's default deplibs_check_method of +# match_pattern, libtool then decides it cannot satisfy the inter-library +# dependencies of a -module and silently builds a *static* module instead. +# A static module cannot be dlopen()ed, so the C++ plugins (exiv2, pdf) +# would be built but never loadable, and their tests fail with every +# expected item missing. Nothing here has undefined symbols we need +# libtool to police, so tell it to accept the dependencies. +AS_CASE(["$host_os"], + [netbsd*],[: ${lt_cv_deplibs_check_method=pass_all}]) + LT_INIT # save LIBS, libtool does a AC_SEARCH_LIBS(dlopen, dl), but plugins # need not have -ldl added diff --git a/src/main/extractor_ipc_gnu.c b/src/main/extractor_ipc_gnu.c @@ -134,25 +134,22 @@ struct EXTRACTOR_SharedMemory * EXTRACTOR_IPC_shared_memory_create_ (size_t size) { struct EXTRACTOR_SharedMemory *shm; - const char *tpath; if (NULL == (shm = malloc (sizeof (struct EXTRACTOR_SharedMemory)))) { LOG_STRERROR ("malloc"); return NULL; } -#if SOMEBSD - /* this works on FreeBSD, not sure about others... */ - tpath = getenv ("TMPDIR"); - if (NULL == tpath) - tpath = "/tmp/"; -#else - tpath = "/"; /* Linux */ -#endif + /* POSIX only guarantees portability for a shared memory object name + that consists of an initial slash followed by one or more + characters, none of which is a slash. The name is not a file + system path: NetBSD keeps POSIX shared memory in a tmpfs of its + own on /var/shm and rejects any name with an embedded slash with + EINVAL, so prefixing a directory such as /tmp made every call to + shm_open() fail there. */ snprintf (shm->shm_name, MAX_SHM_NAME, - "%sLE-%u-%u", - tpath, + "/LE-%u-%u", getpid (), (unsigned int) random ()); if (-1 == (shm->shm_id = shm_open (shm->shm_name, diff --git a/src/main/extractor_logging.h b/src/main/extractor_logging.h @@ -25,6 +25,9 @@ #ifndef EXTRACTOR_LOGGING_H #define EXTRACTOR_LOGGING_H +/* for strerror() in the LOG_STRERROR* macros below */ +#include <string.h> + #define DEBUG 0 #if DEBUG @@ -65,7 +68,7 @@ EXTRACTOR_log_ (const char *file, int line, const char *format, ...); * @param syscall name of the syscall that failed */ #define LOG_STRERROR(syscall) LOG ("System call `%s' failed: %s\n", syscall, \ - STRERROR (errno)) + strerror (errno)) /** @@ -76,8 +79,9 @@ EXTRACTOR_log_ (const char *file, int line, const char *format, ...); * @param filename name of the file that was involved */ #define LOG_STRERROR_FILE(syscall,filename) LOG ( \ - "System call `%s' failed for file `%s': %s\n", syscall, filename, STRERROR ( \ - errno)) + "System call `%s' failed for file `%s': %s\n", syscall, filename, \ + strerror ( \ + errno)) /**