summaryrefslogtreecommitdiff
path: root/usr.bin/vi
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2007-09-11 15:47:18 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2007-09-11 15:47:18 +0000
commita8ba60ecf20c221bd24ff666339eb5edcbbbac33 (patch)
tree650532cc79cb8294b5e7739a5b61676601594950 /usr.bin/vi
parentd0c98e555e46b02b8df61047ae1c820859b23e93 (diff)
use strcspn to properly overwrite '\n' in fgets returned buffer
ok pyr@, ray@, millert@, moritz@, chl@
Diffstat (limited to 'usr.bin/vi')
-rw-r--r--usr.bin/vi/common/recover.c5
-rw-r--r--usr.bin/vi/ex/ex_cscope.c5
2 files changed, 4 insertions, 6 deletions
diff --git a/usr.bin/vi/common/recover.c b/usr.bin/vi/common/recover.c
index c47f7809464..6d4655d486c 100644
--- a/usr.bin/vi/common/recover.c
+++ b/usr.bin/vi/common/recover.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: recover.c,v 1.11 2006/12/11 20:50:55 deraadt Exp $ */
+/* $OpenBSD: recover.c,v 1.12 2007/09/11 15:47:17 gilles Exp $ */
/*-
* Copyright (c) 1993, 1994
@@ -817,8 +817,7 @@ rcv_gets(buf, len, fd)
if ((nr = read(fd, buf, len - 1)) == -1)
return (NULL);
buf[nr] = '\0';
- if ((p = strchr(buf, '\n')) == NULL)
- return (NULL);
+ buf[strcspn(buf, "\n")] = '\0';
(void)lseek(fd, (off_t)((p - buf) + 1), SEEK_SET);
return (buf);
}
diff --git a/usr.bin/vi/ex/ex_cscope.c b/usr.bin/vi/ex/ex_cscope.c
index 7bd12194599..dc7a66de5b2 100644
--- a/usr.bin/vi/ex/ex_cscope.c
+++ b/usr.bin/vi/ex/ex_cscope.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ex_cscope.c,v 1.13 2007/03/20 03:56:13 tedu Exp $ */
+/* $OpenBSD: ex_cscope.c,v 1.14 2007/09/11 15:47:17 gilles Exp $ */
/*-
* Copyright (c) 1994, 1996
@@ -675,8 +675,7 @@ parse(sp, csc, tqp, matchesp)
#define CSCOPE_NLINES_FMT "cscope: %d lines%1[\n]"
if (sscanf(buf, CSCOPE_NLINES_FMT, &nlines, dummy) == 2)
break;
- if ((p = strchr(buf, '\n')) != NULL)
- *p = '\0';
+ buf[strcspn(buf, "\n")] = '\0';
msgq(sp, M_ERR, "%s: \"%s\"", csc->dname, buf);
}