diff options
author | Bob Beck <beck@cvs.openbsd.org> | 2005-04-21 19:16:22 +0000 |
---|---|---|
committer | Bob Beck <beck@cvs.openbsd.org> | 2005-04-21 19:16:22 +0000 |
commit | d416f9cf49cf12282f57475762b7d13b7cdc5da3 (patch) | |
tree | f5935ed11d250996f6e3e4f83ffa873e6d21dcdc | |
parent | be9305853eb2aa58ebc34359721c1cfac0be0bad (diff) |
correct strlcpy abuse, and always check for NULL return from find_buffer
ok cloder@, feedback from many
-rw-r--r-- | usr.bin/mg/file.c | 4 | ||||
-rw-r--r-- | usr.bin/mg/main.c | 7 |
2 files changed, 8 insertions, 3 deletions
diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c index 5a168644f0a..69dfd6d7159 100644 --- a/usr.bin/mg/file.c +++ b/usr.bin/mg/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.32 2005/04/03 02:09:28 db Exp $ */ +/* $OpenBSD: file.c,v 1.33 2005/04/21 19:16:21 beck Exp $ */ /* * File commands. @@ -128,6 +128,8 @@ findbuffer(char *fname) return (bp); } i = strlcpy(bname, basename(fname), sizeof(bname)); + if (i >= sizeof(bname)) + return NULL; remain = sizeof(bname) - i; for (count = 2; bfind(bname, FALSE) != NULL; count++) snprintf(&bname[i], remain, "<%d>", count); diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c index e7ca3f6897c..e2e4014519e 100644 --- a/usr.bin/mg/main.c +++ b/usr.bin/mg/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.38 2005/04/03 02:09:28 db Exp $ */ +/* $OpenBSD: main.c,v 1.39 2005/04/21 19:16:21 beck Exp $ */ /* * Mainline. @@ -110,7 +110,10 @@ notnum: if (nfiles == 1) splitwind(0, 1); - curbp = findbuffer(cp); + if ((curbp = findbuffer(cp)) == NULL) { + vttidy(); + errx(1, "Can't find current buffer!"); + } (void)showbuffer(curbp, curwp, 0); if ((status = readin(cp)) != TRUE) killbuffer(curbp); |