summaryrefslogtreecommitdiff
path: root/usr.bin/file
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2007-09-11 15:47:18 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2007-09-11 15:47:18 +0000
commita8ba60ecf20c221bd24ff666339eb5edcbbbac33 (patch)
tree650532cc79cb8294b5e7739a5b61676601594950 /usr.bin/file
parentd0c98e555e46b02b8df61047ae1c820859b23e93 (diff)
use strcspn to properly overwrite '\n' in fgets returned buffer
ok pyr@, ray@, millert@, moritz@, chl@
Diffstat (limited to 'usr.bin/file')
-rw-r--r--usr.bin/file/print.c7
-rw-r--r--usr.bin/file/softmagic.c11
2 files changed, 7 insertions, 11 deletions
diff --git a/usr.bin/file/print.c b/usr.bin/file/print.c
index 9b172d37a06..1271370d843 100644
--- a/usr.bin/file/print.c
+++ b/usr.bin/file/print.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print.c,v 1.11 2004/05/19 02:32:35 tedu Exp $ */
+/* $OpenBSD: print.c,v 1.12 2007/09/11 15:47:17 gilles Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -42,7 +42,7 @@
#include <time.h>
#ifndef lint
-FILE_RCSID("@(#)$Id: print.c,v 1.11 2004/05/19 02:32:35 tedu Exp $")
+FILE_RCSID("@(#)$Id: print.c,v 1.12 2007/09/11 15:47:17 gilles Exp $")
#endif /* lint */
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
@@ -181,7 +181,6 @@ file_fmttime(uint32_t v, int local)
pp = asctime(tm);
}
- if ((rt = strchr(pp, '\n')) != NULL)
- *rt = '\0';
+ pp[strcspn(pp, "\n")] = '\0';
return pp;
}
diff --git a/usr.bin/file/softmagic.c b/usr.bin/file/softmagic.c
index fda453a1ec9..4c9ecc9a09b 100644
--- a/usr.bin/file/softmagic.c
+++ b/usr.bin/file/softmagic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softmagic.c,v 1.11 2004/05/19 02:32:36 tedu Exp $ */
+/* $OpenBSD: softmagic.c,v 1.12 2007/09/11 15:47:17 gilles Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -40,7 +40,7 @@
#ifndef lint
-FILE_RCSID("@(#)$Id: softmagic.c,v 1.11 2004/05/19 02:32:36 tedu Exp $")
+FILE_RCSID("@(#)$Id: softmagic.c,v 1.12 2007/09/11 15:47:17 gilles Exp $")
#endif /* lint */
private int match(struct magic_set *, struct magic *, uint32_t,
@@ -278,11 +278,8 @@ mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
t = m->offset + strlen(m->value.s);
}
else {
- if (*m->value.s == '\0') {
- char *cp = strchr(p->s,'\n');
- if (cp)
- *cp = '\0';
- }
+ if (*m->value.s == '\0')
+ p->s[strcspn(p->s, "\n")] = '\0';
if (file_printf(ms, m->desc, p->s) == -1)
return -1;
t = m->offset + strlen(p->s);