teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0040-shared-Add-more-dlopen-tests.patch

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