Subject: Buglet in the Installer - may bite you eventually.
To: None <port-mac68k@netbsd.org>
From: Bob Beck <beck@bofh.ucs.ualberta.ca>
List: port-mac68k
Date: 10/11/2001 13:44:53
 
   Greetings NetBSD'ers.

	In my trevails with the Installer as we use it in OpenBSD land
I did notice a small problem with the Installer - I was getting bit by
bad tar header checksums, Extracting our (OpenBSD) tarballs with the
NetBSD Installer produced the same problem (The installers are the
same except ours builds different devices). Looks like the Installer
in xtar.c has a bit of a problem, in that it uses and dereferences a
char* pointer to a block which may turn out to be signed depending on
the compiler you happen to build it with under MacOS.  When this
happens it can compute the wrong value, because a byte comes back
negative.

       I've changed ours as follows, which fixes the problem. You may
wish to do something similar to avoid problems in the future if you
get anything in a tar header that makes a char go negative. basic
minimum to avoid the problem is to change p to be u_char I believe.

  Cheers,

  -Bob

----------------8<-----------------
--- ../Installer 1.1h/xtar.c    Tue Oct  9 22:32:54 2001
+++ xtar.c      Thu Oct 11 13:27:59 2001
@@ -63,7 +63,8 @@
 
 /* pull header buffer apart into these variables */
 char   tar_name[100], tar_linkname[100];
-int    tar_mode, tar_uid, tar_gid, tar_chksum, tar_linkflag;
+int    tar_mode, tar_uid, tar_gid, tar_linkflag;
+u_long  tar_chksum;
 int    tar_rdev, tar_major, tar_minor;
 long   tar_size, tar_mtime;
 long   tar_blocks, tar_remainder;
@@ -290,10 +291,11 @@
        tar_header.chksum[6] = ' ';
        tar_header.chksum[7] = ' ';
        {
-               int sum = 0;
+               u_long sum = 0;
                int i = TBLOCK;
-               char *p = (char *)&tar_header;
-               while (i-->0) sum += *p++;
+               u_char *p = (char *)&tar_header;
+               u_char *stop = p + TBLOCK; 
+               while (p < stop) sum += (*p++ & 0xff);
                if (sum != tar_chksum) {
                        printf("bad checksum in tar header %d %d\n",
                                sum, tar_chksum);