Skip to content

Commit 601a072

Browse files
Escape RequiresMountsFor value
Signed-off-by: Dmitry Konishchev <[email protected]>
1 parent c8ba67f commit 601a072

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

pkg/systemd/parser/unitfile.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,15 @@ func (f *UnitFile) Add(groupName string, key string, value string) {
879879
group.add(key, value)
880880
}
881881

882+
func (f *UnitFile) AddEscaped(groupName string, key string, value string) {
883+
if wordNeedEscape(value) {
884+
var escaped strings.Builder
885+
appendEscapeWord(&escaped, value)
886+
value = escaped.String()
887+
}
888+
f.Add(groupName, key, value)
889+
}
890+
882891
func (f *UnitFile) AddCmdline(groupName string, key string, args []string) {
883892
f.Add(groupName, key, escapeWords(args))
884893
}

pkg/systemd/quadlet/quadlet.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ func ConvertVolume(volume *parser.UnitFile, unitsInfoMap map[string]*UnitInfo, i
11511151
if devValid {
11521152
podman.add("--opt", fmt.Sprintf("type=%s", devType))
11531153
if devType == "bind" {
1154-
service.Add(UnitGroup, "RequiresMountsFor", dev)
1154+
service.AddEscaped(UnitGroup, "RequiresMountsFor", dev)
11551155
}
11561156
} else {
11571157
return nil, warnings, fmt.Errorf("key Type can't be used without Device")
@@ -1929,7 +1929,7 @@ func handleStorageSource(quadletUnitFile, serviceUnitFile *parser.UnitFile, sour
19291929
}
19301930
if source[0] == '/' {
19311931
// Absolute path
1932-
serviceUnitFile.Add(UnitGroup, "RequiresMountsFor", source)
1932+
serviceUnitFile.AddEscaped(UnitGroup, "RequiresMountsFor", source)
19331933
} else if strings.HasSuffix(source, ".volume") || (checkImage && strings.HasSuffix(source, ".image")) || strings.HasSuffix(source, ".artifact") {
19341934
sourceUnitInfo, ok := unitsInfoMap[source]
19351935
if !ok {

test/e2e/quadlet/mount.container

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
[Container]
22
Image=localhost/imagename
3+
## assert-has-key Unit RequiresMountsFor "/path/on/host"
34
## assert-podman-args-key-val "--mount" "," "type=bind,source=/path/on/host,destination=/path/in/container"
45
Mount=type=bind,source=/path/on/host,destination=/path/in/container
6+
## assert-has-key Unit RequiresMountsFor "\"/path/on/host\\x20with\\x20spaces\""
7+
## assert-podman-args-key-val "--mount" "," "type=bind,source=/path/on/host with spaces,dst=/path"
8+
Mount="type=bind,src=/path/on/host with spaces,dst=/path"
59
## assert-podman-args-key-val "--mount" "," "type=bind,source=/path/on/host,dst=/path/in/container,relabel=shared"
610
Mount=type=bind,src=/path/on/host,dst=/path/in/container,relabel=shared
711
## assert-podman-args-key-val "--mount" "," "type=bind,source=/path/on/host,dst=/path/in/container,relabel=shared,U=true"

0 commit comments

Comments
 (0)