summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-09-11 09:37:23 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-09-11 09:37:23 -0700
commit30d89e097b9ccc46de833a6bbe2013f223f299dd (patch)
treec20968c854ab92cd975197d40c572f421fb96dbc
parent30a88bbde181cbc6f66e7646591bb1582756ce06 (diff)
downloadtxr-30d89e097b9ccc46de833a6bbe2013f223f299dd.tar.gz
txr-30d89e097b9ccc46de833a6bbe2013f223f299dd.tar.bz2
txr-30d89e097b9ccc46de833a6bbe2013f223f299dd.zip
sockets: bug in clearing SOCK_* type flags.
Paul A. Patience reports a regression in 6ac0b45bdf7d1358234639905e760717f74e572c, whereby the code marked with #if SOCK_NONBLOCK || SOCK_CLOEXEC is being excluded by the preprocoessor, and so those flags are not being cleared from the socket type that we retain. This is because these preprocessor symbols are not necessarily integer constants. They may expand to C enum identifiers, in which case, in preprocessor expressions they appear to take on the value zero. * socket.c (open_socket, socketpair_wrap): Use the if statement to test for SOCK_NONBLOCK or SOCK_CLOEXEC being nonzero, rather than a preprocessor #if. This should still be optimized away as unreachable code if they are zero. * tests/014/socket-misc.tl: New file.
-rw-r--r--socket.c11
-rw-r--r--tests/014/socket-misc.tl4
2 files changed, 9 insertions, 6 deletions
diff --git a/socket.c b/socket.c
index b05d15e8..ea11a8c0 100644
--- a/socket.c
+++ b/socket.c
@@ -1107,9 +1107,9 @@ static val open_socket(val family, val type, val mode_str)
uw_ethrowf(socket_error_s, lit("~a failed: ~d/~s"),
self, num(errno), errno_to_str(errno), nao);
-#if SOCK_NONBLOCK || SOCK_CLOEXEC
- type = num_fast(c_num(type, self) & ~(SOCK_NONBLOCK | SOCK_CLOEXEC));
-#endif
+ if (SOCK_NONBLOCK || SOCK_CLOEXEC)
+ type = num_fast(c_num(type, self) & ~(SOCK_NONBLOCK | SOCK_CLOEXEC));
+
return open_sockfd(num(fd), family, type, mode_str, self);
}
@@ -1126,9 +1126,8 @@ static val socketpair_wrap(val family, val type, val mode_str)
uw_ethrowf(socket_error_s, lit("~a failed: ~d/~s"),
self, num(errno), errno_to_str(errno), nao);
-#if SOCK_NONBLOCK || SOCK_CLOEXEC
- type = num_fast(c_num(type, self) & ~(SOCK_NONBLOCK | SOCK_CLOEXEC));
-#endif
+ if (SOCK_NONBLOCK || SOCK_CLOEXEC)
+ type = num_fast(c_num(type, self) & ~(SOCK_NONBLOCK | SOCK_CLOEXEC));
{
val s0 = open_sockfd(num(sv[0]), family, type, mode_str, self);
diff --git a/tests/014/socket-misc.tl b/tests/014/socket-misc.tl
new file mode 100644
index 00000000..39045c1d
--- /dev/null
+++ b/tests/014/socket-misc.tl
@@ -0,0 +1,4 @@
+(load "../common")
+
+(with-stream (s (open-socket af-inet (logior sock-dgram sock-nonblock)))
+ (test (sock-listen s) t))