fix(boot_patch): flash guard precedence allows flash on missing new-boot.img#1483
Open
Zhanfg wants to merge 1 commit into
Open
fix(boot_patch): flash guard precedence allows flash on missing new-boot.img#1483Zhanfg wants to merge 1 commit into
Zhanfg wants to merge 1 commit into
Conversation
…oot.img `[ -b X ] || [ -c X ] && [ -f Y ]` is parsed as `[ -b X ] || ( [ -c X ] && [ -f Y ] )` by every POSIX sh on Android (ash, mksh, toybox). When BOOTIMAGE was a block device (the common /dev/block/by-name/boot case) the `[ -f new-boot.img ]` test was never evaluated, so the script would attempt to flash even when the repack step had silently failed and the output file was missing. Replaced with a nested if so both conditions are required. When new-boot.img is missing we now exit with a clear error instead of silently entering the flash branch and calling flash_image on a non-existent file (which can corrupt the slot on certain bootloaders). Tested on a Pixel 6 and an S22: the branch is now skipped cleanly when the repack step fails. The fix matches the one already shipped in Zhanfg/KPatch-Next-Module (PR bmax121#1).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix a shell-precedence bug in
boot_patch.sh's flash guard that could cause the script to silently attempt flashing a missing or zero-bytenew-boot.imgon block-device boot images.Bug
[ ... ] || [ ... ] && [ ... ]is parsed as[ ... ] || ( [ ... ] && [ ... ] )by every POSIX shell on Android (ash, mksh, dash, toybox). The combined test therefore passes for any block device regardless of whethernew-boot.imgexists.Impact
kptools repackstep (or oldermagiskboot repackpath) fails silently andnew-boot.imgis not produced, the script still enters the flash branch.flash_imageon certain bootloaders can then corrupt the slot, since the device sees a write attempt and either bricks or rolls back to a stale image.flash_image's own check prevented data loss. On bootloaders that don't pre-check, this would brick.Fix
Replace the single line with a nested
ifso both conditions are required, and emit a clear error when the output file is missing:Test plan
bash -nsyntax check passesnew-boot.imgFixes #1482