diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-04-14 06:52:01 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-04-14 06:52:01 -0700 |
commit | 9a03b24eb2cc94a2e95f6a50db60ea6ed3004130 (patch) | |
tree | c31fc5ead97a7b7a1b17fbe8cece870dc1a3b29c | |
parent | 10b6ffd9a5409dc578dfaa58e0d137d3b6c74657 (diff) | |
download | txr-9a03b24eb2cc94a2e95f6a50db60ea6ed3004130.tar.gz txr-9a03b24eb2cc94a2e95f6a50db60ea6ed3004130.tar.bz2 txr-9a03b24eb2cc94a2e95f6a50db60ea6ed3004130.zip |
Fix error handling in dgram case of sock-accept.
* socket.c (sock_accept): Reduce scope of unwind catch around
recvfrom call. Add missing check nbytes == -1. Branch to
failed label in dup failed case, instead of throwing
exception with truncated "unable to" message.
-rw-r--r-- | socket.c | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -835,6 +835,16 @@ static val sock_accept(val sock, val mode_str, val timeout_in) sig_restore_enable; + uw_unwind { + if (nbytes == -1) + free(dgram); + } + + uw_catch_end; + + if (nbytes == -1) + goto failed; + if (family == num_fast(AF_INET)) peer = sockaddr_in_unpack(coerce(struct sockaddr_in *, &sa)); else if (family == num_fast(AF_INET6)) @@ -843,18 +853,10 @@ static val sock_accept(val sock, val mode_str, val timeout_in) peer = sockaddr_un_unpack(coerce(struct sockaddr_un *, &sa)); else { free(dgram); - dgram = 0; uw_throwf(socket_error_s, lit("sock-accept: ~s isn't a supported socket family"), family, nao); } - uw_unwind { - if (nbytes == -1) - free(dgram); - } - - uw_catch_end; - { int afd = dup(fd); struct stdio_mode mode_rpb = stdio_mode_init_rpb; @@ -866,8 +868,7 @@ static val sock_accept(val sock, val mode_str, val timeout_in) if (afd == -1) { free(dgram); dgram = 0; - uw_throwf(socket_error_s, lit("sock-accept: unable to "), - family, nao); + goto failed; } return make_dgram_sock_stream(afd, family, peer, dgram, nbytes, coerce(struct sockaddr *, &sa), salen, |