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

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=2c4814f7cb676c335c6372284ac95b7fc986effb

The following commit(s) were added to refs/heads/main by this push:
     new 2c4814f7c libdpkg: Handle missing Version when formatting 
source:Upstream-Version
2c4814f7c is described below

commit 2c4814f7cb676c335c6372284ac95b7fc986effb (HEAD -> main)
Author: Guillem Jover <[email protected]>
AuthorDate: Sun Apr 23 04:44:32 2023 +0200

    libdpkg: Handle missing Version when formatting source:Upstream-Version
    
    When dealing with virtual packages (such as the ones from Provides, or
    for not-installed Recommends or Suggests), there might be no version
    field at all, so we cannot assume we can use these when filling in the
    version information in the fallback code handling the missing Source
    field.
    
    The commit that removed the check for not-installed packages missed that
    this instance had not been protected, as the code in varbufversion() is
    doing the correct thing, but unfortunately we are not using that because
    we need to get at the upstream part, so we need to also check explicitly
    for a non-NULL upstream part. This was causing a segfault.
    
    Fixes: commit 560574b55a543d3d0a0f4e8abf0ae42f46d2a2f1
    Stable-Candidates: 1.20.x 1.21.x
    Reported-by: John Scott <[email protected]>
---
 lib/dpkg/pkg-format.c     |  3 ++-
 lib/dpkg/t/t-pkg-format.c | 19 ++++++++++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/lib/dpkg/pkg-format.c b/lib/dpkg/pkg-format.c
index 84052a7f1..b98401217 100644
--- a/lib/dpkg/pkg-format.c
+++ b/lib/dpkg/pkg-format.c
@@ -359,7 +359,8 @@ virt_source_upstream_version(struct varbuf *vb,
 
        pkg_source_version(&version, pkg, pkgbin);
 
-       varbuf_add_str(vb, version.version);
+       if (version.version)
+               varbuf_add_str(vb, version.version);
        varbuf_end_str(vb);
 }
 
diff --git a/lib/dpkg/t/t-pkg-format.c b/lib/dpkg/t/t-pkg-format.c
index 0588c91ff..a6d33feb6 100644
--- a/lib/dpkg/t/t-pkg-format.c
+++ b/lib/dpkg/t/t-pkg-format.c
@@ -43,6 +43,17 @@ prep_pkg(struct pkgset *set, struct pkginfo *pkg)
        pkg->installed.version = DPKG_VERSION_OBJECT(0, "4.5", "2");
 }
 
+static void
+prep_virtpkg(struct pkgset *set, struct pkginfo *pkg)
+{
+       pkg_blank(pkg);
+
+       pkgset_blank(set);
+       pkgset_link_pkg(set, pkg);
+
+       set->name = "test-virt";
+}
+
 static void
 test_field(struct pkginfo *pkg, const char *fmt, const char *exp)
 {
@@ -96,6 +107,12 @@ test_pkg_format_virtual_fields(void)
 
        test_field(&pkg, "${binary:Summary}",
                         "short synopsis -- some package");
+
+       prep_virtpkg(&pkgset, &pkg);
+       test_field(&pkg, "${source:Package}_${source:Version}",
+                        "test-virt_");
+       test_field(&pkg, "${source:Upstream-Version}",
+                        "");
 }
 
 static void
@@ -116,7 +133,7 @@ test_pkg_format_virtual_fields_db_fsys(void)
 
 TEST_ENTRY(test)
 {
-       test_plan(20);
+       test_plan(24);
 
        test_pkg_format_real_fields();
        test_pkg_format_virtual_fields();

-- 
Dpkg.Org's dpkg

Reply via email to