From 0d5c018c3cda149f338277cf5b421dea2f1a76de Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Thu, 8 Nov 2018 23:09:14 -0500 Subject: [PATCH] fs: if search fails, return empty result set Make sure the result set is empty before running the ioctl in case something tries to consume the result without checking the error status. Signed-off-by: Zygo Blaxell --- lib/fs.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fs.cc b/lib/fs.cc index 2b2793d..69e398c 100644 --- a/lib/fs.cc +++ b/lib/fs.cc @@ -823,6 +823,8 @@ namespace crucible { ioctl_ptr->buf_size = m_buf_size; + m_result.clear(); + // Don't bother supporting V1. Kernels that old have other problems. int rv = ioctl(fd, BTRFS_IOC_TREE_SEARCH_V2, ioctl_ptr); if (rv != 0) { @@ -831,8 +833,6 @@ namespace crucible { static_cast(*this) = ioctl_ptr->key; - m_result.clear(); - size_t offset = pointer_distance(ioctl_ptr->buf, ioctl_ptr); for (decltype(nr_items) i = 0; i < nr_items; ++i) { BtrfsIoctlSearchHeader item;