]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-coredump-util: also test parse_auxv() with unaligned data 26935/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 22 Mar 2023 13:06:31 +0000 (14:06 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 23 Mar 2023 17:07:45 +0000 (18:07 +0100)
src/test/test-coredump-util.c

index 755cb49dae76a223beeedba78c06e391c23cf565..7a41e0fc2949b1248d453838d401e8f0616df395 100644 (file)
@@ -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;