Bug 1672951 - virt-inspector fails with "error: int_of_string" on a Linux image when /etc/fstab contains a partionless device
Summary: virt-inspector fails with "error: int_of_string" on a Linux image when /etc/f...
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libguestfs
Version: 7.7
Hardware: Unspecified
OS: Unspecified
Target Milestone: rc
: ---
Assignee: Pino Toscano
QA Contact: YongkuiGuo
Depends On: 1621895 1661038
Blocks: 1673280 libguestfs-1.38.2-12.29.lp.el7ev
TreeView+ depends on / blocked
Reported: 2019-02-06 10:08 UTC by Jaroslav Spanko
Modified: 2019-08-06 12:45 UTC (History)
10 users (show)

Fixed In Version: libguestfs-1.40.1-1.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 1661038
: 1673280 libguestfs-1.38.2-12.29.lp.el7ev 1679966 (view as bug list)
Last Closed: 2019-08-06 12:44:47 UTC
Target Upstream Version:

Attachments (Terms of Use)

System ID Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2019:2096 None None None 2019-08-06 12:45:14 UTC

Comment 3 Pino Toscano 2019-02-06 10:40:03 UTC
Clone of bug 1661038, so copying its important bits:


Description of problem:

guestfish fails to correctly parse (some?) partitionless devices listed in /etc/fstab within a Linux image and unexpectedly exits with an error.


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

$ guestfish --version
guestfish 1.38.2rhel=7,release=12.el7_6.1,libvirt


How reproducible:



Steps to Reproduce:

1. Build a qcow2 image for a Linux OS where '/etc/fstab' specifies where a device such as '/dev/vdc' should be mounted.

2. Run 'virt-inspector' on the image. Or run 'guestfish -a <image>', and from within the 'guestfish' shell, run 'launch' followed by 'inspect_os'.

As of this writing, the following are bootable images for Fedora 24 and Ubuntu 12.04 that illustrate the issue:

* https://platform.swampinabox.org/platform-images/condor-fedora-24-64-master-2016080801.qcow2.gz
* https://platform.swampinabox.org/platform-images/condor-ubuntu-12.04-64-master-2016102702.qcow2.gz


Actual results:

$ virt-inspector condor-fedora-24-64-master-2016080801.qcow2 
libguestfs: error: inspect_os: int_of_string
virt-inspector: no operating system could be detected inside this disk image.


Expected results:

Valid information.


Additional info:

In the 'libguestfs' sources, 'daemon/inspect_fs_unix_fstab.ml' appears to contain a bug. The definition of 're_xdev' allows for partionless devices. The use of this regular expression within the function 'resolve_fstab_device' assumes that the string being matched does specify a partition:

    else if PCRE.matches re_xdev spec then (
      and part = int_of_string (PCRE.sub 3)

See the attachment 'virt-inspector-verbose.txt' for the output from 'virt-inspector -v'. The following section appears to be relevant:

    check_fstab_entry: augeas path: /files/etc/fstab/5
    check_fstab_entry: spec=/dev/vdc
    check_fstab_entry: mp=/mnt/out
    resolve_fstab_device: /dev/vdc matched xdev
    ocaml_exn: 'inspect_os' raised 'Failure' exception
    guestfsd: error: int_of_string
    guestfsd: => inspect_os (0x1e0) took 1.14 secs
    libguestfs: error: inspect_os: int_of_string


To be more precise: the OCaml code above assumes that the partition number is not an empty string, while re_xdev is:
  let re_xdev = PCRE.compile "^/dev/(h|s|v|xv)d([a-z]+)(\\d*)$"
which indeed can result in an empty string for the 3rd match.

This is a regression in the new OCaml code, compared to the old C one (in libguestfs < 1.38).
The old code just took the result of the 3rd match as string, using it as-is without trying to convert it as integer.

Sent a simple patch to fix this:


Fixed upstream with
which is in libguestfs >= 1.39.15.

Comment 4 Pino Toscano 2019-02-06 10:41:23 UTC
This bug is fixed by the rebase scheduled for RHEL 7.7, see bug 1621895.

Comment 8 YongkuiGuo 2019-02-12 02:54:32 UTC
Verified with package:


1. Download the condor-fedora-24-64-master-2016080801.qcow2 image from the link:
# virt-inspector -a condor-fedora-24-64-master-2016080801.qcow2
libguestfs: error: mount_ro: mount_ro_stub: /dev/vdb: expecting a device name
libguestfs: error: mount_ro: mount_ro_stub: /dev/vdc: expecting a device name
virt-inspector: some filesystems could not be mounted (ignored)
<?xml version="1.0"?>
    <product_name>Fedora 24 (Twenty Four)</product_name>
      <mountpoint dev="/dev/vg0/lv_root">/</mountpoint>
      <mountpoint dev="/dev/sda2">/boot</mountpoint>
      <mountpoint dev="/dev/sdb">/mnt/in</mountpoint>
      <mountpoint dev="/dev/sdc">/mnt/out</mountpoint>
      <filesystem dev="/dev/sda2">
      <filesystem dev="/dev/sdb"/>
      <filesystem dev="/dev/sdc"/>
      <filesystem dev="/dev/vg0/lv_root">
      <filesystem dev="/dev/vg0/lv_swap">

The virt-inspector command can inspect the linux image when /etc/fstab contains a partionless device. Verified this bug.

Comment 10 errata-xmlrpc 2019-08-06 12:44:47 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.


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