Skip to content

Commit fe7afb7

Browse files
committed
cli/container: Don't ignore error when parsing volume spec
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
1 parent df04aca commit fe7afb7

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

‎cli/command/container/opts.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,10 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
358358
volumes := copts.volumes.GetMap()
359359
// add any bind targets to the list of container volumes
360360
for bind := range copts.volumes.GetMap() {
361-
parsed, _ := loader.ParseVolume(bind)
361+
parsed, err := loader.ParseVolume(bind)
362+
if err != nil {
363+
return nil, err
364+
}
362365

363366
if parsed.Source != "" {
364367
toBind := bind

‎cli/compose/loader/volume_test.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,8 @@ func TestParseVolumeInvalidSections(t *testing.T) {
223223
_, err := ParseVolume("/foo::rw")
224224
assert.ErrorContains(t, err, "invalid spec")
225225
}
226+
227+
func TestParseVolumeWithEmptySource(t *testing.T) {
228+
_, err := ParseVolume(":/vol")
229+
assert.ErrorContains(t, err, "empty section between colons")
230+
}

‎e2e/container/create_test.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,19 @@ func TestTrustedCreateFromBadTrustServer(t *testing.T) {
101101
Err: "could not rotate trust to a new trusted root",
102102
})
103103
}
104+
105+
func TestCreateWithEmptySourceVolume(t *testing.T) {
106+
icmd.RunCmd(icmd.Command("docker", "create", "-v", ":/volume", fixtures.AlpineImage)).
107+
Assert(t, icmd.Expected{
108+
ExitCode: 125,
109+
Err: "empty section between colons",
110+
})
111+
}
112+
113+
func TestCreateWithEmptyVolumeSpec(t *testing.T) {
114+
icmd.RunCmd(icmd.Command("docker", "create", "-v", "", fixtures.AlpineImage)).
115+
Assert(t, icmd.Expected{
116+
ExitCode: 125,
117+
Err: "invalid empty volume spec",
118+
})
119+
}

0 commit comments

Comments
 (0)