Bug 1858625 - supermin fails to parse non-integer pacman pkgrel
Summary: supermin fails to parse non-integer pacman pkgrel
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Virtualization Tools
Classification: Community
Component: supermin
Version: unspecified
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: ---
Assignee: Richard W.M. Jones
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
: 1895623 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-07-19 16:36 UTC by Tim Schumacher
Modified: 2020-11-09 08:57 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-07-23 15:33:48 UTC


Attachments (Terms of Use)
The full libguestfs-test-tool output when encountering the bug. (3.30 KB, text/plain)
2020-07-19 16:36 UTC, Tim Schumacher
no flags Details

Description Tim Schumacher 2020-07-19 16:36:14 UTC
Created attachment 1701676 [details]
The full libguestfs-test-tool output when encountering the bug.

Description of problem:

supermin tries to parse the pkgrel of a pacman package into an integer, which fails if the version contains anything else than numbers (for example a major.minor verison format).


Version-Release number of selected component (if applicable): 5.2.0


How reproducible:

Should be reproducible on any pacman-based system, as long as a package with a non-integer pkgrel is installed.


Steps to Reproduce:
1. Install package with non-integer pkgrel (for example Manjaro's `dbus-x11` or `util-linux` packages).
2. Run `libguestfs-test-tool`

Actual results:

libguestfs-test-tool exits with the following (full output in the attachments):

    supermin: mapping package names to installed packages
    supermin: resolving full list of package dependencies
    supermin: failure: failed to parse epoch:version-release field 0.116-5.1
    libguestfs: error: /usr/bin/supermin exited with error status 1, see debug messages above
    libguestfs: closing guestfs handle 0x55606feedaf0 (state 0)

Expected results:

libguestfs-test-tool does not fail while parsing pacman package versions.


Additional info:

While the PKGBUILD documentation says that pkgrel is _often_ an integer number, it also mentions exceptional cases where the version is written in a different format.

Comment 1 Richard W.M. Jones 2020-07-23 14:21:23 UTC
I'm not sure how to fix this, but I can explain what's happening.  This
is the code:

https://github.com/libguestfs/supermin/blob/a27dd57d3a7c35093d3f5c71cac8d45a220ce016/src/ph_pacman.ml#L73-L89

In this code at line 84 the call to int_of_string is failing because (as
you say) the code expects the release field to be an integer but it's
"5.1".

Furthermore in the internal pac_t type, release is an int (should it be a string)?

https://github.com/libguestfs/supermin/blob/a27dd57d3a7c35093d3f5c71cac8d45a220ce016/src/ph_pacman.ml#L39

The release field is not significantly used for anything, so the following
patch compiles for me (but I didn't test it further because I don't have
a system handy which demonstrates the bug):

diff --git a/src/ph_pacman.ml b/src/ph_pacman.ml
index b3effca..67f7512 100644
--- a/src/ph_pacman.ml
+++ b/src/ph_pacman.ml
@@ -36,7 +36,7 @@ type pac_t = {
   name : string;
   epoch : int;
   version : string;
-  release : int;
+  release : string;
   arch : string;
 }
 
@@ -81,7 +81,7 @@ let pacman_package_of_string str =
           with Not_found -> 0, evr in
         let version, release =
           match string_split "-" vr with
-          | [ v; r ] -> v, int_of_string r
+          | [ v; r ] -> v, r
           | _ -> assert false in
         epoch, version, release
       with
@@ -117,9 +117,9 @@ let pacman_package_of_string str =
 let pacman_package_to_string pkg =
   let pac = pac_of_pkg pkg in
   if pac.epoch = 0 then
-    sprintf "%s-%s-%d.%s" pac.name pac.version pac.release pac.arch
+    sprintf "%s-%s-%s.%s" pac.name pac.version pac.release pac.arch
   else
-    sprintf "%s-%d:%s-%d.%s"
+    sprintf "%s-%d:%s-%s.%s"
       pac.name pac.epoch pac.version pac.release pac.arch
 
 let pacman_package_name pkg =

Comment 2 Tim Schumacher 2020-07-23 14:51:46 UTC
I dug a bit deeper into the pacman source (or rather libalpm, the actual core),
and found more information regarding the format in the linter:

https://git.archlinux.org/pacman.git/tree/scripts/libmakepkg/lint_pkgbuild/pkgrel.sh.in#n40

It seems like only a pkgrel of the formats "%d" or "%d.%d" is allowed, nothing else.
Since that can't be stored in an integer, I assume making that a string is the way to go.

The patch you attached I built locally and confirmed that libguestfs-test-tool doesn't error
out anymore, but instead passes all tests.

Comment 4 Richard W.M. Jones 2020-11-09 08:57:29 UTC
*** Bug 1895623 has been marked as a duplicate of this bug. ***


Note You need to log in before you can comment on or make changes to this bug.