Bug 1858625

Summary: supermin fails to parse non-integer pacman pkgrel
Product: [Community] Virtualization Tools Reporter: Tim Schumacher <timschumi>
Component: superminAssignee: Richard W.M. Jones <rjones>
Status: CLOSED UPSTREAM QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: unspecifiedCC: cl.dev, johnadegbile, ptoscano, rjones
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-07-23 15:33:48 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Description Flags
The full libguestfs-test-tool output when encountering the bug. none

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:


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

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


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
@@ -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
-    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:


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. ***

Comment 5 jade 2020-12-17 04:39:08 UTC

Has the fix for this been rolled out? I am running the latest available updates for Manjaro (System completely uptodate as at 16th December)

Operating System: Manjaro Linux
KDE Plasma Version: 5.20.4
KDE Frameworks Version: 5.76.0
Qt Version: 5.15.2
Kernel Version: 5.8.18-1-MANJARO
OS Type: 64-bit

I'm trying to clone a KVM domain and I'm getting an error when running "virt-sysprep":

"supermin: failure: failed to parse epoch:version-release field 29-1.0
libguestfs: trace: launch = -1 (error)
virt-sysprep: error: libguestfs error: /usr/bin/supermin exited with error
status 1, see debug messages above"

Comment 6 Tim Schumacher 2020-12-17 09:48:36 UTC
Neither Arch Linux nor Manjaro have updated their supermin packages since the issue has been fixed,
but that isn't surprising seeing how there hasn't been a tagged release since.

The best way to get them to adopt the fix early would probably be to ask them to add that patch manually.

Comment 7 jade 2020-12-17 13:55:52 UTC
Thanks for taking the time to respond. I will follow up with Manjaro team.