Merge pull request #2519 from aaronlehmann/dedup-mounts-panic

Fix out-of-bounds panic in dedupMounts
master
Tõnis Tiigi 2021-12-10 10:53:15 -08:00 committed by GitHub
commit e89482149f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -104,11 +104,11 @@ func withBoundProc() oci.SpecOpts {
func dedupMounts(mnts []specs.Mount) []specs.Mount { func dedupMounts(mnts []specs.Mount) []specs.Mount {
ret := make([]specs.Mount, 0, len(mnts)) ret := make([]specs.Mount, 0, len(mnts))
visited := make(map[string]int) visited := make(map[string]int)
for i, mnt := range mnts { for _, mnt := range mnts {
if j, ok := visited[mnt.Destination]; ok { if j, ok := visited[mnt.Destination]; ok {
ret[j] = mnt ret[j] = mnt
} else { } else {
visited[mnt.Destination] = i visited[mnt.Destination] = len(ret)
ret = append(ret, mnt) ret = append(ret, mnt)
} }
} }