diff --git a/tests/extract-vendor-firmware b/tests/extract-vendor-firmware index a4b13271f..a2adf3416 100755 --- a/tests/extract-vendor-firmware +++ b/tests/extract-vendor-firmware @@ -17,7 +17,8 @@ # refused before anything is written; and a move that fails while # publishing puts the previous outputs back. With mkfs.ext4 # and debugfs on the host, the same on a real ext4 image whose registry -# belongs to root, and a copy that a file size limit cuts short. EVF=path +# belongs to root, work and output paths with a space and a double quote +# in them, and a copy that a file size limit cuts short. EVF=path # runs another copy of the tool (a negative control), so every check runs # and the failures are counted rather than stopping at the first. set -euo pipefail @@ -43,6 +44,7 @@ cat > "$t/bin/debugfs" <<'EOF' set -u echo "debugfs 1.47.2 (stand-in)" >&2 read -r cmd src out <<<"$2" +out=${out#\"}; out=${out%\"}; out=${out//\"\"/\"} # debugfs's quoting if [[ -f $FAKE_VENDOR/.fail-dump && $src == "/$(cat "$FAKE_VENDOR/.fail-dump")" ]] || [[ $cmd == rdump && -f $FAKE_VENDOR/.fail-rdump ]]; then if [[ $cmd == dump ]]; then @@ -337,6 +339,14 @@ if realdfs=$(command -v debugfs) && mkfs.ext4 -q -F -d "$t/v2" "$t/real.img" 8M else cat "$t/log"; fail "real ext4: a second run keeps nothing from the earlier generation" fi + sp=$t/'a "spaced" dir' + if "$EVF" -w "$sp/work" -o "$sp/out" "$t/real.img" > "$t/log" 2>&1 && + grep -cF "Vendor partition: fictional/gen2" "$t/log" >/dev/null && + [[ $(listed "$sp/out") == "$CHEETAH_FILES" && $(cat "$sp/out/$FW/aoc.bin") == "aoc gen2" ]]; then + pass "real ext4: work and output paths with a space and a quote" + else + cat "$t/log"; fail "real ext4: work and output paths with a space and a quote" + fi before=$(snap "$o") if "$EVF" -w "$t/work" -o "$o" "$t/real-missing.img" > "$t/log" 2>&1; then fail "real ext4: a missing file with an older copy in OUT is refused" diff --git a/tools/extract-camera-data b/tools/extract-camera-data index c8f2f58d3..c151689c1 100755 --- a/tools/extract-camera-data +++ b/tools/extract-camera-data @@ -1753,10 +1753,15 @@ def build_phy_zumapro(emu, ctle=None): return sects +def dq(path): + """A host path in debugfs's command syntax, which splits at blanks.""" + return '"' + path.replace('"', '""') + '"' + + def from_apex_settings(apex, tmp): out = os.path.join(tmp, "csis_phy_link_phy_settings.binarypb") subprocess.run(["debugfs", "-R", - f"dump /etc/camera/csis_phy_link_phy_settings.binarypb {out}", + f"dump /etc/camera/csis_phy_link_phy_settings.binarypb {dq(out)}", os.path.join(tmp, "apex_payload.img")], check=True, stderr=subprocess.DEVNULL) if not os.path.exists(out) or not os.path.getsize(out): @@ -1767,7 +1772,7 @@ def from_apex_settings(apex, tmp): def from_apex(apex, tmp): subprocess.run(["unzip", "-q", "-o", apex, "apex_payload.img", "-d", tmp], check=True) out = os.path.join(tmp, "liblyric_hwl.so") - subprocess.run(["debugfs", "-R", f"dump /lib64/liblyric_hwl.so {out}", + subprocess.run(["debugfs", "-R", f"dump /lib64/liblyric_hwl.so {dq(out)}", os.path.join(tmp, "apex_payload.img")], check=True, stderr=subprocess.DEVNULL) if not os.path.getsize(out): diff --git a/tools/extract-fingerprint-vendor b/tools/extract-fingerprint-vendor index 7a3c1d279..e00ee35dd 100755 --- a/tools/extract-fingerprint-vendor +++ b/tools/extract-fingerprint-vendor @@ -179,11 +179,15 @@ fetch_images() { is_ext4() { [[ "$(od -An -tx2 -j 1080 -N2 "$1" | tr -d ' ')" == ef53 ]]; } +# debugfs splits its command at blanks: a host path goes in double quotes, +# with any double quote in it doubled +dq() { printf '"%s"' "${1//\"/\"\"}"; } + # rdump one path ($2, no leading /) from ext4 image $1 into directory $3. # Symlinks are kept as symlinks. rdump() { mkdir -p "$3" - debugfs -R "rdump /$2 $3" "$1" 2>&1 | + debugfs -R "rdump /$2 $(dq "$3")" "$1" 2>&1 | grep -v -e '^debugfs ' -e 'Operation not permitted while changing ownership' >&2 || true } @@ -195,7 +199,7 @@ done # The vendor partition says which device it was built for. mkdir -p "$WORK/v" -debugfs -R "dump /build.prop $WORK/v/build.prop" "$WORK/vendor.img" 2>/dev/null +debugfs -R "dump /build.prop $(dq "$WORK/v/build.prop")" "$WORK/vendor.img" 2>/dev/null [[ -s "$WORK/v/build.prop" ]] || die "vendor.img has no build.prop" dev=$(sed -n 's/^ro.product.vendor.device=//p' "$WORK/v/build.prop" | head -1) [[ "$dev" == "$DEVICE" || -n "$FORCE" ]] || @@ -211,11 +215,11 @@ say "Reading the system partition" mkdir -p "$WORK/s/system" for d in bin lib64 etc apex; do [[ $d == apex ]] && { mkdir -p "$WORK/s/system/apex" - debugfs -R "dump /system/apex/com.android.runtime.apex $WORK/s/system/apex/com.android.runtime.apex" \ + debugfs -R "dump /system/apex/com.android.runtime.apex $(dq "$WORK/s/system/apex/com.android.runtime.apex")" \ "$WORK/system.img" 2>/dev/null; continue; } rdump "$WORK/system.img" "system/$d" "$WORK/s/system" done -debugfs -R "dump /system/build.prop $WORK/s/system/build.prop" "$WORK/system.img" 2>/dev/null +debugfs -R "dump /system/build.prop $(dq "$WORK/s/system/build.prop")" "$WORK/system.img" 2>/dev/null [[ -s "$WORK/s/$RUNTIME_APEX" ]] || die "no $RUNTIME_APEX in system.img" say "Reading com.android.runtime" diff --git a/tools/extract-vendor-chroot b/tools/extract-vendor-chroot index 088d4caa7..a552ec5dd 100755 --- a/tools/extract-vendor-chroot +++ b/tools/extract-vendor-chroot @@ -275,11 +275,15 @@ fetch_images() { is_ext4() { [[ "$(od -An -tx2 -j 1080 -N2 "$1" | tr -d ' ')" == ef53 ]]; } +# debugfs splits its command at blanks: a host path goes in double quotes, +# with any double quote in it doubled +dq() { printf '"%s"' "${1//\"/\"\"}"; } + # rdump one path ($2, no leading /) from ext4 image $1 into directory $3. # Symlinks are kept as symlinks. rdump() { mkdir -p "$3" - debugfs -R "rdump /$2 $3" "$1" 2>&1 | + debugfs -R "rdump /$2 $(dq "$3")" "$1" 2>&1 | grep -v -e '^debugfs ' -e 'Operation not permitted while changing ownership' >&2 || true } @@ -291,7 +295,7 @@ done # The vendor partition says which device it was built for. mkdir -p "$WORK/v" -debugfs -R "dump /build.prop $WORK/v/build.prop" "$WORK/vendor.img" 2>/dev/null +debugfs -R "dump /build.prop $(dq "$WORK/v/build.prop")" "$WORK/vendor.img" 2>/dev/null [[ -s "$WORK/v/build.prop" ]] || die "vendor.img has no build.prop" dev=$(sed -n 's/^ro.product.vendor.device=//p' "$WORK/v/build.prop" | head -1) [[ "$dev" == "$DEVICE" || -n "$FORCE" ]] || @@ -307,11 +311,11 @@ say "Reading the system partition" mkdir -p "$WORK/s/system" for d in bin lib64 etc apex; do [[ $d == apex ]] && { mkdir -p "$WORK/s/system/apex" - debugfs -R "dump /system/apex/com.android.runtime.apex $WORK/s/system/apex/com.android.runtime.apex" \ + debugfs -R "dump /system/apex/com.android.runtime.apex $(dq "$WORK/s/system/apex/com.android.runtime.apex")" \ "$WORK/system.img" 2>/dev/null; continue; } rdump "$WORK/system.img" "system/$d" "$WORK/s/system" done -debugfs -R "dump /system/build.prop $WORK/s/system/build.prop" "$WORK/system.img" 2>/dev/null +debugfs -R "dump /system/build.prop $(dq "$WORK/s/system/build.prop")" "$WORK/system.img" 2>/dev/null [[ -s "$WORK/s/$RUNTIME_APEX" ]] || die "no $RUNTIME_APEX in system.img" say "Reading com.android.runtime" diff --git a/tools/extract-vendor-firmware b/tools/extract-vendor-firmware index f8d3010e9..8558d0f5b 100755 --- a/tools/extract-vendor-firmware +++ b/tools/extract-vendor-firmware @@ -372,8 +372,11 @@ if [[ "$(od -An -tx2 -j 1080 -N2 "$img" | tr -d ' ')" == ef53 ]]; then esac done } - get_file() { dfs "dump /$1 $2" && [[ -s "$2" ]]; } - get_dir() { mkdir -p "$2" && dfs "rdump /$1 $2" && [[ -d "$2/$(basename "$1")" ]]; } + # debugfs splits its command at blanks: a host path goes in double + # quotes, with any double quote in it doubled + dq() { printf '"%s"' "${1//\"/\"\"}"; } + get_file() { dfs "dump /$1 $(dq "$2")" && [[ -s "$2" ]]; } + get_dir() { mkdir -p "$2" && dfs "rdump /$1 $(dq "$2")" && [[ -d "$2/$(basename "$1")" ]]; } elif [[ "$(magic_at "$img" 1024)" == e0f5e1e2 ]]; then need fsck.erofs "install erofs-utils" say "vendor.img is EROFS; extracting it with fsck.erofs"