The following commit has been merged in the master branch:
commit 58e7276b69be105735eccb3c18c2b28d3a2ec2e5
Author: Guillem Jover <[email protected]>
Date:   Mon Jan 31 10:11:56 2011 +0100

    libdpkg: Ensure parsed packages have a usable arch member
    
    In case the package didn't have an Architecture field, warn and
    initialize it to an empty string, so that it can be safely used for
    string comparisons, printing, etc.
    
    This fixes a potential segfault when setting the environment variable
    DPKG_MAINTSCRIPT_ARCH from a package w/o an Architecture field, which
    are a thing from the distant past, but still should be supported.

diff --git a/debian/changelog b/debian/changelog
index 9d0cf03..a4cbd45 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -25,6 +25,8 @@ dpkg (1.16.0) UNRELEASED; urgency=low
   * Do not fail when trying to remove the root directory. This will only
     happen either on distributions where dpkg is a foreign package manager,
     or on artificial dpkg databases.
+  * Always warn when parsing any package control data which does not have
+    an Architecture field.
 
   [ Raphaƫl Hertzog ]
   * Fail properly when debian/source/format is empty. Closes: #600854
diff --git a/dpkg-deb/build.c b/dpkg-deb/build.c
index dcf86c4..3379862 100644
--- a/dpkg-deb/build.c
+++ b/dpkg-deb/build.c
@@ -368,12 +368,12 @@ static char *
 pkg_get_pathname(const char *dir, struct pkginfo *pkg)
 {
   char *path;
-  const char *versionstring, *arch;
+  const char *versionstring, *arch_sep;
 
   versionstring = versiondescribe(&pkg->available.version, vdew_never);
-  arch = pkg->available.arch;
+  arch_sep = pkg->available.arch[0] == '\0' ? "" : "_";
   m_asprintf(&path, "%s/%s_%s%s%s%s", dir, pkg->name, versionstring,
-             arch ? "_" : "", arch ? arch : "", DEBEXT);
+             arch_sep, pkg->available.arch, DEBEXT);
 
   return path;
 }
diff --git a/lib/dpkg/parse.c b/lib/dpkg/parse.c
index fae3531..fc94ce5 100644
--- a/lib/dpkg/parse.c
+++ b/lib/dpkg/parse.c
@@ -168,8 +168,10 @@ pkg_parse_verify(struct parsedb_state *ps,
     parse_ensure_have_field(ps, pkg, &pkgbin->maintainer, "maintainer");
     parse_must_have_field(ps, pkg, pkgbin->version.version, "version");
   }
-  if (ps->flags & pdb_recordavailable)
-    parse_ensure_have_field(ps, pkg, &pkgbin->arch, "architecture");
+
+  /* We always want usable architecture information, so that it can be used
+   * safely on string comparisons and the like. */
+  parse_ensure_have_field(ps, pkg, &pkgbin->arch, "architecture");
 
   /* Check the Config-Version information:
    * If there is a Config-Version it is definitely to be used, but
diff --git a/src/processarc.c b/src/processarc.c
index c642bc2..f7675e6 100644
--- a/src/processarc.c
+++ b/src/processarc.c
@@ -282,8 +282,7 @@ void process_archive(const char *filename) {
     return;
   }
 
-  if (pkg->available.arch && *pkg->available.arch &&
-      strcmp(pkg->available.arch, "all") &&
+  if (strcmp(pkg->available.arch, "all") &&
       strcmp(pkg->available.arch, native_arch))
     forcibleerr(fc_architecture,
                 _("package architecture (%s) does not match system (%s)"),

-- 
dpkg's main repository


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

Reply via email to