diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-08 18:51:17 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-08 18:51:17 +0000 |
commit | f8bdff40eb3060586a7a385e7879f519b9af7d51 (patch) | |
tree | 0581c838f37fefddfd6d880aea14159dd9479e93 /src/test/test-fs-util.c | |
parent | Releasing progress-linux version 252.22-1~deb12u1progress7u1. (diff) | |
download | systemd-f8bdff40eb3060586a7a385e7879f519b9af7d51.tar.xz systemd-f8bdff40eb3060586a7a385e7879f519b9af7d51.zip |
Merging upstream version 252.23.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test-fs-util.c')
-rw-r--r-- | src/test/test-fs-util.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index 67feb68..35b93b6 100644 --- a/src/test/test-fs-util.c +++ b/src/test/test-fs-util.c @@ -1068,4 +1068,42 @@ static int intro(void) { return EXIT_SUCCESS; } +TEST(readlinkat_malloc) { + _cleanup_(rm_rf_physical_and_freep) char *t = NULL; + _cleanup_close_ int tfd = -EBADF, fd = -EBADF; + _cleanup_free_ char *p = NULL, *q = NULL; + const char *expect = "hgoehogefoobar", *a; + + a = strjoina(arg_test_dir ?: "/tmp", "/readlinkat-malloc.XXXXXX"); + assert_se(mkdtemp_malloc(a, &t) >= 0); + + tfd = open(t, O_PATH|O_DIRECTORY|O_CLOEXEC); + assert_se(tfd >= 0); + + assert_se(symlinkat(expect, tfd, "linkname") >= 0); + + assert_se(readlinkat_malloc(tfd, "linkname", &p) >= 0); + assert_se(streq(p, expect)); + p = mfree(p); + + fd = openat(tfd, "linkname", O_PATH | O_NOFOLLOW | O_CLOEXEC); + assert_se(fd >= 0); + assert_se(readlinkat_malloc(fd, NULL, &p) >= 0); + assert_se(streq(p, expect)); + p = mfree(p); + assert_se(readlinkat_malloc(fd, "", &p) >= 0); + assert_se(streq(p, expect)); + p = mfree(p); + fd = safe_close(fd); + + assert_se(q = path_join(t, "linkname")); + assert_se(readlinkat_malloc(AT_FDCWD, q, &p) >= 0); + assert_se(streq(p, expect)); + p = mfree(p); + assert_se(readlinkat_malloc(INT_MAX, q, &p) >= 0); + assert_se(streq(p, expect)); + p = mfree(p); + q = mfree(q); +} + DEFINE_TEST_MAIN_WITH_INTRO(LOG_INFO, intro); |