fix(layout): guard VulnerabilitiesTable against a short row - #670
Open
arpitjain099 wants to merge 1 commit into
Open
fix(layout): guard VulnerabilitiesTable against a short row#670arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
rows is a [2][]string, so len(rows) is always 2 and len(rows) != 2 is always false. With the && that makes the whole guard condition always false, so it never returns and the function goes on to index rows[1][0] through rows[1][4] unconditionally. A second row with fewer than 5 columns is then an index out of range panic. Switch the operator to || so the guard does what it was written for: return an empty string unless the second row has the 5 columns the code reads. The current caller in ticketLayout.go always passes 5 columns, so this doesn't change existing behavior; it just stops the exported helper from panicking on a shorter row. Add a test that passes a 3-column row (panics before this change, returns "" after) and one that confirms a full 5-column row still renders. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The guard at the top of
VulnerabilitiesTablecan't actually reject a bad row.rowsis a[2][]string, solen(rows)is always 2 andlen(rows) != 2is always false. With the&&that makes the whole condition always false, so the guard never returns and the function goes on to indexrows[1][0]throughrows[1][4]unconditionally. If the second row has fewer than 5 columns that is an index out of range panic.Switching the operator to
||makes the check do what it was written for: bail out with an empty string unless the second row has the 5 columns the code reads. The current caller inticketLayout.goalways passes 5 columns, so this doesn't change existing behavior, it just stops the exported helper from panicking on a shorter row.Added a small test that passes a 3-column row (panics before this change, returns "" after) plus one that confirms a full 5-column row still renders.
go test ./layout/is green.I do supply-chain-security contributions across open-source projects; happy to adjust if you'd prefer a different guard shape.