[dpkg] 111/187: libdpkg: Use our own dpkg_ar_hdr instead of relying on the system one

Reiner Herrmann reiner at reiner-h.de
Sun Nov 6 12:46:30 UTC 2016


This is an automated email from the git hooks/post-receive script.

deki-guest pushed a commit to branch master
in repository dpkg.

commit 534510ae79d96691ba31d08b52c1158455a9621f
Author: Guillem Jover <guillem at debian.org>
Date:   Fri Aug 26 02:58:36 2016 +0200

    libdpkg: Use our own dpkg_ar_hdr instead of relying on the system one
    
    The ar format is not standardized and some systems might provide a
    different format than the one used by dpkg. For example on AIX.
---
 debian/changelog   |  3 +++
 dpkg-deb/extract.c |  2 +-
 dpkg-split/info.c  |  2 +-
 lib/dpkg/ar.c      | 12 ++++++------
 lib/dpkg/ar.h      | 19 ++++++++++++++++---
 lib/dpkg/t/t-ar.c  |  6 +++---
 6 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 2b5d955..977d364 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -53,6 +53,9 @@ dpkg (1.18.11) UNRELEASED; urgency=medium
       derivatives, by using perl's $Config{cf_by} variable to key on. The
       Debian-specific --rsyncable option should have never been accepted for
       use in dpkg to begin with.
+    - Use our own dpkg_ar_hdr struct instead of relying on the system
+      ar_hdr struct, as the ar format is not standardized and does vary
+      across systems, for example on AIX.
   * Perl modules:
     - Obsolete Source-Version substvar in Dpkg::Substvars by emitting errors.
     - Rework keyring hooks in Dpkg::Vendor. Deprecate the keyrings hook, and
diff --git a/dpkg-deb/extract.c b/dpkg-deb/extract.c
index d486c6d..5edba2d 100644
--- a/dpkg-deb/extract.c
+++ b/dpkg-deb/extract.c
@@ -131,7 +131,7 @@ extracthalf(const char *debar, const char *dir,
     ctrllennum= 0;
     header_done = false;
     for (;;) {
-      struct ar_hdr arh;
+      struct dpkg_ar_hdr arh;
 
       r = fd_read(ar->fd, &arh, sizeof(arh));
       if (r != sizeof(arh))
diff --git a/dpkg-split/info.c b/dpkg-split/info.c
index 57de75e..58d1153 100644
--- a/dpkg-split/info.c
+++ b/dpkg-split/info.c
@@ -93,7 +93,7 @@ read_info(struct dpkg_ar *ar, struct partinfo *ir)
   intmax_t templong;
   char magicbuf[sizeof(DPKG_AR_MAGIC) - 1], *rip, *partnums, *slash;
   const char *err;
-  struct ar_hdr arh;
+  struct dpkg_ar_hdr arh;
   ssize_t rc;
 
   rc = fd_read(ar->fd, magicbuf, sizeof(magicbuf));
diff --git a/lib/dpkg/ar.c b/lib/dpkg/ar.c
index 8a84c67..70a5a43 100644
--- a/lib/dpkg/ar.c
+++ b/lib/dpkg/ar.c
@@ -110,7 +110,7 @@ dpkg_ar_member_init(struct dpkg_ar *ar, struct dpkg_ar_member *member,
 }
 
 void
-dpkg_ar_normalize_name(struct ar_hdr *arh)
+dpkg_ar_normalize_name(struct dpkg_ar_hdr *arh)
 {
 	char *name = arh->ar_name;
 	int i;
@@ -125,7 +125,7 @@ dpkg_ar_normalize_name(struct ar_hdr *arh)
 }
 
 off_t
-dpkg_ar_member_get_size(struct dpkg_ar *ar, struct ar_hdr *arh)
+dpkg_ar_member_get_size(struct dpkg_ar *ar, struct dpkg_ar_hdr *arh)
 {
 	const char *str = arh->ar_size;
 	int len = sizeof(arh->ar_size);
@@ -150,9 +150,9 @@ dpkg_ar_member_get_size(struct dpkg_ar *ar, struct ar_hdr *arh)
 }
 
 bool
-dpkg_ar_member_is_illegal(struct ar_hdr *arh)
+dpkg_ar_member_is_illegal(struct dpkg_ar_hdr *arh)
 {
-	return memcmp(arh->ar_fmag, ARFMAG, sizeof(arh->ar_fmag)) != 0;
+	return memcmp(arh->ar_fmag, DPKG_AR_FMAG, sizeof(arh->ar_fmag)) != 0;
 }
 
 void
@@ -165,7 +165,7 @@ dpkg_ar_put_magic(struct dpkg_ar *ar)
 void
 dpkg_ar_member_put_header(struct dpkg_ar *ar, struct dpkg_ar_member *member)
 {
-	char header[sizeof(struct ar_hdr) + 1];
+	char header[sizeof(struct dpkg_ar_hdr) + 1];
 	int n;
 
 	if (strlen(member->name) > 15)
@@ -177,7 +177,7 @@ dpkg_ar_member_put_header(struct dpkg_ar *ar, struct dpkg_ar_member *member)
 	            member->name, (unsigned long)member->time,
 	            (unsigned long)member->uid, (unsigned long)member->gid,
 	            (unsigned long)member->mode, (intmax_t)member->size);
-	if (n != sizeof(struct ar_hdr))
+	if (n != sizeof(struct dpkg_ar_hdr))
 		ohshit(_("generated corrupt ar header for '%s'"), ar->name);
 
 	if (fd_write(ar->fd, header, n) < 0)
diff --git a/lib/dpkg/ar.h b/lib/dpkg/ar.h
index ba3ebd9..116703d 100644
--- a/lib/dpkg/ar.h
+++ b/lib/dpkg/ar.h
@@ -37,6 +37,19 @@ DPKG_BEGIN_DECLS
  */
 
 #define DPKG_AR_MAGIC "!<arch>\n"
+#define DPKG_AR_FMAG  "`\n"
+
+/**
+ * An on-disk archive header.
+ */
+struct dpkg_ar_hdr {
+	char ar_name[16];	   /* Member file name, sometimes / terminated. */
+	char ar_date[12];	   /* File date, decimal seconds since Epoch.  */
+	char ar_uid[6], ar_gid[6]; /* User and group IDs, in ASCII decimal.  */
+	char ar_mode[8];	   /* File mode, in ASCII octal.  */
+	char ar_size[10];	   /* File size, in ASCII decimal.  */
+	char ar_fmag[2];
+};
 
 /**
  * An archive (Unix ar) file.
@@ -70,8 +83,8 @@ struct dpkg_ar *dpkg_ar_create(const char *filename, mode_t mode);
 void dpkg_ar_set_mtime(struct dpkg_ar *ar, time_t mtime);
 void dpkg_ar_close(struct dpkg_ar *ar);
 
-void dpkg_ar_normalize_name(struct ar_hdr *arh);
-bool dpkg_ar_member_is_illegal(struct ar_hdr *arh);
+void dpkg_ar_normalize_name(struct dpkg_ar_hdr *arh);
+bool dpkg_ar_member_is_illegal(struct dpkg_ar_hdr *arh);
 
 void dpkg_ar_put_magic(struct dpkg_ar *ar);
 void dpkg_ar_member_put_header(struct dpkg_ar *ar,
@@ -80,7 +93,7 @@ void dpkg_ar_member_put_file(struct dpkg_ar *ar, const char *name,
                              int fd, off_t size);
 void dpkg_ar_member_put_mem(struct dpkg_ar *ar, const char *name,
                             const void *data, size_t size);
-off_t dpkg_ar_member_get_size(struct dpkg_ar *ar, struct ar_hdr *arh);
+off_t dpkg_ar_member_get_size(struct dpkg_ar *ar, struct dpkg_ar_hdr *arh);
 
 /** @} */
 
diff --git a/lib/dpkg/t/t-ar.c b/lib/dpkg/t/t-ar.c
index 013e62a..28b5e38 100644
--- a/lib/dpkg/t/t-ar.c
+++ b/lib/dpkg/t/t-ar.c
@@ -27,7 +27,7 @@
 static void
 test_ar_normalize_name(void)
 {
-	struct ar_hdr arh;
+	struct dpkg_ar_hdr arh;
 
 	strncpy(arh.ar_name, "member-name/    ", sizeof(arh.ar_name));
 	dpkg_ar_normalize_name(&arh);
@@ -41,12 +41,12 @@ test_ar_normalize_name(void)
 static void
 test_ar_member_is_illegal(void)
 {
-	struct ar_hdr arh;
+	struct dpkg_ar_hdr arh;
 
 	memset(&arh, ' ', sizeof(arh));
 	test_pass(dpkg_ar_member_is_illegal(&arh));
 
-	memcpy(arh.ar_fmag, ARFMAG, sizeof(arh.ar_fmag));
+	memcpy(arh.ar_fmag, DPKG_AR_FMAG, sizeof(arh.ar_fmag));
 	test_fail(dpkg_ar_member_is_illegal(&arh));
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list