Skip to content

Commit

Permalink
Fix buffer overrun in SimpleParser::handleBackslash
Browse files Browse the repository at this point in the history
Summary:
It read 4 chars, then checked for validity, but any of them could have
been the end of the string, so check after each one instead.

Reviewed By: oulgen

Differential Revision: D19611163

fbshipit-source-id: 3da0a39555cb85a93f4fd98048368f17cf37e2e4
  • Loading branch information
Mark Williams authored and facebook-github-bot committed Feb 20, 2020
1 parent bd58667 commit b367912
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions hphp/runtime/ext/json/JSON_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,12 +453,13 @@ struct SimpleParser {
case 'u': {
if (UNLIKELY(is_tsimplejson)) {
auto const ch1 = *p++;
if (UNLIKELY(ch1 != '0')) return false;
auto const ch2 = *p++;
if (UNLIKELY(ch2 != '0')) return false;
auto const dch3 = dehexchar(*p++);
if (UNLIKELY(dch3 < 0)) return false;
auto const dch4 = dehexchar(*p++);
if (UNLIKELY(ch1 != '0' || ch2 != '0' || dch3 < 0 || dch4 < 0)) {
return false;
}
if (UNLIKELY(dch4 < 0)) return false;
out = (dch3 << 4) | dch4;
return true;
} else {
Expand Down
1 change: 1 addition & 0 deletions hphp/test/slow/ext_json/decode_crash.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

var_dump(json_decode('"a"', false, 0, 0));
var_dump(json_decode('"abc', true, 1000, 0));
var_dump(json_decode('"\\u', true, 1000, 17180393472));
1 change: 1 addition & 0 deletions hphp/test/slow/ext_json/decode_crash.php.expect
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
NULL
NULL
NULL

0 comments on commit b367912

Please sign in to comment.