diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-04-17 08:07:09 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-04-17 19:52:26 -0600 |
commit | 1efce3f90371d12bbb429b1810ce3a5c53e4d4f6 (patch) | |
tree | f4eacb2ddad751fe663afa6c7c9df42df47ce516 /lib/btrfsutil/rebuilt_tree.go | |
parent | 1a979d52855911980acc0b6f366d808c5734c054 (diff) |
btrfsutil: RebuiltTree: Fix potential infinite loop in RebuiltCOWDistance
Diffstat (limited to 'lib/btrfsutil/rebuilt_tree.go')
-rw-r--r-- | lib/btrfsutil/rebuilt_tree.go | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/btrfsutil/rebuilt_tree.go b/lib/btrfsutil/rebuilt_tree.go index 3036938..a0f5932 100644 --- a/lib/btrfsutil/rebuilt_tree.go +++ b/lib/btrfsutil/rebuilt_tree.go @@ -506,11 +506,12 @@ func (tree *RebuiltTree) RebuiltAddRoot(ctx context.Context, rootNode btrfsvol.L // RebuiltCOWDistance returns how many COW-snapshots down the 'tree' // is from the 'parent'. func (tree *RebuiltTree) RebuiltCOWDistance(parentID btrfsprim.ObjID) (dist int, ok bool) { + root := tree.ancestorRoot for { if parentID == tree.ID { return dist, true } - if tree.Parent == nil { + if tree.Parent == nil || tree.ID == root { return 0, false } tree = tree.Parent |