From a8ba60ecf20c221bd24ff666339eb5edcbbbac33 Mon Sep 17 00:00:00 2001 From: Gilles Chehade Date: Tue, 11 Sep 2007 15:47:18 +0000 Subject: use strcspn to properly overwrite '\n' in fgets returned buffer ok pyr@, ray@, millert@, moritz@, chl@ --- usr.bin/vi/common/recover.c | 5 ++--- usr.bin/vi/ex/ex_cscope.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'usr.bin/vi') 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); } -- cgit v1.2.3