Skip to content

Commit

Permalink
shared: Add more dlopen() tests
Browse files Browse the repository at this point in the history
Add dlopen_dw(), dlopen_elf() and dlopen_pcre2() to the dlopen test.
To enable adding dlopen_pcre2(), we move pcre2-dlopen.h/c from
src/journal to src/shared.
  • Loading branch information
DaanDeMeyer committed Mar 1, 2022
1 parent c8aeb9d commit ee48779
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/journal/meson.build
Expand Up @@ -49,8 +49,6 @@ systemd_cat_sources = files('cat.c')

journalctl_sources = files('''
journalctl.c
pcre2-dlopen.c
pcre2-dlopen.h
'''.split())

if install_sysconfdir_samples
Expand Down
4 changes: 2 additions & 2 deletions src/shared/elf-util.c
Expand Up @@ -80,7 +80,7 @@ unsigned int (*sym_elf_version)(unsigned int);
GElf_Phdr *(*sym_gelf_getphdr)(Elf *, int, GElf_Phdr *);
size_t (*sym_gelf_getnote)(Elf_Data *, size_t, GElf_Nhdr *, size_t *, size_t *);

static int dlopen_dw(void) {
int dlopen_dw(void) {
int r;

r = dlopen_many_sym_or_warn(
Expand Down Expand Up @@ -123,7 +123,7 @@ static int dlopen_dw(void) {
return 1;
}

static int dlopen_elf(void) {
int dlopen_elf(void) {
int r;

r = dlopen_many_sym_or_warn(
Expand Down
3 changes: 3 additions & 0 deletions src/shared/elf-util.h
Expand Up @@ -4,6 +4,9 @@
#include "json.h"

#if HAVE_ELFUTILS
int dlopen_dw(void);
int dlopen_elf(void);

/* Parse an ELF object in a forked process, so that errors while iterating over
* untrusted and potentially malicious data do not propagate to the main caller's process.
* If fork_disable_dump, the child process will not dump core if it crashes. */
Expand Down
2 changes: 2 additions & 0 deletions src/shared/meson.build
Expand Up @@ -243,6 +243,8 @@ shared_sources = files('''
parse-argument.h
parse-socket-bind-item.c
parse-socket-bind-item.h
pcre2-dlopen.c
pcre2-dlopen.h
pe-header.h
pkcs11-util.c
pkcs11-util.h
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions src/test/test-dlopen-so.c
Expand Up @@ -5,10 +5,12 @@

#include "bpf-dlopen.h"
#include "cryptsetup-util.h"
#include "elf-util.h"
#include "idn-util.h"
#include "libfido2-util.h"
#include "macro.h"
#include "main-func.h"
#include "pcre2-dlopen.h"
#include "pwquality-util.h"
#include "qrcode-util.h"
#include "tests.h"
Expand Down Expand Up @@ -49,6 +51,15 @@ static int run(int argc, char **argv) {
assert_se(dlopen_bpf() >= 0);
#endif

#if HAVE_ELFUTILS
assert_se(dlopen_dw() >= 0);
assert_se(dlopen_elf() >= 0);
#endif

#if HAVE_PCRE2
assert_se(dlopen_pcre2() >= 0);
#endif

return 0;
}

Expand Down

0 comments on commit ee48779

Please sign in to comment.