svn commit: trunk/busybox: e2fsprogs/old_e2fsprogs editors networki etc...

vda at busybox.net vda at busybox.net
Fri Mar 28 02:24:59 UTC 2008


Author: vda
Date: 2008-03-27 19:24:59 -0700 (Thu, 27 Mar 2008)
New Revision: 21524

Log:
fix a few stray unguarded strdup's



Modified:
   trunk/busybox/e2fsprogs/old_e2fsprogs/fsck.c
   trunk/busybox/editors/ed.c
   trunk/busybox/networking/httpd.c
   trunk/busybox/selinux/sestatus.c


Changeset:
Modified: trunk/busybox/e2fsprogs/old_e2fsprogs/fsck.c
===================================================================
--- trunk/busybox/e2fsprogs/old_e2fsprogs/fsck.c	2008-03-28 01:00:09 UTC (rev 21523)
+++ trunk/busybox/e2fsprogs/old_e2fsprogs/fsck.c	2008-03-28 02:24:59 UTC (rev 21524)
@@ -285,7 +285,7 @@
 
 	if (!s)
 		return 0;
-	ret = strdup(s);
+	ret = xstrdup(s);
 	return ret;
 }
 

Modified: trunk/busybox/editors/ed.c
===================================================================
--- trunk/busybox/editors/ed.c	2008-03-28 01:00:09 UTC (rev 21523)
+++ trunk/busybox/editors/ed.c	2008-03-28 02:24:59 UTC (rev 21524)
@@ -119,7 +119,7 @@
 static void doCommands(void)
 {
 	const char *cp;
-	char *endbuf, *newname, buf[USERSIZE];
+	char *endbuf, buf[USERSIZE];
 	int len, num1, num2;
 	smallint have1, have2;
 
@@ -168,162 +168,157 @@
 			num2 = num1;
 
 		switch (*cp++) {
-			case 'a':
-				addLines(num1 + 1);
-				break;
+		case 'a':
+			addLines(num1 + 1);
+			break;
 
-			case 'c':
-				deleteLines(num1, num2);
-				addLines(num1);
-				break;
+		case 'c':
+			deleteLines(num1, num2);
+			addLines(num1);
+			break;
 
-			case 'd':
-				deleteLines(num1, num2);
-				break;
+		case 'd':
+			deleteLines(num1, num2);
+			break;
 
-			case 'f':
-				if (*cp && !isblank(*cp)) {
-					bb_error_msg("bad file command");
-					break;
-				}
-				cp = skip_blank(cp);
-				if (*cp == '\0') {
-					if (fileName)
-						printf("\"%s\"\n", fileName);
-					else
-						printf("No file name\n");
-					break;
-				}
-				newname = strdup(cp);
-				if (newname == NULL) {
-					bb_error_msg("no memory for file name");
-					break;
-				}
-				free(fileName);
-				fileName = newname;
+		case 'f':
+			if (*cp && !isblank(*cp)) {
+				bb_error_msg("bad file command");
 				break;
-
-			case 'i':
-				addLines(num1);
+			}
+			cp = skip_blank(cp);
+			if (*cp == '\0') {
+				if (fileName)
+					printf("\"%s\"\n", fileName);
+				else
+					printf("No file name\n");
 				break;
+			}
+			free(fileName);
+			fileName = xstrdup(cp);
+			break;
 
-			case 'k':
-				cp = skip_blank(cp);
-				if ((*cp < 'a') || (*cp > 'z') || cp[1]) {
-					bb_error_msg("bad mark name");
-					break;
-				}
-				marks[*cp - 'a'] = num2;
-				break;
+		case 'i':
+			addLines(num1);
+			break;
 
-			case 'l':
-				printLines(num1, num2, TRUE);
+		case 'k':
+			cp = skip_blank(cp);
+			if ((*cp < 'a') || (*cp > 'z') || cp[1]) {
+				bb_error_msg("bad mark name");
 				break;
+			}
+			marks[*cp - 'a'] = num2;
+			break;
 
-			case 'p':
-				printLines(num1, num2, FALSE);
-				break;
+		case 'l':
+			printLines(num1, num2, TRUE);
+			break;
 
-			case 'q':
-				cp = skip_blank(cp);
-				if (have1 || *cp) {
-					bb_error_msg("bad quit command");
-					break;
-				}
-				if (!dirty)
-					return;
-				len = read_line_input("Really quit? ", buf, 16, NULL);
-				/* read error/EOF - no way to continue */
-				if (len < 0)
-					return;
-				cp = skip_blank(buf);
-				if ((*cp | 0x20) == 'y') /* Y or y */
-					return;
-				break;
+		case 'p':
+			printLines(num1, num2, FALSE);
+			break;
 
-			case 'r':
-				if (*cp && !isblank(*cp)) {
-					bb_error_msg("bad read command");
-					break;
-				}
-				cp = skip_blank(cp);
-				if (*cp == '\0') {
-					bb_error_msg("no file name");
-					break;
-				}
-				if (!have1)
-					num1 = lastNum;
-				if (readLines(cp, num1 + 1))
-					break;
-				if (fileName == NULL)
-					fileName = strdup(cp);
+		case 'q':
+			cp = skip_blank(cp);
+			if (have1 || *cp) {
+				bb_error_msg("bad quit command");
 				break;
+			}
+			if (!dirty)
+				return;
+			len = read_line_input("Really quit? ", buf, 16, NULL);
+			/* read error/EOF - no way to continue */
+			if (len < 0)
+				return;
+			cp = skip_blank(buf);
+			if ((*cp | 0x20) == 'y') /* Y or y */
+				return;
+			break;
 
-			case 's':
-				subCommand(cp, num1, num2);
+		case 'r':
+			if (*cp && !isblank(*cp)) {
+				bb_error_msg("bad read command");
 				break;
-
-			case 'w':
-				if (*cp && !isblank(*cp)) {
-					bb_error_msg("bad write command");
-					break;
-				}
-				cp = skip_blank(cp);
-				if (!have1) {
-					num1 = 1;
-					num2 = lastNum;
-				}
-				if (*cp == '\0')
-					cp = fileName;
-				if (cp == NULL) {
-					bb_error_msg("no file name specified");
-					break;
-				}
-				writeLines(cp, num1, num2);
+			}
+			cp = skip_blank(cp);
+			if (*cp == '\0') {
+				bb_error_msg("no file name");
 				break;
-
-			case 'z':
-				switch (*cp) {
-				case '-':
-					printLines(curNum - 21, curNum, FALSE);
-					break;
-				case '.':
-					printLines(curNum - 11, curNum + 10, FALSE);
-					break;
-				default:
-					printLines(curNum, curNum + 21, FALSE);
-					break;
-				}
+			}
+			if (!have1)
+				num1 = lastNum;
+			if (readLines(cp, num1 + 1))
 				break;
+			if (fileName == NULL)
+				fileName = xstrdup(cp);
+			break;
 
-			case '.':
-				if (have1) {
-					bb_error_msg("no arguments allowed");
-					break;
-				}
-				printLines(curNum, curNum, FALSE);
+		case 's':
+			subCommand(cp, num1, num2);
+			break;
+
+		case 'w':
+			if (*cp && !isblank(*cp)) {
+				bb_error_msg("bad write command");
 				break;
+			}
+			cp = skip_blank(cp);
+			if (!have1) {
+				num1 = 1;
+				num2 = lastNum;
+			}
+			if (*cp == '\0')
+				cp = fileName;
+			if (cp == NULL) {
+				bb_error_msg("no file name specified");
+				break;
+			}
+			writeLines(cp, num1, num2);
+			break;
 
+		case 'z':
+			switch (*cp) {
 			case '-':
-				if (setCurNum(curNum - 1))
-					printLines(curNum, curNum, FALSE);
+				printLines(curNum - 21, curNum, FALSE);
 				break;
-
-			case '=':
-				printf("%d\n", num1);
+			case '.':
+				printLines(curNum - 11, curNum + 10, FALSE);
 				break;
-			case '\0':
-				if (have1) {
-					printLines(num2, num2, FALSE);
-					break;
-				}
-				if (setCurNum(curNum + 1))
-					printLines(curNum, curNum, FALSE);
+			default:
+				printLines(curNum, curNum + 21, FALSE);
 				break;
+			}
+			break;
 
-			default:
-				bb_error_msg("unimplemented command");
+		case '.':
+			if (have1) {
+				bb_error_msg("no arguments allowed");
 				break;
+			}
+			printLines(curNum, curNum, FALSE);
+			break;
+
+		case '-':
+			if (setCurNum(curNum - 1))
+				printLines(curNum, curNum, FALSE);
+			break;
+
+		case '=':
+			printf("%d\n", num1);
+			break;
+		case '\0':
+			if (have1) {
+				printLines(num2, num2, FALSE);
+				break;
+			}
+			if (setCurNum(curNum + 1))
+				printLines(curNum, curNum, FALSE);
+			break;
+
+		default:
+			bb_error_msg("unimplemented command");
+			break;
 		}
 	}
 }

Modified: trunk/busybox/networking/httpd.c
===================================================================
--- trunk/busybox/networking/httpd.c	2008-03-28 01:00:09 UTC (rev 21523)
+++ trunk/busybox/networking/httpd.c	2008-03-28 02:24:59 UTC (rev 21524)
@@ -800,7 +800,7 @@
 /*
  * Given a URL encoded string, convert it to plain ascii.
  * Since decoding always makes strings smaller, the decode is done in-place.
- * Thus, callers should strdup() the argument if they do not want the
+ * Thus, callers should xstrdup() the argument if they do not want the
  * argument modified.  The return is the original pointer, allowing this
  * function to be easily used as arguments to other functions.
  *
@@ -1725,9 +1725,7 @@
 
 			if (strcmp(p, request) == 0) {
  set_remoteuser_var:
-				remoteuser = strdup(request);
-				if (remoteuser)
-					remoteuser[u - request] = '\0';
+				remoteuser = xstrndup(request, u - request);
 				return 1;   /* Ok */
 			}
 			/* unauthorized */
@@ -1990,13 +1988,13 @@
 #endif
 #if ENABLE_FEATURE_HTTPD_CGI
 			else if (STRNCASECMP(iobuf, "Cookie:") == 0) {
-				cookie = strdup(skip_whitespace(iobuf + sizeof("Cookie:")-1));
+				cookie = xstrdup(skip_whitespace(iobuf + sizeof("Cookie:")-1));
 			} else if (STRNCASECMP(iobuf, "Content-Type:") == 0) {
-				content_type = strdup(skip_whitespace(iobuf + sizeof("Content-Type:")-1));
+				content_type = xstrdup(skip_whitespace(iobuf + sizeof("Content-Type:")-1));
 			} else if (STRNCASECMP(iobuf, "Referer:") == 0) {
-				referer = strdup(skip_whitespace(iobuf + sizeof("Referer:")-1));
+				referer = xstrdup(skip_whitespace(iobuf + sizeof("Referer:")-1));
 			} else if (STRNCASECMP(iobuf, "User-Agent:") == 0) {
-				user_agent = strdup(skip_whitespace(iobuf + sizeof("User-Agent:")-1));
+				user_agent = xstrdup(skip_whitespace(iobuf + sizeof("User-Agent:")-1));
 			}
 #endif
 #if ENABLE_FEATURE_HTTPD_BASIC_AUTH
@@ -2377,7 +2375,7 @@
 	 * Besides, it is also smaller. */
 	{
 		char *p = getenv("PATH");
-		/* env strings themself are not freed, no need to strdup(p): */
+		/* env strings themself are not freed, no need to xstrdup(p): */
 		clearenv();
 		if (p)
 			putenv(p - 5);

Modified: trunk/busybox/selinux/sestatus.c
===================================================================
--- trunk/busybox/selinux/sestatus.c	2008-03-28 01:00:09 UTC (rev 21523)
+++ trunk/busybox/selinux/sestatus.c	2008-03-28 02:24:59 UTC (rev 21524)
@@ -78,10 +78,10 @@
 			section = 2;
 		} else {
 			if (section == 1 && pc_ofs < npc -1) {
-				pc[pc_ofs++] = strdup(buf);
+				pc[pc_ofs++] = xstrdup(buf);
 				pc[pc_ofs] = NULL;
 			} else if (section == 2 && fc_ofs < nfc - 1) {
-				fc[fc_ofs++] = strdup(buf);
+				fc[fc_ofs++] = xstrdup(buf);
 				fc[fc_ofs] = NULL;
 			}
 		}




More information about the busybox-cvs mailing list