From: Zbigniew Jędrzejewski-Szmek Date: Wed, 22 Mar 2023 13:06:31 +0000 (+0100) Subject: test-coredump-util: also test parse_auxv() with unaligned data X-Git-Tag: v254-rc1~943^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F26935%2Fhead;p=thirdparty%2Fsystemd.git test-coredump-util: also test parse_auxv() with unaligned data --- diff --git a/src/test/test-coredump-util.c b/src/test/test-coredump-util.c index 755cb49dae7..7a41e0fc294 100644 --- a/src/test/test-coredump-util.c +++ b/src/test/test-coredump-util.c @@ -69,29 +69,26 @@ TEST(coredump_filter_mask_from_string) { 1 << COREDUMP_FILTER_SHARED_DAX))); } -static void test_parse_auxv_one( +static void test_parse_auxv_two( uint8_t elf_class, - int dir_fd, - const char *filename, + 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) { - _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); + 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); @@ -99,6 +96,38 @@ static void test_parse_auxv_one( assert_se(egid == expect_egid); } +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 *buf; + const char *data; + size_t data_size; + log_info("Parsing %s…", filename); + assert_se(read_full_file_at(dir_fd, filename, &buf, &data_size) >= 0); + + for (size_t offset = 0; offset < 8; offset++) { + _cleanup_free_ char *buf2 = NULL; + + if (offset == 0) + data = buf; + else { + assert_se(buf2 = malloc(offset + data_size)); + memcpy(buf2 + offset, buf, data_size); + data = buf2 + offset; + } + + 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) { _cleanup_free_ char *dir = NULL; _cleanup_close_ int dir_fd = -EBADF;