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

Avoid generating and parsing invalid JSON files #220

Merged
merged 2 commits into from
Dec 16, 2017

Conversation

kattrali
Copy link
Contributor

In the case that the crash state file fails to be written completely, avoid flushing the buffer as the file contents will be inconsistent. In addition, when parsing the file, add validation to avoid comparing a string to NULL.

To reproduce:

  • Install the sample app with v5.14.1 onto a device
  • Download the application container and show package contents
  • Change the contents of AppData/Library/Caches/KSCrashReport/{app name}-CrashState.json to 3 }. This triggers the code path where the file is invalid but it is not rejected before crashing.
  • Replace the app container on the device with the altered one
  • Restart app

Fixes #218

If there was a parsing error, the buffer has random stuff in it and
shouldn't be flushed to disk

Introduced in 9b0d3fb
If a string starting with an integer (but not solely an integer) is
passed as an argument to be decoded by the JSON parser, the parser will
crash because NULL is eventually handed to strcmp(3). Integers aren't
valid at the top level anyway.
@kattrali kattrali merged commit 292a227 into master Dec 16, 2017
@kattrali kattrali deleted the kattrali/patch-parsing-partial-file branch December 16, 2017 01:02
@jessesquires
Copy link

Thanks so much @kattrali ! 🙌

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