Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fuzzing issues #473

Merged
merged 1 commit into from
Aug 4, 2023
Merged

Fix fuzzing issues #473

merged 1 commit into from
Aug 4, 2023

Conversation

loosebazooka
Copy link
Member

@loosebazooka loosebazooka commented Aug 3, 2023

  • handle invalid json for rekor response
  • handle bundle with no tlog entry

@loosebazooka loosebazooka requested a review from vlsi August 3, 2023 18:28
@loosebazooka loosebazooka changed the title Catch json parse exception in rekor response Fix fuzzing issues Aug 3, 2023
try {
entryMap = GSON.get().fromJson(rawResponse, type);
} catch (JsonSyntaxException jse) {
throw new RekorParseException("Rekor entry json could not be parsed", jse);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT of mentioning the problematic response in the error message?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the stack trace should show it? but yeah I can just do jse.getMessage() too. I'll add that in.

vlsi
vlsi previously approved these changes Aug 3, 2023
@loosebazooka
Copy link
Member Author

turns out parsing bad data can create npes too.

@loosebazooka
Copy link
Member Author

I think we can logger.error the whole rekor response? Is that what you were kinda looking for?

@loosebazooka loosebazooka force-pushed the fix-a-fuzzing-issue branch 3 times, most recently from 742382d to d1e75d2 Compare August 4, 2023 00:12
@loosebazooka loosebazooka requested a review from vlsi August 4, 2023 12:22
Comment on lines 66 to 68
log.severe("Rekor entry could not be parsed");
log.severe(rawResponse);
throw new RekorParseException("Rekor entry json could not be parsed: " + ex.getMessage(), ex);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging messages as several lines would be hard to analyze.
I suggest skip logging here.

Suggested change
log.severe("Rekor entry could not be parsed");
log.severe(rawResponse);
throw new RekorParseException("Rekor entry json could not be parsed: " + ex.getMessage(), ex);
throw new RekorParseException("Rekor entry json could not be parsed: " + rawResponse, ex);

ex.getMessage() would be automatically included as a part of Caused by:..., so explicitly concatenating ex.getMessage() is not useful.

Copy link
Member Author

@loosebazooka loosebazooka Aug 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm... I imagine that response could be pretty huge, but whatever, this appears to be a pretty edge error case.

- Catch parsing exceptions when handling rekor response
- Check bundle before reading first tlog entry

Signed-off-by: Appu Goundan <appu@google.com>
Map<String, RekorEntry> entryMap;
try {
entryMap = GSON.get().fromJson(rawResponse, type);
} catch (JsonSyntaxException | NullPointerException | StringIndexOutOfBoundsException ex) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should report npe to gson team

@loosebazooka
Copy link
Member Author

I think fuzzing caught a number format exception issue, but I'll fix that in a followup.

@loosebazooka loosebazooka merged commit 59dae85 into main Aug 4, 2023
@loosebazooka loosebazooka deleted the fix-a-fuzzing-issue branch August 4, 2023 17:38
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.

2 participants