mirror of
https://github.com/kdave/btrfs-progs
synced 2025-02-16 17:56:51 +00:00
libbtrfsutil: subvolume: use helpers to access search header
The test cli-tests/008-subvolume-get-set-default fails when compiled with 'D=ubsan', the access to search header items does not follow the type alignment, so use the accessors. The error: subvolume get-default: default id is not 256, but libbtrfsutil/subvolume.c:361:13: runtime error: member access within misaligned address 0x7ffc147e4b6f for type 'const struct btrfs_ioctl_search_header', which requires 8 byte alignment Note that using the accessors does not fix the ubsan warning, as it warns on taking the address of a member whose _base_ type is unaligned, ie. it's the 'sh'. Fixing that would need to play tricks with pointers to do &sh->type manually, but to avoid triggering ubsan. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
db1246039d
commit
4d29e37947
@ -358,7 +358,7 @@ static enum btrfs_util_error get_subvolume_info_privileged(int fd, uint64_t id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
header = (struct btrfs_ioctl_search_header *)(search.buf + buf_off);
|
header = (struct btrfs_ioctl_search_header *)(search.buf + buf_off);
|
||||||
if (header->type == BTRFS_ROOT_ITEM_KEY) {
|
if (btrfs_search_header_type(header) == BTRFS_ROOT_ITEM_KEY) {
|
||||||
if (subvol) {
|
if (subvol) {
|
||||||
const struct btrfs_root_item *root;
|
const struct btrfs_root_item *root;
|
||||||
|
|
||||||
@ -367,12 +367,12 @@ static enum btrfs_util_error get_subvolume_info_privileged(int fd, uint64_t id,
|
|||||||
}
|
}
|
||||||
need_root_item = false;
|
need_root_item = false;
|
||||||
search.key.min_type = BTRFS_ROOT_BACKREF_KEY;
|
search.key.min_type = BTRFS_ROOT_BACKREF_KEY;
|
||||||
} else if (header->type == BTRFS_ROOT_BACKREF_KEY) {
|
} else if (btrfs_search_header_type(header) == BTRFS_ROOT_BACKREF_KEY) {
|
||||||
if (subvol) {
|
if (subvol) {
|
||||||
const struct btrfs_root_ref *ref;
|
const struct btrfs_root_ref *ref;
|
||||||
|
|
||||||
ref = (const struct btrfs_root_ref *)(header + 1);
|
ref = (const struct btrfs_root_ref *)(header + 1);
|
||||||
subvol->parent_id = header->offset;
|
subvol->parent_id = btrfs_search_header_offset(header);
|
||||||
subvol->dir_id = le64_to_cpu(ref->dirid);
|
subvol->dir_id = le64_to_cpu(ref->dirid);
|
||||||
}
|
}
|
||||||
need_root_backref = false;
|
need_root_backref = false;
|
||||||
@ -380,7 +380,7 @@ static enum btrfs_util_error get_subvolume_info_privileged(int fd, uint64_t id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
items_pos++;
|
items_pos++;
|
||||||
buf_off += sizeof(*header) + header->len;
|
buf_off += sizeof(*header) + btrfs_search_header_len(header);
|
||||||
}
|
}
|
||||||
|
|
||||||
return BTRFS_UTIL_OK;
|
return BTRFS_UTIL_OK;
|
||||||
@ -1366,7 +1366,7 @@ static enum btrfs_util_error build_subvol_path_privileged(struct btrfs_util_subv
|
|||||||
size_t *path_len_ret)
|
size_t *path_len_ret)
|
||||||
{
|
{
|
||||||
struct btrfs_ioctl_ino_lookup_args lookup = {
|
struct btrfs_ioctl_ino_lookup_args lookup = {
|
||||||
.treeid = header->objectid,
|
.treeid = btrfs_search_header_objectid(header),
|
||||||
.objectid = le64_to_cpu(ref->dirid),
|
.objectid = le64_to_cpu(ref->dirid),
|
||||||
};
|
};
|
||||||
int ret;
|
int ret;
|
||||||
@ -1442,11 +1442,11 @@ static enum btrfs_util_error subvolume_iterator_next_tree_search(struct btrfs_ut
|
|||||||
header = (struct btrfs_ioctl_search_header *)(top->search.buf + top->buf_off);
|
header = (struct btrfs_ioctl_search_header *)(top->search.buf + top->buf_off);
|
||||||
|
|
||||||
top->items_pos++;
|
top->items_pos++;
|
||||||
top->buf_off += sizeof(*header) + header->len;
|
top->buf_off += sizeof(*header) + btrfs_search_header_len(header);
|
||||||
top->search.key.min_offset = header->offset + 1;
|
top->search.key.min_offset = btrfs_search_header_offset(header) + 1;
|
||||||
|
|
||||||
/* This shouldn't happen, but handle it just in case. */
|
/* This shouldn't happen, but handle it just in case. */
|
||||||
if (header->type != BTRFS_ROOT_REF_KEY)
|
if (btrfs_search_header_type(header) != BTRFS_ROOT_REF_KEY)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ref = (struct btrfs_root_ref *)(header + 1);
|
ref = (struct btrfs_root_ref *)(header + 1);
|
||||||
@ -1456,7 +1456,8 @@ static enum btrfs_util_error subvolume_iterator_next_tree_search(struct btrfs_ut
|
|||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
err = append_to_search_stack(iter, header->offset, path_len);
|
err = append_to_search_stack(iter,
|
||||||
|
btrfs_search_header_offset(header), path_len);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user