diff options
Diffstat (limited to '')
| -rw-r--r-- | src/usr.bin/nc/netcat.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index ba7e88af55..99fea29b03 100644 --- a/src/usr.bin/nc/netcat.c +++ b/src/usr.bin/nc/netcat.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: netcat.c,v 1.154 2016/06/27 23:58:08 deraadt Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.155 2016/06/28 00:01:10 deraadt Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
| 4 | * Copyright (c) 2015 Bob Beck. All rights reserved. | 4 | * Copyright (c) 2015 Bob Beck. All rights reserved. |
| @@ -668,7 +668,7 @@ int | |||
| 668 | unix_bind(char *path, int flags) | 668 | unix_bind(char *path, int flags) |
| 669 | { | 669 | { |
| 670 | struct sockaddr_un s_un; | 670 | struct sockaddr_un s_un; |
| 671 | int s; | 671 | int s, save_errno; |
| 672 | 672 | ||
| 673 | /* Create unix domain socket. */ | 673 | /* Create unix domain socket. */ |
| 674 | if ((s = socket(AF_UNIX, flags | (uflag ? SOCK_DGRAM : SOCK_STREAM), | 674 | if ((s = socket(AF_UNIX, flags | (uflag ? SOCK_DGRAM : SOCK_STREAM), |
| @@ -686,7 +686,9 @@ unix_bind(char *path, int flags) | |||
| 686 | } | 686 | } |
| 687 | 687 | ||
| 688 | if (bind(s, (struct sockaddr *)&s_un, sizeof(s_un)) < 0) { | 688 | if (bind(s, (struct sockaddr *)&s_un, sizeof(s_un)) < 0) { |
| 689 | save_errno = errno; | ||
| 689 | close(s); | 690 | close(s); |
| 691 | errno = save_errno; | ||
| 690 | return (-1); | 692 | return (-1); |
| 691 | } | 693 | } |
| 692 | return (s); | 694 | return (s); |
| @@ -762,7 +764,7 @@ int | |||
| 762 | unix_connect(char *path) | 764 | unix_connect(char *path) |
| 763 | { | 765 | { |
| 764 | struct sockaddr_un s_un; | 766 | struct sockaddr_un s_un; |
| 765 | int s; | 767 | int s, save_errno; |
| 766 | 768 | ||
| 767 | if (uflag) { | 769 | if (uflag) { |
| 768 | if ((s = unix_bind(unix_dg_tmp_socket, SOCK_CLOEXEC)) < 0) | 770 | if ((s = unix_bind(unix_dg_tmp_socket, SOCK_CLOEXEC)) < 0) |
| @@ -782,7 +784,9 @@ unix_connect(char *path) | |||
| 782 | return (-1); | 784 | return (-1); |
| 783 | } | 785 | } |
| 784 | if (connect(s, (struct sockaddr *)&s_un, sizeof(s_un)) < 0) { | 786 | if (connect(s, (struct sockaddr *)&s_un, sizeof(s_un)) < 0) { |
| 787 | save_errno = errno; | ||
| 785 | close(s); | 788 | close(s); |
| 789 | errno = save_errno; | ||
| 786 | return (-1); | 790 | return (-1); |
| 787 | } | 791 | } |
| 788 | return (s); | 792 | return (s); |
| @@ -816,7 +820,7 @@ int | |||
| 816 | remote_connect(const char *host, const char *port, struct addrinfo hints) | 820 | remote_connect(const char *host, const char *port, struct addrinfo hints) |
| 817 | { | 821 | { |
| 818 | struct addrinfo *res, *res0; | 822 | struct addrinfo *res, *res0; |
| 819 | int s, error, on = 1; | 823 | int s, error, on = 1, save_errno; |
| 820 | 824 | ||
| 821 | if ((error = getaddrinfo(host, port, &hints, &res))) | 825 | if ((error = getaddrinfo(host, port, &hints, &res))) |
| 822 | errx(1, "getaddrinfo: %s", gai_strerror(error)); | 826 | errx(1, "getaddrinfo: %s", gai_strerror(error)); |
| @@ -855,7 +859,9 @@ remote_connect(const char *host, const char *port, struct addrinfo hints) | |||
| 855 | warn("connect to %s port %s (%s) failed", host, port, | 859 | warn("connect to %s port %s (%s) failed", host, port, |
| 856 | uflag ? "udp" : "tcp"); | 860 | uflag ? "udp" : "tcp"); |
| 857 | 861 | ||
| 862 | save_errno = errno; | ||
| 858 | close(s); | 863 | close(s); |
| 864 | errno = save_errno; | ||
| 859 | s = -1; | 865 | s = -1; |
| 860 | } while ((res0 = res0->ai_next) != NULL); | 866 | } while ((res0 = res0->ai_next) != NULL); |
| 861 | 867 | ||
| @@ -901,7 +907,7 @@ int | |||
| 901 | local_listen(char *host, char *port, struct addrinfo hints) | 907 | local_listen(char *host, char *port, struct addrinfo hints) |
| 902 | { | 908 | { |
| 903 | struct addrinfo *res, *res0; | 909 | struct addrinfo *res, *res0; |
| 904 | int s, ret, x = 1; | 910 | int s, ret, x = 1, save_errno; |
| 905 | int error; | 911 | int error; |
| 906 | 912 | ||
| 907 | /* Allow nodename to be null. */ | 913 | /* Allow nodename to be null. */ |
| @@ -933,7 +939,9 @@ local_listen(char *host, char *port, struct addrinfo hints) | |||
| 933 | res0->ai_addrlen) == 0) | 939 | res0->ai_addrlen) == 0) |
| 934 | break; | 940 | break; |
| 935 | 941 | ||
| 942 | save_errno = errno; | ||
| 936 | close(s); | 943 | close(s); |
| 944 | errno = save_errno; | ||
| 937 | s = -1; | 945 | s = -1; |
| 938 | } while ((res0 = res0->ai_next) != NULL); | 946 | } while ((res0 = res0->ai_next) != NULL); |
| 939 | 947 | ||
