From ff662963781c0b9e32c85c6cf725533b61af2bc7 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sun, 3 Aug 2025 15:35:32 +0900 Subject: container/mount: mount data escape helper function For formatting user-supplied path strings into overlayfs mount data. Signed-off-by: Ophestra --- container/mount.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'container/mount.go') diff --git a/container/mount.go b/container/mount.go index 7ee614b4..fc0e177f 100644 --- a/container/mount.go +++ b/container/mount.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "strings" . "syscall" "hakurei.app/container/vfs" @@ -183,3 +184,20 @@ func parentPerm(perm os.FileMode) os.FileMode { } return os.FileMode(pperm) } + +// escapeOverlayDataSegment escapes a string for formatting into the data argument of an overlay mount call. +func escapeOverlayDataSegment(s string) string { + if s == zeroString { + return zeroString + } + + if f := strings.SplitN(s, "\x00", 2); len(f) > 0 { + s = f[0] + } + + return strings.NewReplacer( + `\`, `\\`, + `,`, `\,`, + `:`, `\:`, + ).Replace(s) +} -- cgit v1.3.1