Repository navigation
fix(helpers): prevent panic in AllPkgTreeToPurl on empty namespaces or names - #3292
vishnums2k5 wants to merge 1 commit into
Conversation
…r names AllPkgTreeToPurl unconditionally indexed v.Namespaces[0] and ns.Names[0]. When the graph returns a package tree with no namespaces or no names (e.g. a type-level node from a sparse query), the function panicked with an index-out-of-range error, crashing the guacrest endpoints that call it. Add nil and empty-slice guards so the function returns an empty string instead of panicking. Also simplify the version lookup to use the already-bound name variable instead of re-indexing from the root. Signed-off-by: vishnums2k5 <vishnusajeev2005@gmail.com>
2024934 to
103925a
Compare
mihaimaruseac
left a comment
There was a problem hiding this comment.
This doesn't look like a scenario that happens in practice
Thank you for the review, mihaimaruseac. You're right that the current callers (e.g. pkgVersionIDs) filter to I also noticed that retrieveSboms.go already guards the call site Would it be more useful to close this PR and instead:
Happy to rework the PR in that direction if that would be more |
Description of the PR
AllPkgTreeToPurlunconditionally indexedv.Namespaces[0]andns.Names[0]. When the graph returns a package tree with no namespacesor no names (e.g. a type-level node from a sparse query), the function
panicked with an index-out-of-range error, crashing any
guacrestendpoint that calls it.
This PR adds nil and empty-slice guards so the function returns an empty
string instead of panicking, and simplifies the version lookup to use
the already-bound
namevariable rather than re-indexing from the root.Three new table-driven test cases cover: nil input, empty Namespaces
slice, and a namespace with an empty Names slice.
PR Checklist
-sflag togit commit.make generatehas been runmake generatehas been runmake generatehas been runcollectsubprotobuf has been changed,make protohas been run