From cb38fdbedb1da1a75857dec4e583acf9732c082d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 22 Mar 2023 09:53:16 +0100 Subject: [PATCH 1/3] coredump: split out parse_auxv() to src/shared/ No functional change. (We already checked for ELFCLASS32 or ELFCLASS64 before, so even though there's a new check for other architectures, the only caller only passes ELFCLASS32 or ELFCLASS64.) --- src/coredump/coredump.c | 74 +++--------------------------- src/shared/coredump-util.c | 92 ++++++++++++++++++++++++++++++++++++++ src/shared/coredump-util.h | 10 +++++ 3 files changed, 107 insertions(+), 69 deletions(-) diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index 1f259cf669..b7a62e72b0 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -49,7 +49,6 @@ #include "sync-util.h" #include "tmpfile-util.h" #include "uid-alloc-range.h" -#include "unaligned.h" #include "user-util.h" /* The maximum size up to which we process coredumps. We use 1G on 32bit systems, and 32G on 64bit systems */ @@ -336,66 +335,6 @@ static int make_filename(const Context *context, char **ret) { return 0; } -#define _DEFINE_PARSE_AUXV(size, type, unaligned_read) \ - static int parse_auxv##size( \ - const void *auxv, \ - size_t size_bytes, \ - int *at_secure, \ - uid_t *uid, \ - uid_t *euid, \ - gid_t *gid, \ - gid_t *egid) { \ - \ - assert(auxv || size_bytes == 0); \ - \ - if (size_bytes % (2 * sizeof(type)) != 0) \ - return log_warning_errno(SYNTHETIC_ERRNO(EIO), \ - "Incomplete auxv structure (%zu bytes).", \ - size_bytes); \ - \ - size_t words = size_bytes / sizeof(type); \ - \ - /* Note that we set output variables even on error. */ \ - \ - for (size_t i = 0; i + 1 < words; i += 2) { \ - type key, val; \ - \ - key = unaligned_read((uint8_t*) auxv + i * sizeof(type)); \ - val = unaligned_read((uint8_t*) auxv + (i + 1) * sizeof(type)); \ - \ - switch (key) { \ - case AT_SECURE: \ - *at_secure = val != 0; \ - break; \ - case AT_UID: \ - *uid = val; \ - break; \ - case AT_EUID: \ - *euid = val; \ - break; \ - case AT_GID: \ - *gid = val; \ - break; \ - case AT_EGID: \ - *egid = val; \ - break; \ - case AT_NULL: \ - if (val != 0) \ - goto error; \ - return 0; \ - } \ - } \ - error: \ - return log_warning_errno(SYNTHETIC_ERRNO(ENODATA), \ - "AT_NULL terminator not found, cannot parse auxv structure."); \ - } - -#define DEFINE_PARSE_AUXV(size)\ - _DEFINE_PARSE_AUXV(size, uint##size##_t, unaligned_read_ne##size) - -DEFINE_PARSE_AUXV(32); -DEFINE_PARSE_AUXV(64); - static int grant_user_access(int core_fd, const Context *context) { int at_secure = -1; uid_t uid = UID_INVALID, euid = UID_INVALID; @@ -430,14 +369,11 @@ static int grant_user_access(int core_fd, const Context *context) { return log_info_errno(SYNTHETIC_ERRNO(EUCLEAN), "Core file has non-native endianness, not adjusting permissions."); - if (elf[EI_CLASS] == ELFCLASS64) - r = parse_auxv64(context->meta[META_PROC_AUXV], - context->meta_size[META_PROC_AUXV], - &at_secure, &uid, &euid, &gid, &egid); - else - r = parse_auxv32(context->meta[META_PROC_AUXV], - context->meta_size[META_PROC_AUXV], - &at_secure, &uid, &euid, &gid, &egid); + r = parse_auxv(LOG_WARNING, + /* elf_class= */ elf[EI_CLASS], + context->meta[META_PROC_AUXV], + context->meta_size[META_PROC_AUXV], + &at_secure, &uid, &euid, &gid, &egid); if (r < 0) return r; diff --git a/src/shared/coredump-util.c b/src/shared/coredump-util.c index 3d2f179049..bf8ea00b14 100644 --- a/src/shared/coredump-util.c +++ b/src/shared/coredump-util.c @@ -1,9 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include + #include "coredump-util.h" #include "extract-word.h" #include "fileio.h" #include "string-table.h" +#include "unaligned.h" #include "virt.h" static const char *const coredump_filter_table[_COREDUMP_FILTER_MAX] = { @@ -65,6 +68,95 @@ int coredump_filter_mask_from_string(const char *s, uint64_t *ret) { return 0; } +#define _DEFINE_PARSE_AUXV(size, type, unaligned_read) \ + static int parse_auxv##size( \ + int log_level, \ + const void *auxv, \ + size_t size_bytes, \ + int *at_secure, \ + uid_t *uid, \ + uid_t *euid, \ + gid_t *gid, \ + gid_t *egid) { \ + \ + assert(auxv || size_bytes == 0); \ + assert(at_secure); \ + assert(uid); \ + assert(euid); \ + assert(gid); \ + assert(egid); \ + \ + if (size_bytes % (2 * sizeof(type)) != 0) \ + return log_full_errno(log_level, \ + SYNTHETIC_ERRNO(EIO), \ + "Incomplete auxv structure (%zu bytes).", \ + size_bytes); \ + \ + size_t words = size_bytes / sizeof(type); \ + \ + /* Note that we set output variables even on error. */ \ + \ + for (size_t i = 0; i + 1 < words; i += 2) { \ + type key, val; \ + \ + key = unaligned_read((uint8_t*) auxv + i * sizeof(type)); \ + val = unaligned_read((uint8_t*) auxv + (i + 1) * sizeof(type)); \ + \ + switch (key) { \ + case AT_SECURE: \ + *at_secure = val != 0; \ + break; \ + case AT_UID: \ + *uid = val; \ + break; \ + case AT_EUID: \ + *euid = val; \ + break; \ + case AT_GID: \ + *gid = val; \ + break; \ + case AT_EGID: \ + *egid = val; \ + break; \ + case AT_NULL: \ + if (val != 0) \ + goto error; \ + return 0; \ + } \ + } \ + error: \ + return log_full_errno(log_level, \ + SYNTHETIC_ERRNO(ENODATA), \ + "AT_NULL terminator not found, cannot parse auxv structure."); \ + } + +#define DEFINE_PARSE_AUXV(size) \ + _DEFINE_PARSE_AUXV(size, uint##size##_t, unaligned_read_ne##size) + +DEFINE_PARSE_AUXV(32); +DEFINE_PARSE_AUXV(64); + +int parse_auxv(int log_level, + uint8_t elf_class, + const void *auxv, + size_t size_bytes, + int *at_secure, + uid_t *uid, + uid_t *euid, + gid_t *gid, + gid_t *egid) { + + switch (elf_class) { + case ELFCLASS64: + return parse_auxv64(log_level, auxv, size_bytes, at_secure, uid, euid, gid, egid); + case ELFCLASS32: + return parse_auxv32(log_level, auxv, size_bytes, at_secure, uid, euid, gid, egid); + default: + return log_full_errno(log_level, SYNTHETIC_ERRNO(EPROTONOSUPPORT), + "Unknown ELF class %d.", elf_class); + } +} + int set_coredump_filter(uint64_t value) { char t[STRLEN("0xFFFFFFFF")]; diff --git a/src/shared/coredump-util.h b/src/shared/coredump-util.h index 8eda86dfdb..99dbfde730 100644 --- a/src/shared/coredump-util.h +++ b/src/shared/coredump-util.h @@ -26,5 +26,15 @@ const char* coredump_filter_to_string(CoredumpFilter i) _const_; CoredumpFilter coredump_filter_from_string(const char *s) _pure_; int coredump_filter_mask_from_string(const char *s, uint64_t *ret); +int parse_auxv(int log_level, + uint8_t elf_class, + const void *auxv, + size_t size_bytes, + int *at_secure, + uid_t *uid, + uid_t *euid, + gid_t *gid, + gid_t *egid); + int set_coredump_filter(uint64_t value); void disable_coredumps(void); From 2f809d29e85527acd75d4d2e46aaa14adc2f09dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 22 Mar 2023 13:42:40 +0100 Subject: [PATCH 2/3] test-coredump-util: add tests for parse_aux() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test files are /proc//auxv files copies from various architecutres signified by the file name suffix. Those tests are fairly simple, but when we run them on n architectures, we do ~n² cross-arch tests. --- src/test/test-coredump-util.c | 63 ++++++++++++++++++++ test/auxv/.gitattributes | 3 + test/auxv/bash.riscv64 | Bin 0 -> 384 bytes test/auxv/cat.s390x | Bin 0 -> 304 bytes test/auxv/dbus-broker-launch.aarch64 | Bin 0 -> 336 bytes test/auxv/dbus-broker-launch.amd64 | Bin 0 -> 336 bytes test/auxv/polkitd.aarch64 | Bin 0 -> 336 bytes test/auxv/resolved.arm32 | Bin 0 -> 160 bytes test/auxv/sleep.i686 | Bin 0 -> 192 bytes test/auxv/sleep32.i686 | Bin 0 -> 192 bytes test/auxv/sleep64.amd64 | Bin 0 -> 336 bytes test/auxv/sudo.aarch64 | Bin 0 -> 336 bytes test/auxv/sudo.amd64 | Bin 0 -> 336 bytes test/meson.build | 83 +++++++++------------------ 14 files changed, 92 insertions(+), 57 deletions(-) create mode 100644 test/auxv/.gitattributes create mode 100644 test/auxv/bash.riscv64 create mode 100644 test/auxv/cat.s390x create mode 100644 test/auxv/dbus-broker-launch.aarch64 create mode 100644 test/auxv/dbus-broker-launch.amd64 create mode 100644 test/auxv/polkitd.aarch64 create mode 100644 test/auxv/resolved.arm32 create mode 100644 test/auxv/sleep.i686 create mode 100644 test/auxv/sleep32.i686 create mode 100644 test/auxv/sleep64.amd64 create mode 100644 test/auxv/sudo.aarch64 create mode 100644 test/auxv/sudo.amd64 diff --git a/src/test/test-coredump-util.c b/src/test/test-coredump-util.c index 40b68df9f4..755cb49dae 100644 --- a/src/test/test-coredump-util.c +++ b/src/test/test-coredump-util.c @@ -1,7 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include + #include "alloc-util.h" #include "coredump-util.h" +#include "fileio.h" +#include "fd-util.h" +#include "format-util.h" #include "macro.h" #include "tests.h" @@ -64,4 +69,62 @@ TEST(coredump_filter_mask_from_string) { 1 << COREDUMP_FILTER_SHARED_DAX))); } +static void test_parse_auxv_one( + uint8_t elf_class, + int dir_fd, + const char *filename, + int expect_at_secure, + uid_t expect_uid, + uid_t expect_euid, + gid_t expect_gid, + gid_t expect_egid) { + + _cleanup_free_ char *data; + size_t data_size; + log_info("Parsing %s…", filename); + assert_se(read_full_file_at(dir_fd, filename, &data, &data_size) >= 0); + + int at_secure; + uid_t uid, euid; + gid_t gid, egid; + assert_se(parse_auxv(LOG_ERR, elf_class, data, data_size, + &at_secure, &uid, &euid, &gid, &egid) == 0); + + log_info("at_secure=%d, uid="UID_FMT", euid="UID_FMT", gid="GID_FMT", egid="GID_FMT, + at_secure, uid, euid, gid, egid); + + assert_se(uid == expect_uid); + assert_se(euid == expect_euid); + assert_se(gid == expect_gid); + assert_se(egid == expect_egid); +} + +TEST(test_parse_auxv) { + _cleanup_free_ char *dir = NULL; + _cleanup_close_ int dir_fd = -EBADF; + + assert_se(get_testdata_dir("auxv", &dir) >= 0); + dir_fd = open(dir, O_RDONLY | O_CLOEXEC | O_DIRECTORY | O_PATH); + assert_se(dir_fd >= 0); + + if (__BYTE_ORDER == __LITTLE_ENDIAN) { + test_parse_auxv_one(ELFCLASS32, dir_fd, "resolved.arm32", 0, 193, 193, 193, 193); + test_parse_auxv_one(ELFCLASS64, dir_fd, "bash.riscv64", 0, 1001, 1001, 1001, 1001); + test_parse_auxv_one(ELFCLASS32, dir_fd, "sleep.i686", 0, 1000, 1000, 1000, 1000); + /* after chgrp and chmod g+s */ + test_parse_auxv_one(ELFCLASS32, dir_fd, "sleep32.i686", 1, 1000, 1000, 1000, 10); + test_parse_auxv_one(ELFCLASS64, dir_fd, "sleep64.amd64", 1, 1000, 1000, 1000, 10); + + test_parse_auxv_one(ELFCLASS64, dir_fd, "sudo.aarch64", 1, 1494200408, 0, 1494200408, 1494200408); + test_parse_auxv_one(ELFCLASS64, dir_fd, "sudo.amd64", 1, 1000, 0, 1000, 1000); + + /* Those run unprivileged, but start as root. */ + test_parse_auxv_one(ELFCLASS64, dir_fd, "dbus-broker-launch.amd64", 0, 0, 0, 0, 0); + test_parse_auxv_one(ELFCLASS64, dir_fd, "dbus-broker-launch.aarch64", 0, 0, 0, 0, 0); + test_parse_auxv_one(ELFCLASS64, dir_fd, "polkitd.aarch64", 0, 0, 0, 0, 0); + } else { + test_parse_auxv_one(ELFCLASS64, dir_fd, "cat.s390x", 0, 3481, 3481, 3481, 3481); + } +} + DEFINE_TEST_MAIN(LOG_INFO); diff --git a/test/auxv/.gitattributes b/test/auxv/.gitattributes new file mode 100644 index 0000000000..58e3ff4c98 --- /dev/null +++ b/test/auxv/.gitattributes @@ -0,0 +1,3 @@ +/*.* -whitespace +/*.* binary +/*.* generated diff --git a/test/auxv/bash.riscv64 b/test/auxv/bash.riscv64 new file mode 100644 index 0000000000000000000000000000000000000000..273a468b300ba75532527ff4746f31dca3d0d9ea GIT binary patch literal 384 zcmY#nfP#h<^X!344LBdd(1h|G7&yQzEi`#;G7ZNzHjf+1 qe+jh+W)6(cizd&9#utb3VU#44;r}n}Hz+*iq5OCMA$*uR7!3gMoEBjK literal 0 HcmV?d00001 diff --git a/test/auxv/cat.s390x b/test/auxv/cat.s390x new file mode 100644 index 0000000000000000000000000000000000000000..aa76441fed60eef4598e972a30db9d5cca5cb8bf GIT binary patch literal 304 zcmZQz00Tt^2Il{L{SP2K1_l8zgZ=-1r~n&;h6n@Mf>7}kD9y~kz_dzSgTVpHXMxfd zP?{A=b3$o$uzej+9s>ghoCRS3)q%{@m;e>$hS0n-p?n@RJ}(-d4~;Jl)d!;_LH6I_ X|0n|$kcaU9zlZYqq4GK~4KNx2r`;G6 literal 0 HcmV?d00001 diff --git a/test/auxv/dbus-broker-launch.aarch64 b/test/auxv/dbus-broker-launch.aarch64 new file mode 100644 index 0000000000000000000000000000000000000000..3a05e3cabb0d25a6ec8b16bc908e89c0b6263e17 GIT binary patch literal 336 zcmY#nfP#d;ZU6r>Fc?F*1ws&p0F?iKz95*%2IVtAB?O`T6e!IMr5zYF53O3oz`z3K zTR>@6D9sI}*`YMU1YfZI956nV=7iD>z7X?Z`e4dV!Z literal 0 HcmV?d00001 diff --git a/test/auxv/polkitd.aarch64 b/test/auxv/polkitd.aarch64 new file mode 100644 index 0000000000000000000000000000000000000000..ff1ea9f1409bcaaa3578eb5a73299afd89192c01 GIT binary patch literal 336 zcmY#nfP#jgY5)H-Fc?F*1ws&p0F?iKz95*%2IVtAB?O`T6e!IMr5zZw)~s5^z`z3K zTR>@6D9sI}*`YMU20yU<956nV=7jN=L(GHeg9-D%7*LuQjn9Y17f0huLismXUf%%u YUkXiL9?HMR50U4G@?SvJqbX+q0Km~6Z2$lO literal 0 HcmV?d00001 diff --git a/test/auxv/resolved.arm32 b/test/auxv/resolved.arm32 new file mode 100644 index 0000000000000000000000000000000000000000..7d05f3b20b8f961b92f7aa1de3794d1af0f98f52 GIT binary patch literal 160 zcmY#n0D^*l`vid0wGH+RY#=_6BM78YfS4JGO&A;)Sb($w5VHa?ClIp(F+;K7JtE8z>H>zyJUR CJQhs= literal 0 HcmV?d00001 diff --git a/test/auxv/sleep.i686 b/test/auxv/sleep.i686 new file mode 100644 index 0000000000000000000000000000000000000000..d0b5f2c92747c8f47a351db746dd2a42a5d8a18d GIT binary patch literal 192 zcmY#jU|ui5CGEuf4|<(1`-Ey1c6iv5Hka@NdpT93y@X- zVpbsL0b+I_W;pQqI|qmc0!|=Kn83op4WwTHHG$NCXkI7{v;xc*2ht!Q3B=tOC;XQJ Y(o8@s55(`@Px#Ldq-O)gffQB%0LarEy8r+H literal 0 HcmV?d00001 diff --git a/test/auxv/sleep32.i686 b/test/auxv/sleep32.i686 new file mode 100644 index 0000000000000000000000000000000000000000..f52f512436de7eba5847aade98baabb3cd3f4521 GIT binary patch literal 192 zcmY#jU|>(xfy99vK_Ha^#LPf!(!j#O0;Cmy zm=%b5fS4VK84BKg=K#?_zzM_&6IeL7f%FTYCXgBs%?qW0Rxoe@u{aPj0r?DJ_thq%K!iS^?neO4a#SLN(e&vDNvdjN;@z(fLSb1z6F$K zh0?rGnjK0rFs%J=0JNV2&WA8Kp?n7c2QZ5p%6|d1hzE@iGZ!Wg^#%hMRGm1KW`xp` gP&!j@6D9sI}*`YK;!F90x956nV=7iD*Iw9u4^hIpoj|55aK;>Z+FO&h3=R@O*L-~wQ jS`tcoY%hKV^1l?652NIvj92F&^88SK1XMjt9gGG5Iw~Y! literal 0 HcmV?d00001 diff --git a/test/auxv/sudo.amd64 b/test/auxv/sudo.amd64 new file mode 100644 index 0000000000000000000000000000000000000000..91e46466154133d87ae0f87f1c3231ac6043aba8 GIT binary patch literal 336 zcmY#nfPxRw;s5Iy7>uD@13m~t0LuUW`}KYhlMTvefJz8L`6*DE8A>}mh*Vn>%D}(^ zKrv05{tkC;$Ke literal 0 HcmV?d00001 diff --git a/test/meson.build b/test/meson.build index 1135ecd920..1721cffcd5 100644 --- a/test/meson.build +++ b/test/meson.build @@ -3,63 +3,32 @@ if install_tests testdata_dir = testsdir + '/testdata/' - install_subdir('journal-data', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('units', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('test-execute', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('test-fstab-generator', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('test-path', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('test-path-util', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('test-umount', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('test-network-generator-conversion', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('testsuite-03.units', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('testsuite-04.units', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('testsuite-06.units', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('testsuite-10.units', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('testsuite-11.units', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('testsuite-16.units', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('testsuite-28.units', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('testsuite-30.units', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('testsuite-52.units', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('testsuite-63.units', - exclude_files : '.gitattributes', - install_dir : testdata_dir) - install_subdir('testsuite-80.units', - exclude_files : '.gitattributes', - install_dir : testdata_dir) + foreach subdir : [ + 'auxv', + 'journal-data', + 'units', + 'test-execute', + 'test-fstab-generator', + 'test-path', + 'test-path-util', + 'test-umount', + 'test-network-generator-conversion', + 'testsuite-03.units', + 'testsuite-04.units', + 'testsuite-06.units', + 'testsuite-10.units', + 'testsuite-11.units', + 'testsuite-16.units', + 'testsuite-28.units', + 'testsuite-30.units', + 'testsuite-52.units', + 'testsuite-63.units', + 'testsuite-80.units', + ] + install_subdir(subdir, + exclude_files : '.gitattributes', + install_dir : testdata_dir) + endforeach install_data(kbd_model_map, install_dir : testdata_dir + '/test-keymap-util') From f39546a8818c85ac082cde711074407c5e86bd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 22 Mar 2023 14:06:31 +0100 Subject: [PATCH 3/3] test-coredump-util: also test parse_auxv() with unaligned data --- src/test/test-coredump-util.c | 55 ++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/src/test/test-coredump-util.c b/src/test/test-coredump-util.c index 755cb49dae..7a41e0fc29 100644 --- a/src/test/test-coredump-util.c +++ b/src/test/test-coredump-util.c @@ -69,6 +69,33 @@ TEST(coredump_filter_mask_from_string) { 1 << COREDUMP_FILTER_SHARED_DAX))); } +static void test_parse_auxv_two( + uint8_t elf_class, + size_t offset, + const char *data, + size_t data_size, + int expect_at_secure, + uid_t expect_uid, + uid_t expect_euid, + gid_t expect_gid, + gid_t expect_egid) { + + int at_secure; + uid_t uid, euid; + gid_t gid, egid; + assert_se(parse_auxv(LOG_ERR, elf_class, data, data_size, + &at_secure, &uid, &euid, &gid, &egid) == 0); + + log_debug("[offset=%zu] at_secure=%d, uid="UID_FMT", euid="UID_FMT", gid="GID_FMT", egid="GID_FMT, + offset, + at_secure, uid, euid, gid, egid); + + assert_se(uid == expect_uid); + assert_se(euid == expect_euid); + assert_se(gid == expect_gid); + assert_se(egid == expect_egid); +} + static void test_parse_auxv_one( uint8_t elf_class, int dir_fd, @@ -79,24 +106,26 @@ static void test_parse_auxv_one( gid_t expect_gid, gid_t expect_egid) { - _cleanup_free_ char *data; + _cleanup_free_ char *buf; + const char *data; size_t data_size; log_info("Parsing %s…", filename); - assert_se(read_full_file_at(dir_fd, filename, &data, &data_size) >= 0); + assert_se(read_full_file_at(dir_fd, filename, &buf, &data_size) >= 0); - int at_secure; - uid_t uid, euid; - gid_t gid, egid; - assert_se(parse_auxv(LOG_ERR, elf_class, data, data_size, - &at_secure, &uid, &euid, &gid, &egid) == 0); + for (size_t offset = 0; offset < 8; offset++) { + _cleanup_free_ char *buf2 = NULL; - log_info("at_secure=%d, uid="UID_FMT", euid="UID_FMT", gid="GID_FMT", egid="GID_FMT, - at_secure, uid, euid, gid, egid); + if (offset == 0) + data = buf; + else { + assert_se(buf2 = malloc(offset + data_size)); + memcpy(buf2 + offset, buf, data_size); + data = buf2 + offset; + } - assert_se(uid == expect_uid); - assert_se(euid == expect_euid); - assert_se(gid == expect_gid); - assert_se(egid == expect_egid); + test_parse_auxv_two(elf_class, offset, data, data_size, + expect_at_secure, expect_uid, expect_euid, expect_gid, expect_egid); + } } TEST(test_parse_auxv) {