The following commit has been merged in the master branch:
commit d30a087c4f7686ad237b15b413848a6a8fe87ed6
Author: Guillem Jover <[email protected]>
Date:   Mon Nov 1 20:44:41 2010 +0100

    libdpkg: Refactor tar_header_checksum() out from tar_header_decode()

diff --git a/lib/dpkg/tarfn.c b/lib/dpkg/tarfn.c
index 403216a..3595528 100644
--- a/lib/dpkg/tarfn.c
+++ b/lib/dpkg/tarfn.c
@@ -158,16 +158,37 @@ get_unix_mode(struct tar_header *h)
        return mode;
 }
 
+static bool
+tar_header_checksum(struct tar_header *h)
+{
+       unsigned char *s = (unsigned char *)h;
+       unsigned int i;
+       long checksum;
+       long sum;
+
+       checksum = OtoL(h->checksum, sizeof(h->checksum));
+
+       /* Treat checksum field as all blank. */
+       sum = ' ' * sizeof(h->checksum);
+
+       for (i = checksum_offset; i > 0; i--)
+               sum += *s++;
+
+       /* Skip the real checksum field. */
+       s += sizeof(h->checksum);
+
+       for (i = TARBLKSZ - checksum_offset - sizeof(h->checksum); i > 0; i--)
+               sum += *s++;
+
+       return (sum == checksum);
+}
+
 static int
 tar_header_decode(char *block, struct tar_entry *d)
 {
        struct tar_header *h = (struct tar_header *)block;
-       unsigned char *s = (unsigned char *)block;
        struct passwd *passwd = NULL;
        struct group *group = NULL;
-       unsigned int i;
-       long sum;
-       long checksum;
 
        if (memcmp(h->magic, TAR_MAGIC_GNU, 6) == 0)
                d->format = tar_format_gnu;
@@ -206,18 +227,7 @@ tar_header_decode(char *block, struct tar_entry *d)
        else
                d->stat.gid = (gid_t)OtoL(h->gid, sizeof(h->gid));
 
-       checksum = OtoL(h->checksum, sizeof(h->checksum));
-
-       /* Treat checksum field as all blank. */
-       sum = ' ' * sizeof(h->checksum);
-       for (i = checksum_offset; i > 0; i--)
-               sum += *s++;
-       /* Skip the real checksum field. */
-       s += sizeof(h->checksum);
-       for (i = TARBLKSZ - checksum_offset - sizeof(h->checksum); i > 0; i--)
-               sum += *s++;
-
-       return (sum == checksum);
+       return tar_header_checksum(h);
 }
 
 struct symlinkList {

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to