[BusyBox-cvs] busybox/networking inetd.c,1.19,1.20

Glenn McGrath bug1 at busybox.net
Sun Feb 22 11:25:15 UTC 2004


Update of /var/cvs/busybox/networking
In directory nail:/tmp/cvs-serv2414/networking

Modified Files:
	inetd.c 
Log Message:
Patch from Vodz, cleanup memory usage, send strdup error messages to 
syslog.


Index: inetd.c
===================================================================
RCS file: /var/cvs/busybox/networking/inetd.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- a/inetd.c	22 Feb 2004 04:58:36 -0000	1.19
+++ b/inetd.c	22 Feb 2004 11:25:13 -0000	1.20
@@ -279,6 +279,16 @@
 	_exit(1);
 }
 
+static char * inetd_strdup(const char *s)
+{
+	char *ms = strdup(s);
+
+	if(ms == NULL)
+		syslog_err_and_discard_dg(SOCK_STREAM, "strdup: %m");
+	return ms;
+}
+
+
 static servtab_t *getconfigent(void)
 {
 	static servtab_t serv;
@@ -298,13 +308,15 @@
 	if ((cp == NULL) || (*cp == '#')) {
 		goto more;
 	}
+	/* make bind 0.0.0.0 and other zero default */
+	memset((char *)sep, 0, sizeof *sep);
 
 	cp_ptr = strtok_r(cp, " \t", &cp_ptr_ptr);
 	if (cp_ptr == NULL) {
 		/* Error */
 		goto more;
 	}
-	sep->se_service = bb_xstrdup(cp_ptr);
+	sep->se_service = inetd_strdup(cp_ptr);
 
 	cp_ptr = strtok_r(NULL, " \t", &cp_ptr_ptr);
 	if (cp_ptr == NULL) {
@@ -339,7 +351,7 @@
 		}
 		sep->se_family = AF_INET;
 	}
-	sep->se_proto = bb_xstrdup(cp_ptr);
+	sep->se_proto = inetd_strdup(cp_ptr);
 
 	cp_ptr = strtok_r(NULL, " \t", &cp_ptr_ptr);
 	if (cp_ptr == NULL) {
@@ -361,14 +373,16 @@
 		/* error */
 		goto more;
 	}
+
+	sep->se_user = inetd_strdup(cp_ptr);
 	{
-		char *cp_ptr2 = strchr(cp_ptr, '.');
+		char *cp_ptr2 = strchr(sep->se_user, '.');
+
 		if (cp_ptr2) {
 			*cp_ptr2++ = '\0';
-			sep->se_group = bb_xstrdup(cp_ptr2);
 		}
+		sep->se_group = cp_ptr2;
 	}
-	sep->se_user = bb_xstrdup(cp_ptr);
 
 	cp_ptr = strtok_r(NULL, " \t", &cp_ptr_ptr);
 	if (cp_ptr == NULL) {
@@ -401,19 +415,16 @@
 		sep->se_bi = NULL;
 	}
 #endif
-	sep->se_server = bb_xstrdup(cp_ptr);
+	sep->se_server = inetd_strdup(cp_ptr);
 
 	argc = 0;
 	while ((cp_ptr = strtok_r(NULL, " \t", &cp_ptr_ptr)) != NULL) {
 		if (argc < MAXARGV) {
-			sep->se_argv[argc++] = cp_ptr;
+			sep->se_argv[argc++] = inetd_strdup(cp_ptr);
 		}
 	}
-	while (argc <= MAXARGV) {
-		sep->se_argv[argc++] = NULL;
-	}
+	free(cp);
 
-	//free(cp);	// BUG: cp is the argv[] container; we must not free it here!
 	return (sep);
 }
 




More information about the busybox-cvs mailing list