[v4,08/13] io: Add tst-lstat-nofollow, tst-lstat-nofollow-time64
Checks
Context |
Check |
Description |
redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Test passed
|
Commit Message
They verify that lstat, lstat64 do not follow symbolic links.
---
io/Makefile | 2 +
io/tst-lstat-nofollow-time64.c | 1 +
io/tst-lstat-nofollow.c | 98 ++++++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+)
create mode 100644 io/tst-lstat-nofollow-time64.c
create mode 100644 io/tst-lstat-nofollow.c
Comments
LGTM
Reviewed-by: DJ Delorie <dj@redhat.com>
Florian Weimer <fweimer@redhat.com> writes:
> They verify that lstat, lstat64 do not follow symbolic links.
> ---
> io/Makefile | 2 +
> io/tst-lstat-nofollow-time64.c | 1 +
> io/tst-lstat-nofollow.c | 98 ++++++++++++++++++++++++++++++++++
> 3 files changed, 101 insertions(+)
> create mode 100644 io/tst-lstat-nofollow-time64.c
> create mode 100644 io/tst-lstat-nofollow.c
>
> diff --git a/io/Makefile b/io/Makefile
> index 8987dc1375..a401ec414e 100644
> --- a/io/Makefile
> +++ b/io/Makefile
> @@ -209,6 +209,7 @@ tests := \
> tst-lchmod \
> tst-linkat \
> tst-lockf \
> + tst-lstat-nofollow \
Ok.
> @@ -238,6 +239,7 @@ tests-time64 := \
> tst-futimes-time64\
> tst-futimesat-time64 \
> tst-lchmod-time64 \
> + tst-lstat-nofollow-time64 \
Ok.
> diff --git a/io/tst-lstat-nofollow-time64.c b/io/tst-lstat-nofollow-time64.c
> new file mode 100644
> index 0000000000..45feb3f130
> --- /dev/null
> +++ b/io/tst-lstat-nofollow-time64.c
> @@ -0,0 +1 @@
> +#include "tst-lstat-nofollow.c"
Ok.
> diff --git a/io/tst-lstat-nofollow.c b/io/tst-lstat-nofollow.c
> new file mode 100644
> index 0000000000..5bbb557c72
> --- /dev/null
> +++ b/io/tst-lstat-nofollow.c
> @@ -0,0 +1,98 @@
> +/* Test that lstat does not follow symbolic links.
> + Copyright (C) 2024 Free Software Foundation, Inc.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> +#include <string.h>
> +#include <support/check.h>
> +#include <support/fuse.h>
> +#include <support/support.h>
> +#include <sys/stat.h>
> +#include <unistd.h>
Ok.
> +static void
> +fuse_thread (struct support_fuse *f, void *closure)
> +{
> + struct fuse_in_header *inh;
> + while ((inh = support_fuse_next (f)) != NULL)
> + {
> + if (support_fuse_handle_mountpoint (f)
> + || (inh->nodeid == 1 && support_fuse_handle_directory (f)))
> + continue;
> + switch (inh->opcode)
> + {
> + case FUSE_LOOKUP:
> + {
> + TEST_COMPARE (inh->nodeid, 1);
> + TEST_COMPARE_STRING (support_fuse_cast (LOOKUP, inh), "symlink");
> + struct fuse_entry_out *out = support_fuse_prepare_entry (f, 2);
> + out->attr.mode = S_IFLNK | 0777;
> + out->attr.size = strlen ("target");
> + support_fuse_reply_prepared (f);
> + }
> + break;
Ok; symlink -> target
> + case FUSE_GETATTR:
> + {
> + TEST_COMPARE (inh->nodeid, 2);
> + struct fuse_attr_out *out = support_fuse_prepare_attr (f);
> + out->attr.mode = S_IFLNK | 0777;
> + out->attr.size = strlen ("target");
> + support_fuse_reply_prepared (f);
> + }
> + break;
Ok
> + case FUSE_READLINK:
> + /* The lstat operation must not attempt to look at the
> + symbolic link target. */
> + FAIL ("attempt to obtain target of symblic link for node %llu",
> + (unsigned long long int) inh->nodeid);
> + break;
Ok.
> + default:
> + FAIL ("unexpected event %s", support_fuse_opcode (inh->opcode));
> + }
> + }
> +}
Ok.
> +static int
> +do_test (void)
> +{
> + support_fuse_init ();
> + struct support_fuse *f = support_fuse_mount (fuse_thread, NULL);
> + char *symlink_path = xasprintf ("%s/symlink", support_fuse_mountpoint (f));
> +
> + {
> + struct stat st = { 0, };
> + TEST_COMPARE (lstat (symlink_path, &st), 0);
> + TEST_COMPARE (st.st_uid, getuid ());
> + TEST_COMPARE (st.st_gid, getgid ());
> + TEST_COMPARE (st.st_size, 6);
> + TEST_COMPARE (st.st_mode, S_IFLNK | 0777);
> + }
Ok.
> + {
> + struct stat64 st = { 0, };
> + TEST_COMPARE (lstat64 (symlink_path, &st), 0);
> + TEST_COMPARE (st.st_uid, getuid ());
> + TEST_COMPARE (st.st_gid, getgid ());
> + TEST_COMPARE (st.st_size, 6);
> + TEST_COMPARE (st.st_mode, S_IFLNK | 0777);
> + }
Ok.
> + free (symlink_path);
> + support_fuse_unmount (f);
> + return 0;
> +}
> +
> +#include <support/test-driver.c>
Ok.
@@ -209,6 +209,7 @@ tests := \
tst-lchmod \
tst-linkat \
tst-lockf \
+ tst-lstat-nofollow \
tst-lutimes \
tst-mkdirat \
tst-mkfifoat \
@@ -238,6 +239,7 @@ tests-time64 := \
tst-futimes-time64\
tst-futimesat-time64 \
tst-lchmod-time64 \
+ tst-lstat-nofollow-time64 \
tst-lutimes-time64 \
tst-stat-time64 \
tst-utime-time64 \
new file mode 100644
@@ -0,0 +1 @@
+#include "tst-lstat-nofollow.c"
new file mode 100644
@@ -0,0 +1,98 @@
+/* Test that lstat does not follow symbolic links.
+ Copyright (C) 2024 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <string.h>
+#include <support/check.h>
+#include <support/fuse.h>
+#include <support/support.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+static void
+fuse_thread (struct support_fuse *f, void *closure)
+{
+ struct fuse_in_header *inh;
+ while ((inh = support_fuse_next (f)) != NULL)
+ {
+ if (support_fuse_handle_mountpoint (f)
+ || (inh->nodeid == 1 && support_fuse_handle_directory (f)))
+ continue;
+ switch (inh->opcode)
+ {
+ case FUSE_LOOKUP:
+ {
+ TEST_COMPARE (inh->nodeid, 1);
+ TEST_COMPARE_STRING (support_fuse_cast (LOOKUP, inh), "symlink");
+ struct fuse_entry_out *out = support_fuse_prepare_entry (f, 2);
+ out->attr.mode = S_IFLNK | 0777;
+ out->attr.size = strlen ("target");
+ support_fuse_reply_prepared (f);
+ }
+ break;
+ case FUSE_GETATTR:
+ {
+ TEST_COMPARE (inh->nodeid, 2);
+ struct fuse_attr_out *out = support_fuse_prepare_attr (f);
+ out->attr.mode = S_IFLNK | 0777;
+ out->attr.size = strlen ("target");
+ support_fuse_reply_prepared (f);
+ }
+ break;
+ case FUSE_READLINK:
+ /* The lstat operation must not attempt to look at the
+ symbolic link target. */
+ FAIL ("attempt to obtain target of symblic link for node %llu",
+ (unsigned long long int) inh->nodeid);
+ break;
+ default:
+ FAIL ("unexpected event %s", support_fuse_opcode (inh->opcode));
+ }
+ }
+}
+
+static int
+do_test (void)
+{
+ support_fuse_init ();
+ struct support_fuse *f = support_fuse_mount (fuse_thread, NULL);
+ char *symlink_path = xasprintf ("%s/symlink", support_fuse_mountpoint (f));
+
+ {
+ struct stat st = { 0, };
+ TEST_COMPARE (lstat (symlink_path, &st), 0);
+ TEST_COMPARE (st.st_uid, getuid ());
+ TEST_COMPARE (st.st_gid, getgid ());
+ TEST_COMPARE (st.st_size, 6);
+ TEST_COMPARE (st.st_mode, S_IFLNK | 0777);
+ }
+
+ {
+ struct stat64 st = { 0, };
+ TEST_COMPARE (lstat64 (symlink_path, &st), 0);
+ TEST_COMPARE (st.st_uid, getuid ());
+ TEST_COMPARE (st.st_gid, getgid ());
+ TEST_COMPARE (st.st_size, 6);
+ TEST_COMPARE (st.st_mode, S_IFLNK | 0777);
+ }
+
+ free (symlink_path);
+ support_fuse_unmount (f);
+ return 0;
+}
+
+#include <support/test-driver.c>