btrfs: send: fix is_current_inode_path() to avoid path resets for common prefixes

In case the current inode's path is a prefix of the given path, the helper
is_current_inode_path() will return true, which causes the single caller
to reset the current inode's path. While this is not a functional issue,
it makes the caller recompute the current inode's path later. It could
also become a problem in the future in case get new callers for
is_current_inode_path() in more sensitive contexts.

Example: the current inode path is "/foo/bar" and the path we compare
against is "/foo/bar_xyz".

Fix this by returning true only if we have exact matches.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Filipe Manana 2026-06-15 17:33:03 +01:00 committed by David Sterba
parent a4cea1272c
commit bd3dddec1b

View File

@ -625,9 +625,8 @@ static void fs_path_unreverse(struct fs_path *p)
static inline bool is_current_inode_path(const struct send_ctx *sctx,
const struct fs_path *path)
{
const struct fs_path *cur = &sctx->cur_inode_path;
return (strncmp(path->start, cur->start, fs_path_len(cur)) == 0);
/* Paths are always nul terminated. */
return (strcmp(path->start, sctx->cur_inode_path.start) == 0);
}
static struct btrfs_path *alloc_path_for_send(void)