Skip to content

Commit

Permalink
Fix Winlogbeat bug affecting include_xml (#3943)
Browse files Browse the repository at this point in the history
Then `include_xml: true` is used in the config file the raw `xml` value contains null terminators. This PR removes the null characters from the end of the XML string.
  • Loading branch information
andrewkroh authored and ruflin committed Apr 7, 2017
1 parent e5dcd4d commit 2ce3add
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff]
*Winlogbeat*

- Fix handling of empty strings in event_data. {pull}3705[3705]
- Fix null terminators include in raw XML string when include_xml is enabled. {pull}3943[3943]

==== Added

Expand Down
4 changes: 4 additions & 0 deletions winlogbeat/sys/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func UTF16ToUTF8Bytes(in []byte, out io.Writer) error {
var v1, v2 uint16
for i := 0; i < len(in); i += 2 {
v1 = uint16(in[i]) | uint16(in[i+1])<<8
// Stop at null-terminator.
if v1 == 0 {
return nil
}

switch {
case v1 < surr1, surr3 <= v1:
Expand Down
14 changes: 14 additions & 0 deletions winlogbeat/sys/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ func TestUTF16ToUTF8(t *testing.T) {
assert.Equal(t, []byte(input), outputBuf.Bytes())
}

func TestUTF16BytesToStringTrimNullTerm(t *testing.T) {
input := "abc"
utf16Bytes := append(toUTF16Bytes(input), []byte{0, 0, 0, 0, 0, 0}...)

outputBuf := &bytes.Buffer{}
err := UTF16ToUTF8Bytes(utf16Bytes, outputBuf)
if err != nil {
t.Fatal(err)
}
b := outputBuf.Bytes()
assert.Len(t, b, 3)
assert.Equal(t, input, string(b))
}

func BenchmarkUTF16ToUTF8(b *testing.B) {
utf16Bytes := toUTF16Bytes("A logon was attempted using explicit credentials.")
outputBuf := &bytes.Buffer{}
Expand Down
1 change: 1 addition & 0 deletions winlogbeat/tests/system/test_wineventlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def test_include_xml(self):
self.assertTrue(len(evts), 1)
self.assert_common_fields(evts[0], msg=msg)
self.assertTrue("xml" in evts[0])
self.assertTrue(evts[0]["xml"].endswith('</Event>'), 'xml value: "{}"'.format(evts[0]["xml"]))

def test_query_event_id(self):
"""
Expand Down

0 comments on commit 2ce3add

Please sign in to comment.