]> git.hungrycats.org Git - btrfs-progs/commitdiff
btrfs-progs: image: fix overwritten ret in restore_metadump()
authorQu Wenruo <wqu@suse.com>
Sun, 25 Oct 2026 08:41:43 +0000 (19:11 +1030)
committerQu Wenruo <wqu@suse.com>
Mon, 26 Oct 2026 21:38:10 +0000 (08:08 +1030)
In the "while(!mdrestore.error) {}" loop if we got a bad header or
add_cluster() failed, we break the loop.

But immediately after breaking out the loop, we call wait_for_worker(),
which overwrites @ret, and also continue to open_ctree().

Fix the problem by directly jumping to out label.
Also for bad header case, update the error code to -EUCLEAN.

Assisted-by: LLM (exposing the bug)
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
image/image-restore.c

index 4929beeb697e70c92682bd9f496d21ff51493e9f..3f2a7fcf797cefd54005bd68a0a806ddc76b4408 100644 (file)
@@ -1852,13 +1852,13 @@ int restore_metadump(const char *input, FILE *out, int old_restore,
                if (get_unaligned_le64(&header->magic) != current_version->magic_cpu ||
                    get_unaligned_le64(&header->bytenr) != bytenr) {
                        error("bad header in metadump image");
-                       ret = -EIO;
-                       break;
+                       ret = -EUCLEAN;
+                       goto out;
                }
                ret = add_cluster(cluster, &mdrestore, &bytenr);
                if (ret) {
                        error("failed to add cluster: %d", ret);
-                       break;
+                       goto out;
                }
        }
        ret = wait_for_worker(&mdrestore);