summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2011-07-06 06:23:00 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2011-07-06 06:23:00 +0000
commita1f9369b8a770a2b03dd899cbf7f0425433fc4b3 (patch)
tree2703e36472c261fabd760c87e0a934673b3593ee /regress
parent4d4823e51f9b72164639dc39180d972655f38669 (diff)
Test handling of non-NUL terminated sun_path values as well as garbage
in the end of the sockaddr_un. Done with claudio@
Diffstat (limited to 'regress')
-rw-r--r--regress/sys/kern/unixsock/unixsock_test.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/regress/sys/kern/unixsock/unixsock_test.c b/regress/sys/kern/unixsock/unixsock_test.c
index a4941549686..6ed1b0ef1bc 100644
--- a/regress/sys/kern/unixsock/unixsock_test.c
+++ b/regress/sys/kern/unixsock/unixsock_test.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: unixsock_test.c,v 1.1 2011/07/05 23:09:16 claudio Exp $ */
+/* $OpenBSD: unixsock_test.c,v 1.2 2011/07/06 06:22:59 guenther Exp $ */
/* Written by Claudio Jeker in 2011 */
/* Public domain */
#include <sys/types.h>
@@ -28,6 +28,7 @@ test_bind(struct sockaddr_un *sun, socklen_t slen)
r = bind(s, (struct sockaddr *)sun, slen);
e = errno;
close(s);
+ sun->sun_path[slen - 2] = '\0';
unlink(sun->sun_path);
errno = e;
return r;
@@ -66,8 +67,10 @@ struct test {
{30, 0},
{50, 0},
{100, 0},
+ {102, 0},
{103, 0},
{104, -1},
+ {105, -1},
{110, -1},
{200, -1},
{0, 0}
@@ -93,7 +96,7 @@ main()
for (i = 0; t[i].len != 0; i++) {
socklen_t slen = t[i].len;
- memset(&ss, 0, sizeof(ss));
+ memset(&ss, 0xfe, sizeof(ss));
sun = (struct sockaddr_un *)&ss;
sun->sun_family = AF_UNIX;
@@ -121,6 +124,13 @@ main()
sizeof(*sun));
fail = 1;
}
+ sun->sun_path[slen] = 'a';
+ if (test_bind(sun, slen + 2) != t[i].r) {
+ warn("FAIL4: bind(\"%.*s\") len %d no-NUL",
+ slen + 2, sun->sun_path, slen + 2);
+ fail = 1;
+ }
+ sun->sun_path[slen] = '\0';
if (test_connect(sun, slen + 2, &sun2) != t[i].r) {
warn("FAIL: connect(\"%s\") len %d", sun->sun_path,
@@ -128,7 +138,7 @@ main()
fail = 1;
}
if (test_connect(sun, slen + 3, &sun2) != t[i].r) {
- warn("FAIL: connect(\"%s\") len %d", sun->sun_path,
+ warn("FAIL2: connect(\"%s\") len %d", sun->sun_path,
slen + 3);
fail = 1;
}
@@ -138,6 +148,12 @@ main()
sizeof(*sun));
fail = 1;
}
+ sun->sun_path[slen] = 'a';
+ if (test_connect(sun, slen + 2, &sun2) != t[i].r) {
+ warn("FAIL4: connect(\"%.*s\") len %d no-NUL",
+ slen + 2, sun->sun_path, slen + 2);
+ fail = 1;
+ }
}
return fail;
}