Skip to contentSkip to conversation

btrfs-progs: process_snapshot: don't free ERR

PATCH In review Dāvis Mosāns 3 participants 3 messages Jan 2, 2022 – Jan 3, 2022 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: process_snapshot: don't free ERR

When some error happens when trying to search for parent subvolume then parent_subvol will contain errno so don't try to free that

Crash backtrace would look like:
0 process_snapshot at cmds/receive.c:358

    358		free(parent_subvol->path);
1  0x00005646898aaa67 in read_and_process_cmd at common/send-stream.c:348
2  btrfs_read_and_process_send_stream at common/send-stream.c:525
3  0x00005646898c9b8b in do_receive at cmds/receive.c:1113
4  cmd_receive at cmds/receive.c:1316
5  0x00005646898750b1 in cmd_execute at cmds/commands.h:125
6  main at btrfs.c:405

(gdb) p parent_subvol
$1 = (struct subvol_info *) 0xfffffffffffffffe

---
 cmds/receive.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmds/receive.c +1 -1
index 4d123a1f..d106e554 100644
@@ -354,7 +354,7 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
 	}
 
 out:
-	if (parent_subvol) {
+	if (!IS_ERR_OR_NULL(parent_subvol)) {
 		free(parent_subvol->path);
 		free(parent_subvol);
 	}
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Dāvis Mosāns

When some error happens when trying to search for parent subvolume then parent_subvol will contain errno so don't try to free that

Crash backtrace would look like:
0 process_snapshot at cmds/receive.c:358

     358		free(parent_subvol->path);
1  0x00005646898aaa67 in read_and_process_cmd at common/send-stream.c:348
2  btrfs_read_and_process_send_stream at common/send-stream.c:525
3  0x00005646898c9b8b in do_receive at cmds/receive.c:1113
4  cmd_receive at cmds/receive.c:1316
5  0x00005646898750b1 in cmd_execute at cmds/commands.h:125
6  main at btrfs.c:405
Quoted 4 lines

(gdb) p parent_subvol
$1 = (struct subvol_info *) 0xfffffffffffffffe

Good catch.

Thanks,
Qu

Quoted 16 lines
---
  cmds/receive.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
cmds/receive.c +1 -1
index 4d123a1f..d106e554 100644
@@ -354,7 +354,7 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
  	}
 
  out:
-	if (parent_subvol) {
+	if (!IS_ERR_OR_NULL(parent_subvol)) { >   		free(parent_subvol->path);
  		free(parent_subvol);
  	}
#2 lore raw
In reply to Dāvis Mosāns
Quoted 13 lines · Dāvis Mosāns

When some error happens when trying to search for parent subvolume then parent_subvol will contain errno so don't try to free that

Crash backtrace would look like:
0 process_snapshot at cmds/receive.c:358

    358		free(parent_subvol->path);
1  0x00005646898aaa67 in read_and_process_cmd at common/send-stream.c:348
2  btrfs_read_and_process_send_stream at common/send-stream.c:525
3  0x00005646898c9b8b in do_receive at cmds/receive.c:1113
4  cmd_receive at cmds/receive.c:1316
5  0x00005646898750b1 in cmd_execute at cmds/commands.h:125
6  main at btrfs.c:405
Quoted 4 lines

(gdb) p parent_subvol
$1 = (struct subvol_info *) 0xfffffffffffffffe

Added to devel, thanks.