svn commit: r229938 - head/lib/libc/gen

Guy Helmer ghelmer at FreeBSD.org
Tue Jan 10 19:54:54 UTC 2012


Author: ghelmer
Date: Tue Jan 10 19:54:53 2012
New Revision: 229938
URL: http://svn.freebsd.org/changeset/base/229938

Log:
  Revert unintentional commit of changes to getnetgrent.c.

Modified:
  head/lib/libc/gen/getnetgrent.c

Modified: head/lib/libc/gen/getnetgrent.c
==============================================================================
--- head/lib/libc/gen/getnetgrent.c	Tue Jan 10 19:53:25 2012	(r229937)
+++ head/lib/libc/gen/getnetgrent.c	Tue Jan 10 19:54:53 2012	(r229938)
@@ -203,7 +203,9 @@ setnetgrent(const char *group)
 			if (parse_netgrp(group))
 				endnetgrent();
 			else {
-				grouphead.grname = strdup(group);
+				grouphead.grname = (char *)
+					malloc(strlen(group) + 1);
+				strcpy(grouphead.grname, group);
 			}
 			if (netf)
 				fclose(netf);
@@ -415,7 +417,7 @@ static int
 parse_netgrp(const char *group)
 {
 	char *spos, *epos;
-	int len, strpos, freepos;
+	int len, strpos;
 #ifdef DEBUG
 	int fields;
 #endif
@@ -452,9 +454,9 @@ parse_netgrp(const char *group)
 	while (pos != NULL && *pos != '\0') {
 		if (*pos == '(') {
 			grp = (struct netgrp *)malloc(sizeof (struct netgrp));
-			if (grp == NULL)
-				return(1);
 			bzero((char *)grp, sizeof (struct netgrp));
+			grp->ng_next = grouphead.gr;
+			grouphead.gr = grp;
 			pos++;
 			gpos = strsep(&pos, ")");
 #ifdef DEBUG
@@ -475,13 +477,6 @@ parse_netgrp(const char *group)
 					if (len > 0) {
 						grp->ng_str[strpos] =  (char *)
 							malloc(len + 1);
-						if (grp->ng_str[strpos] == NULL) {
-							for (freepos = 0; freepos < strpos; freepos++)
-								if (grp->ng_str[freepos] != NULL)
-									free(grp->ng_str[freepos]);
-							free(grp);
-							return(1);
-						}
 						bcopy(spos, grp->ng_str[strpos],
 							len + 1);
 					}
@@ -495,8 +490,6 @@ parse_netgrp(const char *group)
 					grp->ng_str[strpos] = NULL;
 				}
 			}
-			grp->ng_next = grouphead.gr;
-			grouphead.gr = grp;
 #ifdef DEBUG
 			/*
 			 * Note: on other platforms, malformed netgroup
@@ -533,7 +526,7 @@ parse_netgrp(const char *group)
 static struct linelist *
 read_for_group(const char *group)
 {
-	char *pos, *spos, *linep;
+	char *pos, *spos, *linep, *olinep;
 	int len, olen;
 	int cont;
 	struct linelist *lp;
@@ -541,7 +534,6 @@ read_for_group(const char *group)
 #ifdef YP
 	char *result;
 	int resultlen;
-	linep = NULL;
 
 	while (_netgr_yp_enabled || fgets(line, LINSIZ, netf) != NULL) {
 		if (_netgr_yp_enabled) {
@@ -562,7 +554,6 @@ read_for_group(const char *group)
 			free(result);
 		}
 #else
-	linep = NULL;
 	while (fgets(line, LINSIZ, netf) != NULL) {
 #endif
 		pos = (char *)&line;
@@ -585,14 +576,8 @@ read_for_group(const char *group)
 			pos++;
 		if (*pos != '\n' && *pos != '\0') {
 			lp = (struct linelist *)malloc(sizeof (*lp));
-			if (lp == NULL) 
-				return(NULL);
 			lp->l_parsed = 0;
 			lp->l_groupname = (char *)malloc(len + 1);
-			if (lp->l_groupname == NULL) {
-				free(lp);
-				return(NULL);
-			}
 			bcopy(spos, lp->l_groupname, len);
 			*(lp->l_groupname + len) = '\0';
 			len = strlen(pos);
@@ -610,15 +595,15 @@ read_for_group(const char *group)
 				} else
 					cont = 0;
 				if (len > 0) {
-					linep = (char *)reallocf(linep, olen + len + 1);
-					if (linep == NULL) {
-						free(lp->l_groupname);
-						free(lp);
-						return(NULL);
+					linep = (char *)malloc(olen + len + 1);
+					if (olen > 0) {
+						bcopy(olinep, linep, olen);
+						free(olinep);
 					}
 					bcopy(pos, linep + olen, len);
 					olen += len;
 					*(linep + olen) = '\0';
+					olinep = linep;
 				}
 				if (cont) {
 					if (fgets(line, LINSIZ, netf)) {
@@ -649,5 +634,5 @@ read_for_group(const char *group)
 	 */
 	rewind(netf);
 #endif
-	return (NULL);
+	return ((struct linelist *)0);
 }


More information about the svn-src-head mailing list