aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/coredump/stackdump_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/testing/selftests/coredump/stackdump_test.c')
-rw-r--r--tools/testing/selftests/coredump/stackdump_test.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/tools/testing/selftests/coredump/stackdump_test.c b/tools/testing/selftests/coredump/stackdump_test.c
index 9a789156f27e..a4ac80bb1003 100644
--- a/tools/testing/selftests/coredump/stackdump_test.c
+++ b/tools/testing/selftests/coredump/stackdump_test.c
@@ -241,16 +241,19 @@ out:
static bool set_core_pattern(const char *pattern)
{
- FILE *file;
- int ret;
+ int fd;
+ ssize_t ret;
- file = fopen("/proc/sys/kernel/core_pattern", "w");
- if (!file)
+ fd = open("/proc/sys/kernel/core_pattern", O_WRONLY | O_CLOEXEC);
+ if (fd < 0)
return false;
- ret = fprintf(file, "%s", pattern);
- fclose(file);
+ ret = write(fd, pattern, strlen(pattern));
+ close(fd);
+ if (ret < 0)
+ return false;
+ fprintf(stderr, "Set core_pattern to '%s' | %zu == %zu\n", pattern, ret, strlen(pattern));
return ret == strlen(pattern);
}
@@ -1804,4 +1807,21 @@ out:
wait_and_check_coredump_server(pid_coredump_server, _metadata, self);
}
+TEST_F(coredump, socket_invalid_paths)
+{
+ ASSERT_FALSE(set_core_pattern("@ /tmp/coredump.socket"));
+ ASSERT_FALSE(set_core_pattern("@/tmp/../coredump.socket"));
+ ASSERT_FALSE(set_core_pattern("@../coredump.socket"));
+ ASSERT_FALSE(set_core_pattern("@/tmp/coredump.socket/.."));
+ ASSERT_FALSE(set_core_pattern("@.."));
+
+ ASSERT_FALSE(set_core_pattern("@@ /tmp/coredump.socket"));
+ ASSERT_FALSE(set_core_pattern("@@/tmp/../coredump.socket"));
+ ASSERT_FALSE(set_core_pattern("@@../coredump.socket"));
+ ASSERT_FALSE(set_core_pattern("@@/tmp/coredump.socket/.."));
+ ASSERT_FALSE(set_core_pattern("@@.."));
+
+ ASSERT_FALSE(set_core_pattern("@@@/tmp/coredump.socket"));
+}
+
TEST_HARNESS_MAIN