Ping tech@, Could anyone spare a minute to check this patch? I think it is indeed a bug.
On 9/4/2018 1:01 PM, Nan Xiao wrote: > Hi tech@, > > Before netcat program exits, it will check whether s is -1, and close > socket if s is not -1: > > if (s != -1) > close(s); > > The following patch fixes the issue that netcat will close socket twice > if it works as a server: > > Index: netcat.c > =================================================================== > RCS file: /cvs/src/usr.bin/nc/netcat.c,v > retrieving revision 1.192 > diff -u -p -r1.192 netcat.c > --- netcat.c 10 Aug 2018 17:15:22 -0000 1.192 > +++ netcat.c 4 Sep 2018 04:51:55 -0000 > @@ -622,9 +622,10 @@ main(int argc, char *argv[]) > } > close(connfd); > } > - if (family != AF_UNIX) > + if (family != AF_UNIX) { > close(s); > - else if (uflag) { > + s = -1; > + } else if (uflag) { > if (connect(s, NULL, 0) < 0) > err(1, "connect"); > } > > Thanks! > -- Best Regards Nan Xiao(肖楠)