Skip to content

fix(layout): guard VulnerabilitiesTable against a short row - #670

Open
arpitjain099 wants to merge 1 commit into
aquasecurity:mainfrom
arpitjain099:chore/vuln-table-short-row-guard
Open

fix(layout): guard VulnerabilitiesTable against a short row#670
arpitjain099 wants to merge 1 commit into
aquasecurity:mainfrom
arpitjain099:chore/vuln-table-short-row-guard

Conversation

@arpitjain099

Copy link
Copy Markdown

The guard at the top of VulnerabilitiesTable can't actually reject a bad row.

rows is a [2][]string, so len(rows) is always 2 and len(rows) != 2 is always false. With the && that makes the whole condition always false, so the guard never returns and the function goes on to index rows[1][0] through rows[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 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.

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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant