ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
8d419f
From 3ed5b365c5134cb18da8aed397c7c4551af25715 Mon Sep 17 00:00:00 2001
8d419f
From: Daan De Meyer <daan.j.demeyer@gmail.com>
8d419f
Date: Tue, 1 Mar 2022 17:04:13 +0000
8d419f
Subject: [PATCH] shared: Add more dlopen() tests
8d419f
8d419f
Add dlopen_dw(), dlopen_elf() and dlopen_pcre2() to the dlopen test.
8d419f
To enable adding dlopen_pcre2(), we move pcre2-dlopen.h/c from
8d419f
src/journal to src/shared.
8d419f
8d419f
(cherry picked from commit ee48779e05831a0ec5e1ba5e7ed5fe92aaca1d9e)
8d419f
8d419f
Related: #2017035
8d419f
---
8d419f
 src/journal/meson.build                |  2 --
8d419f
 src/shared/elf-util.c                  |  4 ++--
8d419f
 src/shared/elf-util.h                  |  3 +++
8d419f
 src/shared/meson.build                 |  2 ++
8d419f
 src/{journal => shared}/pcre2-dlopen.c |  0
8d419f
 src/{journal => shared}/pcre2-dlopen.h |  0
8d419f
 src/test/test-dlopen-so.c              | 11 +++++++++++
8d419f
 7 files changed, 18 insertions(+), 4 deletions(-)
8d419f
 rename src/{journal => shared}/pcre2-dlopen.c (100%)
8d419f
 rename src/{journal => shared}/pcre2-dlopen.h (100%)
8d419f
8d419f
diff --git a/src/journal/meson.build b/src/journal/meson.build
8d419f
index eb66bfd584..270592f2ac 100644
8d419f
--- a/src/journal/meson.build
8d419f
+++ b/src/journal/meson.build
8d419f
@@ -49,8 +49,6 @@ systemd_cat_sources = files('cat.c')
8d419f
 
8d419f
 journalctl_sources = files('''
8d419f
         journalctl.c
8d419f
-        pcre2-dlopen.c
8d419f
-        pcre2-dlopen.h
8d419f
 '''.split())
8d419f
 
8d419f
 if install_sysconfdir_samples
8d419f
diff --git a/src/shared/elf-util.c b/src/shared/elf-util.c
8d419f
index 4d93e7eaba..6d9fcfbbf2 100644
8d419f
--- a/src/shared/elf-util.c
8d419f
+++ b/src/shared/elf-util.c
8d419f
@@ -80,7 +80,7 @@ unsigned int (*sym_elf_version)(unsigned int);
8d419f
 GElf_Phdr *(*sym_gelf_getphdr)(Elf *, int, GElf_Phdr *);
8d419f
 size_t (*sym_gelf_getnote)(Elf_Data *, size_t, GElf_Nhdr *, size_t *, size_t *);
8d419f
 
8d419f
-static int dlopen_dw(void) {
8d419f
+int dlopen_dw(void) {
8d419f
         int r;
8d419f
 
8d419f
         r = dlopen_many_sym_or_warn(
8d419f
@@ -123,7 +123,7 @@ static int dlopen_dw(void) {
8d419f
         return 1;
8d419f
 }
8d419f
 
8d419f
-static int dlopen_elf(void) {
8d419f
+int dlopen_elf(void) {
8d419f
         int r;
8d419f
 
8d419f
         r = dlopen_many_sym_or_warn(
8d419f
diff --git a/src/shared/elf-util.h b/src/shared/elf-util.h
8d419f
index cf3d9be128..b28e64cea6 100644
8d419f
--- a/src/shared/elf-util.h
8d419f
+++ b/src/shared/elf-util.h
8d419f
@@ -4,6 +4,9 @@
8d419f
 #include "json.h"
8d419f
 
8d419f
 #if HAVE_ELFUTILS
8d419f
+int dlopen_dw(void);
8d419f
+int dlopen_elf(void);
8d419f
+
8d419f
 /* Parse an ELF object in a forked process, so that errors while iterating over
8d419f
  * untrusted and potentially malicious data do not propagate to the main caller's process.
8d419f
  * If fork_disable_dump, the child process will not dump core if it crashes. */
8d419f
diff --git a/src/shared/meson.build b/src/shared/meson.build
8d419f
index 5dc58a863d..006310a917 100644
8d419f
--- a/src/shared/meson.build
8d419f
+++ b/src/shared/meson.build
8d419f
@@ -241,6 +241,8 @@ shared_sources = files('''
8d419f
         parse-argument.h
8d419f
         parse-socket-bind-item.c
8d419f
         parse-socket-bind-item.h
8d419f
+        pcre2-dlopen.c
8d419f
+        pcre2-dlopen.h
8d419f
         pe-header.h
8d419f
         pkcs11-util.c
8d419f
         pkcs11-util.h
8d419f
diff --git a/src/journal/pcre2-dlopen.c b/src/shared/pcre2-dlopen.c
8d419f
similarity index 100%
8d419f
rename from src/journal/pcre2-dlopen.c
8d419f
rename to src/shared/pcre2-dlopen.c
8d419f
diff --git a/src/journal/pcre2-dlopen.h b/src/shared/pcre2-dlopen.h
8d419f
similarity index 100%
8d419f
rename from src/journal/pcre2-dlopen.h
8d419f
rename to src/shared/pcre2-dlopen.h
8d419f
diff --git a/src/test/test-dlopen-so.c b/src/test/test-dlopen-so.c
8d419f
index ea2ef31b1f..002f666ed8 100644
8d419f
--- a/src/test/test-dlopen-so.c
8d419f
+++ b/src/test/test-dlopen-so.c
8d419f
@@ -5,10 +5,12 @@
8d419f
 
8d419f
 #include "bpf-dlopen.h"
8d419f
 #include "cryptsetup-util.h"
8d419f
+#include "elf-util.h"
8d419f
 #include "idn-util.h"
8d419f
 #include "libfido2-util.h"
8d419f
 #include "macro.h"
8d419f
 #include "main-func.h"
8d419f
+#include "pcre2-dlopen.h"
8d419f
 #include "pwquality-util.h"
8d419f
 #include "qrcode-util.h"
8d419f
 #include "tests.h"
8d419f
@@ -49,6 +51,15 @@ static int run(int argc, char **argv) {
8d419f
         assert_se(dlopen_bpf() >= 0);
8d419f
 #endif
8d419f
 
8d419f
+#if HAVE_ELFUTILS
8d419f
+        assert_se(dlopen_dw() >= 0);
8d419f
+        assert_se(dlopen_elf() >= 0);
8d419f
+#endif
8d419f
+
8d419f
+#if HAVE_PCRE2
8d419f
+        assert_se(dlopen_pcre2() >= 0);
8d419f
+#endif
8d419f
+
8d419f
         return 0;
8d419f
 }
8d419f