Module Name:    src
Committed By:   christos
Date:           Tue Nov 10 18:01:16 UTC 2015

Modified Files:
        src/lib/libc/rpc: rpc_soc.c

Log Message:
CID 1338513: Check listen(2) return


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/rpc/rpc_soc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/rpc/rpc_soc.c
diff -u src/lib/libc/rpc/rpc_soc.c:1.19 src/lib/libc/rpc/rpc_soc.c:1.20
--- src/lib/libc/rpc/rpc_soc.c:1.19	Wed May 28 10:45:57 2014
+++ src/lib/libc/rpc/rpc_soc.c	Tue Nov 10 13:01:16 2015
@@ -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 @@ svc_com_create(int fd, u_int sendsize, u
 	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 *

Reply via email to