Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 7cdc0a4

Browse files
authored
Merge pull request #454 from thaJeztah/19.03_backport_lgetxattr_panic
[19.03 backport] Fix possible runtime panic in Lgetxattr Upstream-commit: 69098f05cf0f61a1e8ff5f21075adc45288166dd Component: engine
2 parents 78567fe + 2da9c24 commit 7cdc0a4

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

components/engine/pkg/system/xattrs_linux.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,28 @@ import "golang.org/x/sys/unix"
66
// and associated with the given path in the file system.
77
// It will returns a nil slice and nil error if the xattr is not set.
88
func Lgetxattr(path string, attr string) ([]byte, error) {
9+
// Start with a 128 length byte array
910
dest := make([]byte, 128)
1011
sz, errno := unix.Lgetxattr(path, attr, dest)
11-
if errno == unix.ENODATA {
12+
13+
switch {
14+
case errno == unix.ENODATA:
1215
return nil, nil
13-
}
14-
if errno == unix.ERANGE {
16+
case errno == unix.ERANGE:
17+
// 128 byte array might just not be good enough. A dummy buffer is used
18+
// to get the real size of the xattrs on disk
19+
sz, errno = unix.Lgetxattr(path, attr, []byte{})
20+
if errno != nil {
21+
return nil, errno
22+
}
1523
dest = make([]byte, sz)
1624
sz, errno = unix.Lgetxattr(path, attr, dest)
17-
}
18-
if errno != nil {
25+
if errno != nil {
26+
return nil, errno
27+
}
28+
case errno != nil:
1929
return nil, errno
2030
}
21-
2231
return dest[:sz], nil
2332
}
2433

0 commit comments

Comments
 (0)