]> granicus.if.org Git - file/commitdiff
|I killed the bug... The problem was that strtok() was corrupting the
authorIan Darwin <ian@darwinsys.com>
Fri, 11 Sep 1992 10:08:52 +0000 (10:08 +0000)
committerIan Darwin <ian@darwinsys.com>
Fri, 11 Sep 1992 10:08:52 +0000 (10:08 +0000)
|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

src/ascmagic.c
src/softmagic.c

index 51ce3fb139b4db2d33594961db0c16186c706b60..531a999dfc55d1e17fbaf73693b67a6cab8e8a91 100644 (file)
@@ -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++) {
index df0a963a9d1207ca2f6662ecaa73433519bed116..6ded6d0de7c1e49317e90dc77a6d7bcff25a6f4f 100644 (file)
@@ -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);