From: Simon Ruderich Date: Sat, 1 Nov 2025 09:23:41 +0000 (+0100) Subject: remote: guard against (very unlikely) truncation when reading symlink target X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=975710f1451df0139ec444e471d384ca34361d97;p=safcm%2Fsafcm.git remote: guard against (very unlikely) truncation when reading symlink target --- diff --git a/remote/sync/files.go b/remote/sync/files.go index 3f0f196..4ccca5d 100644 --- a/remote/sync/files.go +++ b/remote/sync/files.go @@ -264,10 +264,16 @@ reopen: } oldData = x case fs.ModeSymlink: - buf := make([]byte, unix.PathMax) + buf := make([]byte, unix.PathMax+1) n, err := unix.Readlinkat(parentFd, baseName, buf) if err != nil { - return fmt.Errorf("reading old content: %v", err) + return fmt.Errorf("reading old target: %v", err) + } + if n == len(buf) { + // Cannot differentiate between exact match and truncation. + // This shouldn't occur with unix.PathMax but let's be + // careful. + return fmt.Errorf("old path possibly truncated") } oldData = buf[:n] }