From 975710f1451df0139ec444e471d384ca34361d97 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 1 Nov 2025 10:23:41 +0100 Subject: [PATCH] remote: guard against (very unlikely) truncation when reading symlink target --- remote/sync/files.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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] } -- 2.51.2