diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2020-01-06 15:19:13 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2020-01-06 15:19:13 +0000 |
commit | ffc395c45c93c0f261661096f208a3aac4dbdc25 (patch) | |
tree | d274ce724e16d49e87c6c8a73df09361c3159baf | |
parent | 33b733b474a2ec9fe28274318271d04e5000373c (diff) |
When using UNIX domain sockets, always call report_sock() with the
path name of the socket. This avoids bad errors from getnameinfo(3).
Use the same error check for both calls to getnameinfo(3).
OK millert@ tb@
-rw-r--r-- | usr.bin/nc/netcat.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c index 051daf18118..4ff935c58ef 100644 --- a/usr.bin/nc/netcat.c +++ b/usr.bin/nc/netcat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netcat.c,v 1.212 2019/11/17 17:38:33 deraadt Exp $ */ +/* $OpenBSD: netcat.c,v 1.213 2020/01/06 15:19:12 bluhm Exp $ */ /* * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> * Copyright (c) 2015 Bob Beck. All rights reserved. @@ -597,7 +597,8 @@ main(int argc, char *argv[]) if (vflag) report_sock("Connection received", - (struct sockaddr *)&z, len, NULL); + (struct sockaddr *)&z, len, + family == AF_UNIX ? host : NULL); readwrite(s, NULL); } else { @@ -1784,11 +1785,14 @@ report_sock(const char *msg, const struct sockaddr *sa, socklen_t salen, if (nflag) flags |= NI_NUMERICHOST; - if ((herr = getnameinfo(sa, salen, host, sizeof(host), - port, sizeof(port), flags)) != 0) { - if (herr == EAI_SYSTEM) + herr = getnameinfo(sa, salen, host, sizeof(host), port, sizeof(port), + flags); + switch (herr) { + case 0: + break; + case EAI_SYSTEM: err(1, "getnameinfo"); - else + default: errx(1, "getnameinfo: %s", gai_strerror(herr)); } |