From: Ian Darwin Date: Fri, 11 Sep 1992 10:08:52 +0000 (+0000) Subject: |I killed the bug... The problem was that strtok() was corrupting the X-Git-Tag: FILE3_27~233 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eef93dcd5a9981cda706a85bd820527c54b30b00;p=file |I killed the bug... The problem was that strtok() was corrupting the |input buffer so the uncompressed result was not correct, and it would |fail the tar checksum. | |I make a copy to nbuf and use that buffer to strtok()... |[ascmagic.c bugfix] | |I also restored the value of the buffer in another place so that |buf[] always contains the first HOWMANY bytes of the file. |[softmagic.c bug fix] | |christos --- diff --git a/src/ascmagic.c b/src/ascmagic.c index 51ce3fb1..531a999d 100644 --- a/src/ascmagic.c +++ b/src/ascmagic.c @@ -36,7 +36,7 @@ #ifndef lint static char *moduleid = - "@(#)$Id: ascmagic.c,v 1.10 1992/09/08 15:36:39 ian Exp $"; + "@(#)$Id: ascmagic.c,v 1.11 1992/09/11 10:08:52 ian Exp $"; #endif /* lint */ /* an optimisation over plain strcmp() */ @@ -49,6 +49,7 @@ int nbytes; /* size actually read */ { int i, isblock, has_escapes = 0; unsigned char *s; + char nbuf[HOWMANY]; char *token; register struct names *p; @@ -77,7 +78,8 @@ int nbytes; /* size actually read */ } /* look for tokens from names.h - this is expensive! */ - s = buf; + /* make a copy of the buffer here because strtok() will destroy it */ + s = (unsigned char*) memcpy(nbuf, buf, HOWMANY); while ((token = strtok((char*)s, " \t\n\r\f")) != NULL) { s = NULL; /* make strtok() keep on tokin' */ for (p = names; p < names + NNAMES; p++) { diff --git a/src/softmagic.c b/src/softmagic.c index df0a963a..6ded6d0d 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -34,7 +34,7 @@ #ifndef lint static char *moduleid = - "@(#)$Id: softmagic.c,v 1.14 1992/09/09 15:04:16 ian Exp $"; + "@(#)$Id: softmagic.c,v 1.15 1992/09/11 10:09:26 ian Exp $"; #endif /* lint */ static int match __P((unsigned char *)); @@ -119,15 +119,17 @@ unsigned char *s; (m->reln & MASK) ? p->l & m->mask : p->l); break; case STRING: - if ((pp=strchr(p->s, '\n')) != NULL) - *pp = '\0'; + if ((rt=strchr(p->s, '\n')) != NULL) + *rt = '\0'; (void) printf(m->desc, p->s); + *rt = '\n'; break; case DATE: pp = ctime((time_t*) &p->l); if ((rt = strchr(pp, '\n')) != NULL) *rt = '\0'; (void) printf(m->desc, pp); + *rt = '\n'; break; default: error("invalid m->type (%d) in mprint().\n", m->type);