summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Longeau <chl@cvs.openbsd.org>2007-09-09 23:25:13 +0000
committerCharles Longeau <chl@cvs.openbsd.org>2007-09-09 23:25:13 +0000
commit24fb500a88aba3d8b27347c5c2ef4aec09e6be9b (patch)
tree6483a683be2cee8c1f4e6fc2b138dfc201e44180
parentec457499afee5477325a6450be1d3623832a7d6a (diff)
use strcspn to properly overwrite '\n' in fgets returned buffer
ok moritz@ gilles@
-rw-r--r--regress/lib/libc/regex/main.c4
-rw-r--r--regress/lib/libc/regex/split.c4
2 files changed, 4 insertions, 4 deletions
diff --git a/regress/lib/libc/regex/main.c b/regress/lib/libc/regex/main.c
index fd092905faf..15e0bc8c1f8 100644
--- a/regress/lib/libc/regex/main.c
+++ b/regress/lib/libc/regex/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.5 2004/02/28 08:06:46 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.6 2007/09/09 23:25:12 chl Exp $ */
/* $NetBSD: main.c,v 1.2 1995/04/20 22:39:51 cgd Exp $ */
#include <stdio.h>
@@ -147,7 +147,7 @@ FILE *in;
line++;
if (inbuf[0] == '#' || inbuf[0] == '\n')
continue; /* NOTE CONTINUE */
- inbuf[strlen(inbuf)-1] = '\0'; /* get rid of stupid \n */
+ inbuf[strcspn(inbuf, "\n")] = '\0'; /* get rid of stupid \n */
if (debug)
fprintf(stdout, "%d:\n", line);
nf = split(inbuf, f, MAXF, "\t\t");
diff --git a/regress/lib/libc/regex/split.c b/regress/lib/libc/regex/split.c
index f0f72c8b663..fcd81a35037 100644
--- a/regress/lib/libc/regex/split.c
+++ b/regress/lib/libc/regex/split.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: split.c,v 1.4 2004/02/28 08:06:47 deraadt Exp $ */
+/* $OpenBSD: split.c,v 1.5 2007/09/09 23:25:12 chl Exp $ */
/* $NetBSD: split.c,v 1.2 1995/04/20 22:39:57 cgd Exp $ */
#include <stdio.h>
@@ -171,7 +171,7 @@ char *argv[];
dosplit(argv[1], argv[2]);
else if (argc > 1)
while (fgets(buf, sizeof(buf), stdin) != NULL) {
- buf[strlen(buf)-1] = '\0'; /* stomp newline */
+ buf[strcspn(buf, "\n")] = '\0'; /* stomp newline */
dosplit(buf, argv[1]);
}
else