Skip to content

Fix destructive-cleanup failure when no old packages exist#1936

Merged
cgwalters merged 1 commit intobootc-dev:mainfrom
henrywang:fix-destructive-cleanup-empty-rpm
Jan 21, 2026
Merged

Fix destructive-cleanup failure when no old packages exist#1936
cgwalters merged 1 commit intobootc-dev:mainfrom
henrywang:fix-destructive-cleanup-empty-rpm

Conversation

@henrywang
Copy link
Copy Markdown
Collaborator

When rpm -qa returns no packages, xargs would still invoke rpm -e with no arguments, causing failure with "no packages given for erase" (exit code 123).

Add -r flag to xargs to skip execution when input is empty.

Resolves #1935

When rpm -qa returns no packages, xargs would still invoke
rpm -e with no arguments, causing failure with "no packages
given for erase" (exit code 123).

Add -r flag to xargs to skip execution when input is empty.

Signed-off-by: Xiaofeng Wang <henrywangxf@me.com>
@bootc-bot bootc-bot bot requested a review from jeckersb January 21, 2026 02:28
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to fix a bug in the fedora-bootc-destructive-cleanup script where it would fail if no RPM packages were found. While the addition of the -r flag to xargs addresses this, a critical security vulnerability has been identified: the current use of xargs with output from a potentially untrusted filesystem introduces an argument injection risk. An attacker could manipulate the RPM database to inject flags into rpm -e, potentially leading to unintended package deletions on the host system. It is strongly recommended to use the -- flag to terminate options and -d '\n' for xargs to safely handle input.

# Remove all RPMs installed in the physical root (i.e. the previous OS)
mount -o remount,rw /sysroot
rpm -qa --root=/sysroot --dbpath=/usr/lib/sysimage/rpm | xargs rpm -e --root=/sysroot --dbpath=/usr/lib/sysimage/rpm
rpm -qa --root=/sysroot --dbpath=/usr/lib/sysimage/rpm | xargs -r rpm -e --root=/sysroot --dbpath=/usr/lib/sysimage/rpm
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

This line introduces a critical argument injection vulnerability. Piping output from rpm -qa from a potentially untrusted /sysroot into xargs rpm -e without proper sanitization can allow an attacker to inject malicious flags, potentially causing rpm -e to operate on the host's root filesystem and delete critical packages. Additionally, xargs without -d '\n' can mishandle package names with spaces or special characters. While defining rpm options in a variable could improve readability, addressing the security vulnerability is paramount. The suggested fix includes using -- to terminate options for rpm -e and xargs -d '\n' to safely handle input.

Suggested change
rpm -qa --root=/sysroot --dbpath=/usr/lib/sysimage/rpm | xargs -r rpm -e --root=/sysroot --dbpath=/usr/lib/sysimage/rpm
rpm -qa --root=/sysroot --dbpath=/usr/lib/sysimage/rpm | xargs -r -d '\n' rpm -e --root=/sysroot --dbpath=/usr/lib/sysimage/rpm --
@henrywang
Copy link
Copy Markdown
Collaborator Author

Failure has been fixed by PR #1937

@cgwalters cgwalters merged commit f567f7e into bootc-dev:main Jan 21, 2026
33 of 37 checks passed
@henrywang henrywang deleted the fix-destructive-cleanup-empty-rpm branch January 21, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants