@cryptotaxi247 / kubo / commits / 9f03f1ff1

fix(unixfs): check for errors before dereferencing the link

If there's an error, the link will be nil, and this will panic.

Steven Allen committed Oct 12, 2021 at 12:39 UTC 9f03f1ff14c7f1b1d3461b2b4a6893f0c6ba992b
1 file changed +4 -4
core/coreapi/unixfs.go
+4 -4
@@ -217,13 +217,13 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p path.Path, opts ...options.Unixf
217 }
218
219 func (api *UnixfsAPI) processLink(ctx context.Context, linkres ft.LinkResult, settings *options.UnixfsLsSettings) coreiface.DirEntry {
220 + if linkres.Err != nil {
221 + return coreiface.DirEntry{Err: linkres.Err}
222 + }
223 +
224 lnk := coreiface.DirEntry{
225 Name: linkres.Link.Name,
226 Cid: linkres.Link.Cid,
223 - Err: linkres.Err,
224 - }
225 - if lnk.Err != nil {
226 - return lnk
227 }
228
229 switch lnk.Cid.Type() {