nametransform: fix possible incomplete read in ReadLongNameAt
Pread() needs retry logic, so instead of implementing it ourselves,
use os.File.
Reported by @slackner at
c09bf1f228 (r31813394)
This commit is contained in:
parent
d5a74d2a3e
commit
d99a0480f7
@ -74,16 +74,21 @@ func IsLongContent(cName string) bool {
|
|||||||
// Symlink-safe through Openat().
|
// Symlink-safe through Openat().
|
||||||
func ReadLongNameAt(dirfd int, cName string) (string, error) {
|
func ReadLongNameAt(dirfd int, cName string) (string, error) {
|
||||||
cName += LongNameSuffix
|
cName += LongNameSuffix
|
||||||
|
var f *os.File
|
||||||
|
{
|
||||||
fd, err := syscallcompat.Openat(dirfd, cName, syscall.O_NOFOLLOW, 0)
|
fd, err := syscallcompat.Openat(dirfd, cName, syscall.O_NOFOLLOW, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
defer syscall.Close(fd)
|
f = os.NewFile(uintptr(fd), "")
|
||||||
|
// fd runs out of scope here
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
// 256 (=255 padded to 16) bytes base64-encoded take 344 bytes: "AAAAAAA...AAA=="
|
// 256 (=255 padded to 16) bytes base64-encoded take 344 bytes: "AAAAAAA...AAA=="
|
||||||
lim := 344
|
lim := 344
|
||||||
// Allocate a bigger buffer so we see whether the file is too big
|
// Allocate a bigger buffer so we see whether the file is too big
|
||||||
buf := make([]byte, lim+1)
|
buf := make([]byte, lim+1)
|
||||||
n, err := syscall.Pread(fd, buf, 0)
|
n, err := f.ReadAt(buf, 0)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user