From e5c41c6138a6f0fe1c47c0a1db15ec3113622492 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 12 Feb 2024 15:32:25 +0100 Subject: [PATCH] btrfs-util: use memdup_suffix0() instead of strndup() at one more place The structure we copy this out is a large (unaligned) binary blob, hence let's better use the memdup_suffix0() so that gcc doesn't make assumption about the source being a valid string. --- src/shared/btrfs-util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index 57e11dc1a81..b0ecf8f8204 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -970,7 +970,7 @@ static int subvol_remove_children(int fd, const char *subvolume, uint64_t subvol ref = BTRFS_IOCTL_SEARCH_HEADER_BODY(sh); - p = strndup((char*) ref + sizeof(struct btrfs_root_ref), le64toh(ref->name_len)); + p = memdup_suffix0((char*) ref + sizeof(struct btrfs_root_ref), le64toh(ref->name_len)); if (!p) return -ENOMEM; @@ -1345,7 +1345,7 @@ static int subvol_snapshot_children( continue; ref = BTRFS_IOCTL_SEARCH_HEADER_BODY(sh); - p = strndup((char*) ref + sizeof(struct btrfs_root_ref), le64toh(ref->name_len)); + p = memdup_suffix0((char*) ref + sizeof(struct btrfs_root_ref), le64toh(ref->name_len)); if (!p) return -ENOMEM; -- 2.47.3