]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-fileio: test read_virtual_file() with more files from /proc 20763/head
authorLennart Poettering <lennart@poettering.net>
Thu, 16 Sep 2021 09:31:52 +0000 (11:31 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 16 Sep 2021 10:23:32 +0000 (12:23 +0200)
i.e. let's pick some files we know are too large, or where struct stat's
.st_size is zero even though non-empty, and test read_virtual_file()
with that, to ensure things are handled sensibly. Goal is to ensure all
three major codepaths in read_virtual_file() are tested.

Prompted-by: #20743
src/test/test-fileio.c

index 2b6ef495aaf7a562e99cebda17fb6a2d15fe13d9..fa8a66df042bcbff72849c6a1f2b58c89162bcfb 100644 (file)
@@ -1047,7 +1047,11 @@ static void test_read_virtual_file(size_t max_size) {
         FOREACH_STRING(filename,
                        "/proc/1/cmdline",
                        "/etc/nsswitch.conf",
-                       "/sys/kernel/uevent_seqnum") {
+                       "/sys/kernel/uevent_seqnum",
+                       "/proc/kcore",
+                       "/proc/kallsyms",
+                       "/proc/self/exe",
+                       "/proc/self/pagemap") {
 
                 _cleanup_free_ char *buf = NULL;
                 size_t size = 0;
@@ -1055,7 +1059,11 @@ static void test_read_virtual_file(size_t max_size) {
                 r = read_virtual_file(filename, max_size, &buf, &size);
                 if (r < 0) {
                         log_info_errno(r, "read_virtual_file(\"%s\", %zu): %m", filename, max_size);
-                        assert_se(ERRNO_IS_PRIVILEGE(r) || r == -ENOENT);
+                        assert_se(ERRNO_IS_PRIVILEGE(r) || /* /proc/kcore is not accessible to unpriv */
+                                  IN_SET(r,
+                                         -ENOENT,  /* Some of the files might be absent */
+                                         -EINVAL,  /* too small reads from /proc/self/pagemap trigger EINVAL */
+                                         -EFBIG)); /* /proc/kcore and /proc/self/pagemap should be too large */
                 } else
                         log_info("read_virtual_file(\"%s\", %zu): %s (%zu bytes)", filename, max_size, r ? "non-truncated" : "truncated", size);
         }