Browse Source

dpkg: Fix physical file offset comparison

The comparison function pkg_sorter_by_listfile_phys_offs passed to qsort
does not satisfy qsort symmetry requirements, for some inputs

  pkg_sorter_by_listfile_phys_offs(a, b) != -
  pkg_sorter_by_listfile_phys_offs(b, a)

This may cause various qsort misbehaviors e.g. failing to properly sort
the input array (on some platforms qsort could even abort although that
seems to not be the case for glibc-based systems).

Closes: #808912
Signed-off-by: Guillem Jover <guillem@debian.org>
Stable-Candidate: 1.16.x 1.17.x
Yuri Gribov 8 years ago
parent
commit
873b44e359
2 changed files with 5 additions and 1 deletions
  1. 2 0
      debian/changelog
  2. 3 1
      src/filesdb.c

+ 2 - 0
debian/changelog

@@ -26,6 +26,8 @@ dpkg (1.18.4) UNRELEASED; urgency=medium
     Thanks to Hanno Böck <hanno@hboeck.de>.
   * Add experimental multithreaded xz compression support in libdpkg, which
     requires xz >= 5.2.0.
+  * Fix physical file offset comparison in dpkg. Closes: #808912
+    Thanks to Yuri Gribov <tetra2005@gmail.com>.
   * Test suite:
     - Improve perl code test coverage.
   * Build system:

+ 3 - 1
src/filesdb.c

@@ -312,8 +312,10 @@ pkg_sorter_by_listfile_phys_offs(const void *a, const void *b)
    * INT_MAX. */
   if (pa->clientdata->listfile_phys_offs < pb->clientdata->listfile_phys_offs)
     return -1;
-  else
+  else if (pa->clientdata->listfile_phys_offs > pb->clientdata->listfile_phys_offs)
     return 1;
+  else
+    return 0;
 }
 
 static void