summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-10-24 09:15:29 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-10-24 22:43:59 +0900
commit58ce85f6a17b6db03265e6a974120b18d1c0855a (patch)
tree9edeb2aef014272253407581886097b0af089fe2
parent1048436869416d58071803e8c4fcc897b373af30 (diff)
downloadsystemd-58ce85f6a17b6db03265e6a974120b18d1c0855a.tar.gz
test-socket-util: avoid writing past the defined buffer
.sun_path has 108 bytes, and we'd write a string of 108 bytes + NUL. I added this test, but I don't know what it was supposed to test. Let's just remove. Fixes #13713. CID#1405854.
-rw-r--r--src/test/test-socket-util.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c
index 4e9a0bddf4..b36e005264 100644
--- a/src/test/test-socket-util.c
+++ b/src/test/test-socket-util.c
@@ -66,7 +66,7 @@ static void test_socket_address_parse_one(const char *in, int ret, int family, c
}
#define SUN_PATH_LEN (sizeof(((struct sockaddr_un){}).sun_path))
-assert_cc(sizeof(((struct sockaddr_un){}).sun_path) == 108);
+assert_cc(SUN_PATH_LEN == 108);
static void test_socket_address_parse(void) {
log_info("/* %s */", __func__);
@@ -126,6 +126,7 @@ static void test_socket_address_parse(void) {
static void test_socket_print_unix_one(const char *in, size_t len_in, const char *expected) {
_cleanup_free_ char *out = NULL, *c = NULL;
+ assert(len_in <= SUN_PATH_LEN);
SocketAddress a = { .sockaddr = { .un = { .sun_family = AF_UNIX } },
.size = offsetof(struct sockaddr_un, sun_path) + len_in,
.type = SOCK_STREAM,
@@ -152,8 +153,6 @@ static void test_socket_print_unix(void) {
"@_________________________there\\'s 108 characters in this string_____________________________________________");
test_socket_print_unix_one("////////////////////////////////////////////////////////////////////////////////////////////////////////////", 108,
"////////////////////////////////////////////////////////////////////////////////////////////////////////////");
- test_socket_print_unix_one("////////////////////////////////////////////////////////////////////////////////////////////////////////////", 109,
- "////////////////////////////////////////////////////////////////////////////////////////////////////////////");
test_socket_print_unix_one("\0\a\b\n\255", 6, "@\\a\\b\\n\\255\\000");
}