summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/mg/file.c13
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);