bios-install returns success when saving uninstall data fails
On trunk 76ba020fbcfb3802df5cfc81c3a5fbcbe14921e7, bios-install exits successfully when it cannot save the file requested by --uninstall-data-file.
store_uninstall_data() returns false for open, write and close failures. Its call in the successful-install cleanup path of bios_install() ignores that return value, leaving ok as EXIT_SUCCESS.
Reproduction
Build the host tool with BIOS support (./bootstrap, ./configure --enable-werror --enable-all, make all). On Linux, save the following script as backup-regression.py and run python3 backup-regression.py ./bin/limine.
The script operates only on temporary regular-file images. /dev/full is used as the backup destination to produce a write error.
Standalone regression script
"""Run against a built Limine host tool on Linux; only temporary images are used."""
from pathlib import Path
import json
import subprocess
import sys
import tempfile
exe = str(Path(sys.argv[1]).resolve())
results = []
with tempfile.TemporaryDirectory(prefix="limine-backup-regression-") as tmp:
root = Path(tmp)
original = bytearray(1024 * 1024)
original[510:512] = b"\x55\xaa"
def run(image, quiet, *options):
args = [exe, "bios-install"] + (["--quiet"] if quiet else [])
return subprocess.run(args + list(options) + [str(image)],
capture_output=True, text=True)
for quiet in (False, True):
directory = root / ("quiet" if quiet else "verbose")
directory.mkdir()
normal = directory / "normal.img"
normal.write_bytes(original)
installed = run(normal, quiet)
installed_bytes = normal.read_bytes()
results.append({"case": "no backup", "quiet": quiet,
"exit": installed.returncode,
"pass": installed.returncode == 0 and installed_bytes != original})
for label, backup in (("open failure", directory / "missing" / "undo.bin"),
("write failure", Path("/dev/full"))):
image = directory / (label.replace(" ", "-") + ".img")
image.write_bytes(original)
result = run(image, quiet, "--uninstall-data-file=" + str(backup))
passed = (result.returncode != 0 and "error:" in result.stderr
and image.read_bytes() == installed_bytes)
if label == "open failure":
passed = passed and not backup.exists()
results.append({"case": label, "quiet": quiet,
"exit": result.returncode, "pass": passed,
"stderr": result.stderr})
image = directory / "roundtrip.img"
image.write_bytes(original)
backup = directory / "undo.bin"
install = run(image, quiet, "--uninstall-data-file=" + str(backup))
valid_backup = backup.is_file() and backup.stat().st_size > 0
same_install = image.read_bytes() == installed_bytes
uninstall = run(image, quiet, "--uninstall", "--uninstall-data-file=" + str(backup))
passed = (install.returncode == 0 and valid_backup and same_install
and uninstall.returncode == 0 and image.read_bytes() == original)
results.append({"case": "backup and uninstall roundtrip", "quiet": quiet,
"install_exit": install.returncode,
"uninstall_exit": uninstall.returncode, "pass": passed})
print(json.dumps(results, indent=2))
sys.exit(0 if all(result["pass"] for result in results) else 1)
Expected and observed results
Both a nonexistent backup parent directory and a backup write to /dev/full produce an error diagnostic but exit status 0 on the baseline. This occurs with and without --quiet. The disk has already been modified, and the requested uninstall data has not been saved successfully.
Expected: a nonzero exit status, allowing callers to detect the failed requested backup. The prepared fix propagates the helper's failure through the existing cleanup path; it does not undo the completed installation.
The regression has eight cases. On the baseline, the four backup-failure cases fail and the normal-install and successful-backup/uninstall controls pass. All eight pass with the return-value check. The successful-backup control restores the original image byte-for-byte on uninstall.
I have prepared and tested the fix and will open its PR immediately after this issue.
Fixed on trunk by https://github.com/Limine-Bootloader/Limine/commit/cec5802e5dc8582938a3661ffe374b5499da17ca. It propagates the uninstall-data save failure, rolls back the installation, and prints success only after the backup has been saved. I closed #658 as superseded by this more complete fix.