diff options
author | Charles Longeau <chl@cvs.openbsd.org> | 2007-10-05 14:29:47 +0000 |
---|---|---|
committer | Charles Longeau <chl@cvs.openbsd.org> | 2007-10-05 14:29:47 +0000 |
commit | 63eb2ad70423829314bc396c95a9053f4a001eca (patch) | |
tree | e9ba4938cc05c19e68bc11a1d0207635c085e986 /usr.bin/file | |
parent | ef79351c024045b58ccfe7d2e2b3958b47d296ad (diff) |
use strcspn instead of strchr to properly overwrite '\n' in fgets returned buffer
check if the first byte is NUL instead of invoking strlen()
with help of ray@ "Looks OK" millert@
Diffstat (limited to 'usr.bin/file')
-rw-r--r-- | usr.bin/file/apprentice.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/usr.bin/file/apprentice.c b/usr.bin/file/apprentice.c index afb905b11de..73fdab7f1cf 100644 --- a/usr.bin/file/apprentice.c +++ b/usr.bin/file/apprentice.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apprentice.c,v 1.23 2006/10/31 18:06:27 ray Exp $ */ +/* $OpenBSD: apprentice.c,v 1.24 2007/10/05 14:29:46 chl 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.23 2006/10/31 18:06:27 ray Exp $") +FILE_RCSID("@(#)$Id: apprentice.c,v 1.24 2007/10/05 14:29:46 chl Exp $") #endif /* lint */ #define EATAB {while (isascii((unsigned char) *l) && \ @@ -311,15 +311,12 @@ 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; /* delete newline */ - if ((p = strchr(line, '\n')) != NULL) - *p = '\0'; + line[strcspn(line, "\n")] = '\0'; + if (line[0] == '\0') + continue; if (parse(ms, magicp, nmagicp, line, action) != 0) errs = 1; } |