service/rpc2: Fix panic in ListDynamicLibraries (#2586)

The slice `out.List` is created with a length of 0 but a capacity of
`len(imgs)`. This causes the line below to panic as we try to index into
the `out.List` slice instead of append to it. This patch resolves the
issue by appending instead of indexing into the slice.

Co-authored-by: Derek Parker <deparker@redhat.com>
This commit is contained in:
Derek Parker 2021-07-14 09:28:54 -07:00 committed by GitHub
parent f86ed675d8
commit 175ca0c769
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -838,7 +838,7 @@ func (s *RPCServer) ListDynamicLibraries(in ListDynamicLibrariesIn, out *ListDyn
imgs := s.debugger.ListDynamicLibraries()
out.List = make([]api.Image, 0, len(imgs))
for i := range imgs {
out.List[i] = api.ConvertImage(imgs[i])
out.List = append(out.List, api.ConvertImage(imgs[i]))
}
return nil
}