[Midnightbsd-cvs] src [10417] trunk/lib/libc/yp: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Tue Jun 5 17:49:03 EDT 2018


Revision: 10417
          http://svnweb.midnightbsd.org/src/?rev=10417
Author:   laffer1
Date:     2018-06-05 17:49:02 -0400 (Tue, 05 Jun 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/lib/libc/yp/xdryp.c
    trunk/lib/libc/yp/yplib.c

Modified: trunk/lib/libc/yp/xdryp.c
===================================================================
--- trunk/lib/libc/yp/xdryp.c	2018-06-05 21:41:55 UTC (rev 10416)
+++ trunk/lib/libc/yp/xdryp.c	2018-06-05 21:49:02 UTC (rev 10417)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1992/3 Theo de Raadt <deraadt at fsa.ca>
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/yp/xdryp.c,v 1.14 2002/04/28 15:18:47 des Exp $");
+__FBSDID("$FreeBSD: stable/10/lib/libc/yp/xdryp.c 228826 2011-12-23 01:56:25Z ghelmer $");
 
 #include <rpc/rpc.h>
 #include <rpcsvc/yp.h>
@@ -82,10 +83,21 @@
 		switch (status) {
 		case YP_TRUE:
 			key = (char *)malloc(out.ypresp_all_u.val.key.keydat_len + 1);
+			if (key == NULL) {
+				xdr_free((xdrproc_t)xdr_ypresp_all, &out);
+				*objp = YP_YPERR;
+				return (FALSE);
+			}
 			bcopy(out.ypresp_all_u.val.key.keydat_val, key,
 				out.ypresp_all_u.val.key.keydat_len);
 			key[out.ypresp_all_u.val.key.keydat_len] = '\0';
 			val = (char *)malloc(out.ypresp_all_u.val.val.valdat_len + 1);
+			if (val == NULL) {
+				free(key);
+				xdr_free((xdrproc_t)xdr_ypresp_all, &out);
+				*objp = YP_YPERR;
+				return (FALSE);
+			}
 			bcopy(out.ypresp_all_u.val.val.valdat_val, val,
 				out.ypresp_all_u.val.val.valdat_len);
 			val[out.ypresp_all_u.val.val.valdat_len] = '\0';

Modified: trunk/lib/libc/yp/yplib.c
===================================================================
--- trunk/lib/libc/yp/yplib.c	2018-06-05 21:41:55 UTC (rev 10416)
+++ trunk/lib/libc/yp/yplib.c	2018-06-05 21:49:02 UTC (rev 10417)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1992/3 Theo de Raadt <deraadt at fsa.ca>
  * Copyright (c) 1998 Bill Paul <wpaul at ctr.columbia.edu>
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/yp/yplib.c,v 1.51 2007/07/24 13:06:08 simon Exp $");
+__FBSDID("$FreeBSD: stable/10/lib/libc/yp/yplib.c 292547 2015-12-21 14:32:29Z araujo $");
 
 #include "namespace.h"
 #include "reentrant.h"
@@ -331,6 +332,8 @@
 
 	if (ysd == NULL) {
 		ysd = (struct dom_binding *)malloc(sizeof *ysd);
+		if (ysd == NULL)
+			return (YPERR_RESRC);
 		bzero((char *)ysd, sizeof *ysd);
 		ysd->dom_socket = -1;
 		ysd->dom_vers = 0;
@@ -373,7 +376,7 @@
 			ysd->dom_socket = -1;
 		}
 		snprintf(path, sizeof(path), "%s/%s.%d", BINDINGDIR, dom, 2);
-		if ((fd = _open(path, O_RDONLY)) == -1) {
+		if ((fd = _open(path, O_RDONLY | O_CLOEXEC)) == -1) {
 			/* no binding file, YP is dead. */
 			/* Try to bring it back to life. */
 			_close(fd);
@@ -653,7 +656,7 @@
 	struct timeval tv;
 	struct ypreq_key yprk;
 	int r;
-
+	int retries = 0;
 	*outval = NULL;
 	*outvallen = 0;
 
@@ -683,14 +686,26 @@
 */
 		*outvallen = yprv.val.valdat_len;
 		*outval = (char *)malloc(*outvallen+1);
+		if (*outval == NULL) {
+			_yp_unbind(ysd);
+			*outvallen = 0;
+			YPUNLOCK();
+			return (YPERR_RESRC);
+		}
 		bcopy(yprv.val.valdat_val, *outval, *outvallen);
 		(*outval)[*outvallen] = '\0';
 		YPUNLOCK();
 		return (0);
 	}
+	_yp_unbind(ysd);
 #endif
 
 again:
+	if (retries > MAX_RETRIES) {
+		YPUNLOCK();
+		return (YPERR_RPC);
+	}
+
 	if (_yp_dobind(indomain, &ysd) != 0) {
 		YPUNLOCK();
 		return (YPERR_DOMAIN);
@@ -707,6 +722,7 @@
 	if (r != RPC_SUCCESS) {
 		clnt_perror(ysd->dom_client, "yp_match: clnt_call");
 		_yp_unbind(ysd);
+		retries++;
 		goto again;
 	}
 
@@ -713,6 +729,13 @@
 	if (!(r = ypprot_err(yprv.stat))) {
 		*outvallen = yprv.val.valdat_len;
 		*outval = (char *)malloc(*outvallen+1);
+		if (*outval == NULL) {
+			_yp_unbind(ysd);
+			*outvallen = 0;
+			xdr_free((xdrproc_t)xdr_ypresp_val, &yprv);
+			YPUNLOCK();
+			return (YPERR_RESRC);
+		}
 		bcopy(yprv.val.valdat_val, *outval, *outvallen);
 		(*outval)[*outvallen] = '\0';
 #ifdef YPMATCHCACHE
@@ -756,7 +779,7 @@
 	struct dom_binding *ysd;
 	struct timeval tv;
 	int r;
-
+	int retries = 0;
 	/* Sanity check */
 
 	if (indomain == NULL || !strlen(indomain) ||
@@ -768,6 +791,11 @@
 
 	YPLOCK();
 again:
+	if (retries > MAX_RETRIES) {
+		YPUNLOCK();
+		return (YPERR_RPC);
+	}
+
 	if (_yp_dobind(indomain, &ysd) != 0) {
 		YPUNLOCK();
 		return (YPERR_DOMAIN);
@@ -786,15 +814,31 @@
 	if (r != RPC_SUCCESS) {
 		clnt_perror(ysd->dom_client, "yp_first: clnt_call");
 		_yp_unbind(ysd);
+		retries++;
 		goto again;
 	}
 	if (!(r = ypprot_err(yprkv.stat))) {
 		*outkeylen = yprkv.key.keydat_len;
 		*outkey = (char *)malloc(*outkeylen+1);
+		if (*outkey == NULL) {
+			_yp_unbind(ysd);
+			*outkeylen = 0;
+			xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv);
+			YPUNLOCK();
+			return (YPERR_RESRC);
+		}
 		bcopy(yprkv.key.keydat_val, *outkey, *outkeylen);
 		(*outkey)[*outkeylen] = '\0';
 		*outvallen = yprkv.val.valdat_len;
 		*outval = (char *)malloc(*outvallen+1);
+		if (*outval == NULL) {
+			free(*outkey);
+			_yp_unbind(ysd);
+			*outkeylen = *outvallen = 0;
+			xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv);
+			YPUNLOCK();
+			return (YPERR_RESRC);
+		}
 		bcopy(yprkv.val.valdat_val, *outval, *outvallen);
 		(*outval)[*outvallen] = '\0';
 	}
@@ -813,7 +857,7 @@
 	struct dom_binding *ysd;
 	struct timeval tv;
 	int r;
-
+	int retries = 0;
 	/* Sanity check */
 
 	if (inkey == NULL || !strlen(inkey) || inkeylen <= 0 ||
@@ -826,6 +870,11 @@
 
 	YPLOCK();
 again:
+	if (retries > MAX_RETRIES) {
+		YPUNLOCK();
+		return (YPERR_RPC);
+	}
+
 	if (_yp_dobind(indomain, &ysd) != 0) {
 		YPUNLOCK();
 		return (YPERR_DOMAIN);
@@ -846,15 +895,31 @@
 	if (r != RPC_SUCCESS) {
 		clnt_perror(ysd->dom_client, "yp_next: clnt_call");
 		_yp_unbind(ysd);
+		retries++;
 		goto again;
 	}
 	if (!(r = ypprot_err(yprkv.stat))) {
 		*outkeylen = yprkv.key.keydat_len;
 		*outkey = (char *)malloc(*outkeylen+1);
+		if (*outkey == NULL) {
+			_yp_unbind(ysd);
+			*outkeylen = 0;
+			xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv);
+			YPUNLOCK();
+			return (YPERR_RESRC);
+		}
 		bcopy(yprkv.key.keydat_val, *outkey, *outkeylen);
 		(*outkey)[*outkeylen] = '\0';
 		*outvallen = yprkv.val.valdat_len;
 		*outval = (char *)malloc(*outvallen+1);
+		if (*outval == NULL) {
+			free(*outkey);
+			_yp_unbind(ysd);
+			*outkeylen = *outvallen = 0;
+			xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv);
+			YPUNLOCK();
+			return (YPERR_RESRC);
+		}
 		bcopy(yprkv.val.valdat_val, *outval, *outvallen);
 		(*outval)[*outvallen] = '\0';
 	}
@@ -874,7 +939,7 @@
 	CLIENT *clnt;
 	u_long status, savstat;
 	int clnt_sock;
-
+	int retries = 0;
 	/* Sanity check */
 
 	if (indomain == NULL || !strlen(indomain) ||
@@ -883,6 +948,10 @@
 
 	YPLOCK();
 again:
+	if (retries > MAX_RETRIES) {
+		YPUNLOCK();
+		return (YPERR_RPC);
+	}
 
 	if (_yp_dobind(indomain, &ysd) != 0) {
 		YPUNLOCK();
@@ -912,9 +981,10 @@
 	if (clnt_call(clnt, YPPROC_ALL,
 		(xdrproc_t)xdr_ypreq_nokey, &yprnk,
 		(xdrproc_t)xdr_ypresp_all_seq, &status, tv) != RPC_SUCCESS) {
-			clnt_perror(ysd->dom_client, "yp_all: clnt_call");
+			clnt_perror(clnt, "yp_all: clnt_call");
 			clnt_destroy(clnt);
 			_yp_unbind(ysd);
+			retries++;
 			goto again;
 	}
 



More information about the Midnightbsd-cvs mailing list