Skip to content
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
19 changes: 9 additions & 10 deletions filebeat/input/syslog/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var month = map[string]time.Month{
"Dec": time.December,
}

var monthIndexed = []time.Month{
var monthIndexed = [...]time.Month{
0,
time.January,
time.February,
Expand Down Expand Up @@ -117,7 +117,7 @@ func (s *event) SetTimeZone(b []byte) {
}

// +00 +00:00 or +0000
// Use second value directly and don't use unecessary time.Duration.
// Use second value directly and don't use unnecessary time.Duration.
// Time.FixedZone accepts number of seconds.
var h, m int
switch len(b[1:]) {
Expand All @@ -137,7 +137,10 @@ func (s *event) SetTimeZone(b []byte) {

// SetMonthNumeric sets the month with a number.
func (s *event) SetMonthNumeric(b []byte) {
s.month = monthIndexed[bytesToInt(skipLeadZero(b))]
month := bytesToInt(skipLeadZero(b))
if month < len(monthIndexed) {
s.month = monthIndexed[month]
}
}

// SetMonth sets the month.
Expand Down Expand Up @@ -211,12 +214,8 @@ func (s *event) Year() int {

// SetMessage sets the message.
func (s *event) SetMessage(b []byte) {
// remove BOM
if b[0] == 0xef && b[1] == 0xbb && b[2] == 0xbf {
s.message = string(b[3:])
} else {
s.message = string(b)
}
// Trim BOM: https://unicode.org/faq/utf_bom#bom5
s.message = string(bytes.TrimPrefix(b, []byte("\ufeff")))
}

// Message returns the message.
Expand Down Expand Up @@ -262,7 +261,7 @@ func (s *event) SetHostname(b []byte) {

// Hostname returns the hostname.
func (s *event) Hostname() string {
return string(s.hostname)
return s.hostname
}

// SetProgram sets the programs as a byte slice.
Expand Down
10 changes: 10 additions & 0 deletions filebeat/input/syslog/rfc3164_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,16 @@ func TestPriority(t *testing.T) {
}
}

func TestParserRFC3164InvalidMonthNumeric(t *testing.T) {
event := newEvent()
ParserRFC3164([]byte("0000-20-"), event)
}

func TestParserRFC3164ShortMessage(t *testing.T) {
event := newEvent()
ParserRFC3164([]byte("Oct 1 00:00:00 \xef"), event)
}

var e *event

func BenchmarkParserRFC3164r(b *testing.B) {
Expand Down