From 96409c9dfd1203843bd6895ba4c0f07cd41873f5 Mon Sep 17 00:00:00 2001 From: "Federico G. Schwindt" Date: Fri, 24 Sep 2004 19:45:28 +0000 Subject: save a copy of the pointer before strsep; fixes an abort on free. ok by millert, otto & pedro. --- usr.bin/which/which.c | 8 +++++--- 1 file 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 @@ -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 @@ -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 = "."; -- cgit v1.2.3