summaryrefslogtreecommitdiff
path: root/usr.bin/which/which.c
diff options
context:
space:
mode:
authorFederico G. Schwindt <fgsch@cvs.openbsd.org>2004-09-24 19:45:28 +0000
committerFederico G. Schwindt <fgsch@cvs.openbsd.org>2004-09-24 19:45:28 +0000
commit96409c9dfd1203843bd6895ba4c0f07cd41873f5 (patch)
treed5b589fb60efd91cf00c0f3f3edff76466453fc4 /usr.bin/which/which.c
parentb0dd70056b2e85a92c06334181b81845f20931ae (diff)
save a copy of the pointer before strsep; fixes an abort on free.
ok by millert, otto & pedro.
Diffstat (limited to 'usr.bin/which/which.c')
-rw-r--r--usr.bin/which/which.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/usr.bin/which/which.c b/usr.bin/which/which.c
index 8f478fd7393..d166c06ce9f 100644
--- a/usr.bin/which/which.c
+++ b/usr.bin/which/which.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: which.c,v 1.12 2004/09/23 17:44:47 millert Exp $ */
+/* $OpenBSD: which.c,v 1.13 2004/09/24 19:45:27 fgsch Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -17,7 +17,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: which.c,v 1.12 2004/09/23 17:44:47 millert Exp $";
+static const char rcsid[] = "$OpenBSD: which.c,v 1.13 2004/09/24 19:45:27 fgsch Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -115,6 +115,7 @@ findprog(char *prog, char *path, int progmode, int allmatches)
char *p, filename[MAXPATHLEN];
int proglen, plen, rval = 0;
struct stat sbuf;
+ char *pathcpy;
/* Special case if prog contains '/' */
if (strchr(prog, '/')) {
@@ -130,9 +131,10 @@ findprog(char *prog, char *path, int progmode, int allmatches)
if ((path = strdup(path)) == NULL)
errx(1, "Can't allocate memory.");
+ pathcpy = path;
proglen = strlen(prog);
- while ((p = strsep(&path, ":")) != NULL) {
+ while ((p = strsep(&pathcpy, ":")) != NULL) {
if (*p == '\0')
p = ".";