summaryrefslogtreecommitdiff
path: root/lib/btrfs/btrfsitem/item_rootref.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-07-10 23:49:07 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-07-11 00:44:30 -0600
commitad9ac6d07ce1819260c2b7f090fd4fe742c80d9f (patch)
treeab6a607ea8575382c978f07de943ccf6c077de7c /lib/btrfs/btrfsitem/item_rootref.go
parent41ef03aabf8d6db4f926480fc5ddfec014e342d3 (diff)
Fuzz btrfsitem, and by consequence improve binstruct errors
Diffstat (limited to 'lib/btrfs/btrfsitem/item_rootref.go')
-rw-r--r--lib/btrfs/btrfsitem/item_rootref.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/btrfs/btrfsitem/item_rootref.go b/lib/btrfs/btrfsitem/item_rootref.go
index 228ab55..1ee0ee4 100644
--- a/lib/btrfs/btrfsitem/item_rootref.go
+++ b/lib/btrfs/btrfsitem/item_rootref.go
@@ -5,7 +5,10 @@
package btrfsitem
import (
+ "fmt"
+
"git.lukeshu.com/btrfs-progs-ng/lib/binstruct"
+ "git.lukeshu.com/btrfs-progs-ng/lib/binstruct/binutil"
"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/internal"
)
@@ -18,10 +21,20 @@ type RootRef struct { // ROOT_REF=156 ROOT_BACKREF=144
}
func (o *RootRef) UnmarshalBinary(dat []byte) (int, error) {
+ if err := binutil.NeedNBytes(dat, 0x12); err != nil {
+ return 0, err
+ }
n, err := binstruct.UnmarshalWithoutInterface(dat, o)
if err != nil {
return n, err
}
+ if o.NameLen > MaxNameLen {
+ return 0, fmt.Errorf("maximum name len is %v, but .NameLen=%v",
+ MaxNameLen, o.NameLen)
+ }
+ if err := binutil.NeedNBytes(dat, 0x12+int(o.NameLen)); err != nil {
+ return 0, err
+ }
o.Name = dat[n : n+int(o.NameLen)]
n += int(o.NameLen)
return n, nil