Skip to content

Commit

Permalink
fix panic on single-character volumes
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
thaJeztah committed Feb 21, 2020
1 parent 2a6caf2 commit 11869fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cli/compose/loader/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, `\\`) {
Expand Down
2 changes: 2 additions & 0 deletions cli/compose/loader/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11869fa

Please sign in to comment.