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 Winlogbeat bug affecting include_xml #3943

Merged
merged 1 commit into from
Apr 7, 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 @@ -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