Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 1eae0fe

Browse files
committed
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 <github@gone.nl> (cherry picked from commit 11869fa42a630dd8dc540388669631f33b76fb20) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 4ad65fc3586dabb4e3bb9377e215a8abf39b0a46 Component: cli
1 parent e238f67 commit 1eae0fe

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

components/cli/cli/compose/loader/volume.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ func isFilePath(source string) bool {
111111
case '.', '/', '~':
112112
return true
113113
}
114+
if len([]rune(source)) == 1 {
115+
return false
116+
}
114117

115118
// windows named pipes
116119
if strings.HasPrefix(source, `\\`) {

components/cli/cli/compose/loader/volume_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ func TestParseVolumeWindowsNamedPipe(t *testing.T) {
162162

163163
func TestIsFilePath(t *testing.T) {
164164
assert.Check(t, !isFilePath("a界"))
165+
assert.Check(t, !isFilePath("1"))
166+
assert.Check(t, !isFilePath("c"))
165167
}
166168

167169
// Preserve the test cases for VolumeSplitN

0 commit comments

Comments
 (0)