summaryrefslogtreecommitdiffstats
path: root/usr.bin/file
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1997-10-04 01:03:28 +0000
committerache <ache@FreeBSD.org>1997-10-04 01:03:28 +0000
commit1d704478e47ba414979ce4f1e15b18075567e99a (patch)
tree480c866c4847fc467bc40b7dbf44cca4fdaf9368 /usr.bin/file
parent56229906e0a3ec61fa498490cba25cfd16578bbc (diff)
downloadFreeBSD-src-1d704478e47ba414979ce4f1e15b18075567e99a.zip
FreeBSD-src-1d704478e47ba414979ce4f1e15b18075567e99a.tar.gz
Check for invalid lower controls to not claim binary data with chars < 128 as
ASCII _text_ Cleanup names detection code
Diffstat (limited to 'usr.bin/file')
-rw-r--r--usr.bin/file/ascmagic.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/usr.bin/file/ascmagic.c b/usr.bin/file/ascmagic.c
index 52f5090..eed3998 100644
--- a/usr.bin/file/ascmagic.c
+++ b/usr.bin/file/ascmagic.c
@@ -36,7 +36,7 @@
#ifndef lint
static char *moduleid =
- "@(#)$Id: ascmagic.c,v 1.1.1.3 1997/03/18 17:58:46 mpp Exp $";
+ "@(#)$Id: ascmagic.c,v 1.7 1997/03/18 19:37:17 mpp Exp $";
#endif /* lint */
/* an optimisation over plain strcmp() */
@@ -48,7 +48,7 @@ unsigned char *buf;
int nbytes; /* size actually read */
{
int i, has_escapes = 0;
- unsigned char *s;
+ char *s;
char nbuf[HOWMANY+1]; /* one extra for terminating '\0' */
char *token;
register struct names *p;
@@ -90,17 +90,20 @@ int nbytes; /* size actually read */
/* Make sure we are dealing with ascii text before looking for tokens */
- for (i = 0; i < nbytes; i++) {
- if (!isascii(buf[i]))
+ for (i = 0; i < nbytes - 1; i++) {
+ if (!isascii(buf[i]) ||
+ (iscntrl(buf[i]) && !isspace(buf[i]) &&
+ buf[i] != '\b' && buf[i] != '\032' && buf[i] != '\033'
+ )
+ )
return 0; /* not all ASCII */
}
/* look for tokens from names.h - this is expensive! */
/* make a copy of the buffer here because strtok() will destroy it */
- s = (unsigned char*) memcpy(nbuf, buf, nbytes);
- s[nbytes] = '\0';
- has_escapes = (memchr(s, '\033', nbytes) != NULL);
- while ((token = strtok((char *) s, " \t\n\r\f")) != NULL) {
+ s = strcpy(nbuf, buf);
+ has_escapes = (strchr(s, '\033') != NULL);
+ while ((token = strtok(s, " \t\n\r\f")) != NULL) {
s = NULL; /* make strtok() keep on tokin' */
for (p = names; p < names + NNAMES; p++) {
if (STREQ(p->name, token)) {
OpenPOWER on IntegriCloud