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 JSON panic #4042

Merged
merged 1 commit into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff]
- Allow `-` in Apache access log byte count. {pull}3863[3863]
- Downgrade Elasticsearch per batch item failure log to debug level. {issue}3953[3953]
- Allow log lines without a program name in the Syslog fileset. {pull}3944[3944]
- Fix panic in JSON decoding code if the input line is "null". {pull}4042[4042]

*Heartbeat*
- Add default ports in HTTP monitor. {pull}3924[3924]
Expand Down
2 changes: 1 addition & 1 deletion filebeat/harvester/reader/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (r *JSON) decodeJSON(text []byte) ([]byte, common.MapStr) {
var jsonFields map[string]interface{}

err := unmarshal(text, &jsonFields)
if err != nil {
if err != nil || jsonFields == nil {
logp.Err("Error decoding JSON: %v", err)
if r.cfg.AddErrorKey {
jsonFields = common.MapStr{JsonErrorKey: fmt.Sprintf("Error decoding JSON: %v", err)}
Expand Down
7 changes: 7 additions & 0 deletions filebeat/harvester/reader/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ func TestDecodeJSON(t *testing.T) {
ExpectedText: `{"message": "test", "value": "`,
ExpectedMap: nil,
},
{
// in case the JSON is "null", we should just not panic
Text: `null`,
Config: JSONConfig{MessageKey: "value", AddErrorKey: true},
ExpectedText: `null`,
ExpectedMap: common.MapStr{"json_error": "Error decoding JSON: <nil>"},
},
{
// Add key error helps debugging this
Text: `{"message": "test", "value": "`,
Expand Down