Skip to content

lvm fullreport can produce invalid json

I am using a tool that uses lvm fullreport to export data about LVM for a particular host. In specific, it runs this command:

/usr/sbin/lvm fullreport --all --config 'global/suffix=false global/units=b report/binary_values_as_numeric=1 report/output_format=json report/buffered=false report/time_format=%s' --configreport pv --options pv_uuid,pv_name,pv_all --configreport lv --options lv_uuid,lv_name,lv_all --configreport vg --options vg_uuid,vg_name,vg_all --configreport seg --options -all --configreport pvseg --options -all

An example output from this is attached: output.json

The issue is this part:

"pv_device_id":"t10.ATA_DELLBOSS_VD_1ae4ea1b10650010\0\0\0\0"

LVM is passing the device ID characters literally to the json output. However, that leads to an invalid json file as per the spec: https://datatracker.ietf.org/doc/html/rfc8259#section-7

I am currently running version 2.03.24(2)-RHEL9 of LVM:

# lvm version
  LVM version:     2.03.24(2)-RHEL9 (2024-05-16)
  Library version: 1.02.198-RHEL9 (2024-05-16)
  Driver version:  4.48.0
  Configuration:   ./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-default-dm-run-dir=/run --with-default-run-dir=/run/lvm --with-default-pid-dir=/run --with-default-locking-dir=/run/lock/lvm --with-usrlibdir=/usr/lib64 --enable-fsadm --enable-write_install --with-user= --with-group= --with-device-uid=0 --with-device-gid=6 --with-device-mode=0660 --enable-pkgconfig --enable-cmdlib --enable-dmeventd --enable-blkid_wiping --with-udevdir=/usr/lib/udev/rules.d --enable-udev_sync --with-thin=internal --with-cache=internal --enable-lvmpolld --enable-lvmlockd-dlm --enable-lvmlockd-dlmcontrol --enable-lvmlockd-sanlock --enable-dbus-service --enable-notify-dbus --enable-dmfilemapd --with-writecache=internal --with-vdo=internal --with-vdo-format=/usr/bin/vdoformat --with-integrity=internal --with-default-use-devices-file=1 --disable-silent-rules --enable-app-machineid --enable-editline --disable-readline

In the source code, it looks like the output of strings is handled by _safe_repstr_output(). It has code for escaping double quotes. But not for escaping control characters or backslash.

It looks like this functionality is the same between version 2.03.24(2)-RHEL9 and HEAD.