From 4ad65fc3586dabb4e3bb9377e215a8abf39b0a46 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 21 Feb 2020 01:36:39 +0100 Subject: [PATCH] fix panic on single-character volumes Before this change, this would cause a panic: docker run -it --rm -v 1:/1 alpine panic: runtime error: index out of range goroutine 1 [running]: github.com/docker/cli/cli/compose/loader.isFilePath(0xc42027e058, 0x1, 0x557dcb978c20) ... After this change, a correct error is returned: docker run -it --rm -v 1:/1 alpine docker: Error response from daemon: create 1: volume name is too short, names should be at least two alphanumeric characters. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 11869fa42a630dd8dc540388669631f33b76fb20) Signed-off-by: Sebastiaan van Stijn --- cli/compose/loader/volume.go | 3 +++ cli/compose/loader/volume_test.go | 2 ++ 2 files changed, 5 insertions(+) diff --git a/cli/compose/loader/volume.go b/cli/compose/loader/volume.go index 9c2792e0f7..f043f4aa57 100644 --- a/cli/compose/loader/volume.go +++ b/cli/compose/loader/volume.go @@ -111,6 +111,9 @@ func isFilePath(source string) bool { case '.', '/', '~': return true } + if len([]rune(source)) == 1 { + return false + } // windows named pipes if strings.HasPrefix(source, `\\`) { diff --git a/cli/compose/loader/volume_test.go b/cli/compose/loader/volume_test.go index 7be0411db9..b42be1fc52 100644 --- a/cli/compose/loader/volume_test.go +++ b/cli/compose/loader/volume_test.go @@ -162,6 +162,8 @@ func TestParseVolumeWindowsNamedPipe(t *testing.T) { func TestIsFilePath(t *testing.T) { assert.Check(t, !isFilePath("a界")) + assert.Check(t, !isFilePath("1")) + assert.Check(t, !isFilePath("c")) } // Preserve the test cases for VolumeSplitN