From 63eb2ad70423829314bc396c95a9053f4a001eca Mon Sep 17 00:00:00 2001 From: Charles Longeau Date: Fri, 5 Oct 2007 14:29:47 +0000 Subject: 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@ --- usr.bin/file/apprentice.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'usr.bin/file') 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; } -- cgit v1.2.3