summaryrefslogtreecommitdiff
path: root/usr.bin/file
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2006-10-31 18:06:28 +0000
committerRay Lai <ray@cvs.openbsd.org>2006-10-31 18:06:28 +0000
commitd140c75c0152ba90454d4d8995dbd8ca306bf64f (patch)
tree2b8933faacf6ac9166d08555d17e02626c66e3ca /usr.bin/file
parentdcf6a48a9260f8b700d4ca5add2c7d561274f88b (diff)
Don't blindly truncate buf[strlen(buf) - 1] without checking for
newline. Initial patch from Charles Longeau <chl at tuxfamily dot org>, fix inspired by comment by Anonymous Coward on undeadly. OK moritz@, ian@.
Diffstat (limited to 'usr.bin/file')
-rw-r--r--usr.bin/file/apprentice.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/usr.bin/file/apprentice.c b/usr.bin/file/apprentice.c
index c88fb7ccdcb..afb905b11de 100644
--- a/usr.bin/file/apprentice.c
+++ b/usr.bin/file/apprentice.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apprentice.c,v 1.22 2006/04/04 14:17:01 pedro Exp $ */
+/* $OpenBSD: apprentice.c,v 1.23 2006/10/31 18:06:27 ray Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -46,7 +46,7 @@
#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: apprentice.c,v 1.22 2006/04/04 14:17:01 pedro Exp $")
+FILE_RCSID("@(#)$Id: apprentice.c,v 1.23 2006/10/31 18:06:27 ray Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
@@ -311,11 +311,15 @@ apprentice_file(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
/* parse it */
for (lineno = 1; fgets(line, sizeof(line), f) != NULL; lineno++) {
+ char *p;
+
if (line[0]=='#') /* comment, do not parse */
continue;
if (strlen(line) <= (unsigned)1) /* null line, garbage, etc */
continue;
- line[strlen(line)-1] = '\0'; /* delete newline */
+ /* delete newline */
+ if ((p = strchr(line, '\n')) != NULL)
+ *p = '\0';
if (parse(ms, magicp, nmagicp, line, action) != 0)
errs = 1;
}