]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
remote: guard against (very unlikely) truncation when reading symlink target
authorSimon Ruderich <simon@ruderich.org>
Sat, 1 Nov 2025 09:23:41 +0000 (10:23 +0100)
committerSimon Ruderich <simon@ruderich.org>
Sat, 1 Nov 2025 09:29:44 +0000 (10:29 +0100)
remote/sync/files.go

index 3f0f19652aed1abe298a850f239fb735691e7643..4ccca5d09843c0c899bceb083c7c5892abc3382f 100644 (file)
@@ -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]
                }