Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/rpc CID 1338513: Check listen(2) return



details:   https://anonhg.NetBSD.org/src/rev/b9a9727adaa0
branches:  trunk
changeset: 341527:b9a9727adaa0
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Nov 10 18:01:16 2015 +0000

description:
CID 1338513: Check listen(2) return

diffstat:

 lib/libc/rpc/rpc_soc.c |  19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diffs (45 lines):

diff -r d51adf624730 -r b9a9727adaa0 lib/libc/rpc/rpc_soc.c
--- a/lib/libc/rpc/rpc_soc.c    Tue Nov 10 17:59:37 2015 +0000
+++ b/lib/libc/rpc/rpc_soc.c    Tue Nov 10 18:01:16 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rpc_soc.c,v 1.19 2014/05/28 14:45:57 christos Exp $    */
+/*     $NetBSD: rpc_soc.c,v 1.20 2015/11/10 18:01:16 christos Exp $    */
 
 /*
  * Copyright (c) 2010, Oracle America, Inc.
@@ -45,7 +45,7 @@
 #if 0
 static char sccsid[] = "@(#)rpc_soc.c 1.41 89/05/02 Copyr 1988 Sun Micro";
 #else
-__RCSID("$NetBSD: rpc_soc.c,v 1.19 2014/05/28 14:45:57 christos Exp $");
+__RCSID("$NetBSD: rpc_soc.c,v 1.20 2015/11/10 18:01:16 christos Exp $");
 #endif
 #endif
 
@@ -255,17 +255,20 @@
        memset(&sccsin, 0, sizeof sccsin);
        sccsin.sin_family = AF_INET;
        (void)bindresvport(fd, &sccsin);
-       listen(fd, SOMAXCONN);
+       if (listen(fd, SOMAXCONN) == -1)
+               goto out;
        svc = svc_tli_create(fd, nconf, NULL, sendsize, recvsize);
        (void) freenetconfigent(nconf);
-       if (svc == NULL) {
-               if (madefd)
-                       (void) close(fd);
-               return (NULL);
+       if (svc == NULL)
+               goto out;
        }
        port = (((struct sockaddr_in *)svc->xp_ltaddr.buf)->sin_port);
        svc->xp_port = ntohs(port);
-       return (svc);
+       return svc;
+out:
+       if (madefd)
+               (void) close(fd);
+       return NULL;
 }
 
 SVCXPRT *



Home | Main Index | Thread Index | Old Index