Loading...
sys/posix_spawn.c Libc-1583.0.14 Libc-997.90.3
--- Libc/Libc-1583.0.14/sys/posix_spawn.c
+++ Libc/Libc-997.90.3/sys/posix_spawn.c
@@ -89,7 +89,7 @@
 		env_path = _PATH_DEFPATH;
 
 	/* If it's an absolute or relative path name, it's easy. */
-	if (strchr(file, '/')) {
+	if (index(file, '/')) {
 		bp = (char *)file;
 		cur = NULL;
 		goto retry;
@@ -144,28 +144,14 @@
 		case ENOEXEC:
 			for (cnt = 0; argv[cnt]; ++cnt)
 				;
-
-			/*
-			 * cnt may be 0 above; always allocate at least
-			 * 3 entries so that we can at least fit "sh", bp, and
-			 * the NULL terminator.  We can rely on cnt to take into
-			 * account the NULL terminator in all other scenarios,
-			 * as we drop argv[0].
-			 */
-			memp = alloca(MAX(3, cnt + 2) * sizeof(char *));
+			memp = alloca((cnt + 2) * sizeof(char *));
 			if (memp == NULL) {
 				/* errno = ENOMEM; XXX override ENOEXEC? */
 				goto done;
 			}
-			if (cnt > 0) {
-				memp[0] = argv[0];
-				memp[1] = bp;
-				bcopy(argv + 1, memp + 2, cnt * sizeof(char *));
-			} else {
-				memp[0] = "sh";
-				memp[1] = bp;
-				memp[2] = NULL;
-			}
+			memp[0] = "sh";
+			memp[1] = bp;
+			bcopy(argv + 1, memp + 2, cnt * sizeof(char *));
 			err = posix_spawn(pid, _PATH_BSHELL, file_actions, attrp, memp, envp);
 			goto done;
 		default: