]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
btrfs-util: use memdup_suffix0() instead of strndup() at one more place
authorLennart Poettering <lennart@poettering.net>
Mon, 12 Feb 2024 14:32:25 +0000 (15:32 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 12 Feb 2024 14:35:11 +0000 (15:35 +0100)
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

index 57e11dc1a810d8c4f16413f99444d299b55ae1e0..b0ecf8f82045ad71507c0ad3d8a547200ff6300d 100644 (file)
@@ -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;