diff options
author | Kjell Wooding <kjell@cvs.openbsd.org> | 2005-11-13 07:24:49 +0000 |
---|---|---|
committer | Kjell Wooding <kjell@cvs.openbsd.org> | 2005-11-13 07:24:49 +0000 |
commit | 0b920c10aaeca5cf4123fd2f6554fee361e8d7df (patch) | |
tree | 04365634f9a339baeabd9d811166b5906fd0488d /usr.bin | |
parent | 4c2b8da344a12939eb3c0ab0bd2f939428ab2ebd (diff) |
Copy buffer before handing it to basename().
Inspired by a patch from Han Boetes.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mg/file.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c index 3227257e6f0..8aee558914d 100644 --- a/usr.bin/mg/file.c +++ b/usr.bin/mg/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.43 2005/10/14 19:46:46 kjell Exp $ */ +/* $OpenBSD: file.c,v 1.44 2005/11/13 07:24:48 kjell Exp $ */ /* This file is in the public domain. */ @@ -177,19 +177,24 @@ poptofile(int f, int n) * empty buffer to put it in. */ BUFFER * -findbuffer(char *fname) +findbuffer(char *fn) { BUFFER *bp; - char bname[NBUFN]; + char bname[NBUFN], fname[NBUFN]; unsigned int count, remain, i; + if (strlcpy(fname, fn, sizeof(fname)) >= sizeof(fname)) { + ewprintf("filename too long"); + return (NULL); + } + for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { if (strcmp(bp->b_fname, fname) == 0) return (bp); } i = strlcpy(bname, basename(fname), sizeof(bname)); if (i >= sizeof(bname)) - return NULL; + return (NULL); remain = sizeof(bname) - i; for (count = 2; bfind(bname, FALSE) != NULL; count++) snprintf(&bname[i], remain, "<%d>", count); |