Skip to content

Commit

Permalink
Merge pull request #197 from kcasctiv/fix-get-infinite-loop
Browse files Browse the repository at this point in the history
Fix infinite loop in Get
  • Loading branch information
AllenX2018 committed May 10, 2020
2 parents 57853d8 + b10e032 commit 5754b3e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ func searchKeys(data []byte, keys ...string) int {
// can move to the end of this block
if !lastMatched {
end := blockEnd(data[i:], '{', '}')
if end == -1 {
return -1
}
i += end - 1
} else {
level++
Expand Down
12 changes: 9 additions & 3 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,15 @@ var getTests = []GetTest{
},
{
// Issue #178: Crash in searchKeys
desc: `invalid json`,
json: `{{{"":`,
path: []string{"a", "b"},
desc: `invalid json`,
json: `{{{"":`,
path: []string{"a", "b"},
isFound: false,
},
{
desc: `opening brace instead of closing and without key`,
json: `{"a":1{`,
path: []string{"b"},
isFound: false,
},
}
Expand Down

0 comments on commit 5754b3e

Please sign in to comment.