Fix out-of-bounds panic in dedupMounts

It looks like the intent is to keep track of the index in 'ret' where a
destination was written, but that's not what the current code is doing.

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
master
Aaron Lehmann 2021-12-10 09:25:15 -08:00
parent bfd3cfb6a0
commit 9534552955
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 {
ret := make([]specs.Mount, 0, len(mnts))
visited := make(map[string]int)
for i, mnt := range mnts {
for _, mnt := range mnts {
if j, ok := visited[mnt.Destination]; ok {
ret[j] = mnt
} else {
visited[mnt.Destination] = i
visited[mnt.Destination] = len(ret)
ret = append(ret, mnt)
}
}