From e2402ad019ff01f5ebaf02ca14dc05f2921ac3d2 Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Tue, 31 Mar 2009 23:16:47 +0200 Subject: [PATCH] fixed possible SIGSEGV in listening addresses --- CHANGES | 5 +++++ VERSION | 2 +- xio-listen.c | 19 +++++++++++-------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index 4fe6ee3..cc249ba 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,9 @@ +corrections: + fixed possible SIGSEGV in listening addresses when a new connection was + reset by peer before the socket addresses could be retrieved. Thanks to + Mike Perry for sending a patch. + ####################### V 1.7.0.0: new features: diff --git a/VERSION b/VERSION index bd51149..a675ae8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -"1.7.0.0" +"1.7.0.0+segvonaccept" diff --git a/xio-listen.c b/xio-listen.c index a0f4759..cb885fe 100644 --- a/xio-listen.c +++ b/xio-listen.c @@ -1,5 +1,5 @@ /* source: xio-listen.c */ -/* Copyright Gerhard Rieger 2001-2008 */ +/* Copyright Gerhard Rieger 2001-2009 */ /* Published under the GNU General Public License V.2, see file COPYING */ /* this file contains the source for listen socket options */ @@ -254,8 +254,10 @@ int _xioopen_listen(struct single *xfd, int xioflags, struct sockaddr *us, sockl la = NULL; } Notice2("accepting connection from %s on %s", - sockaddr_info(pa?&pa->soa:NULL, pas, peername, sizeof(peername)), - sockaddr_info(pa?&la->soa:NULL, las, sockname, sizeof(sockname))); + pa? + sockaddr_info(&pa->soa, pas, peername, sizeof(peername)):"NULL", + la? + sockaddr_info(&la->soa, las, sockname, sizeof(sockname)):"NULL"); if (pa != NULL && la != NULL && xiocheckpeer(xfd, pa, la) < 0) { if (Shutdown(ps, 2) < 0) { @@ -264,9 +266,10 @@ int _xioopen_listen(struct single *xfd, int xioflags, struct sockaddr *us, sockl continue; } - Info1("permitting connection from %s", - sockaddr_info((struct sockaddr *)pa, pas, - infobuff, sizeof(infobuff))); + if (pa != NULL) + Info1("permitting connection from %s", + sockaddr_info((struct sockaddr *)pa, pas, + infobuff, sizeof(infobuff))); applyopts(xfd->fd, opts, PH_FD); applyopts(xfd->fd, opts, PH_CONNECTED); @@ -322,8 +325,8 @@ int _xioopen_listen(struct single *xfd, int xioflags, struct sockaddr *us, sockl return result; /* set the env vars describing the local and remote sockets */ - xiosetsockaddrenv("SOCK", la, las, proto); - xiosetsockaddrenv("PEER", pa, pas, proto); + if (la != NULL) xiosetsockaddrenv("SOCK", la, las, proto); + if (pa != NULL) xiosetsockaddrenv("PEER", pa, pas, proto); return 0; }