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

bug: syslog parse in rfc3164 tag length limit is 32 #1819

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
45 changes: 23 additions & 22 deletions external/github.com/jeromer/syslogparser/rfc3164/rfc3164.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rfc3164

import (
"bytes"
"math"
"time"

"github.com/jeromer/syslogparser"
Expand Down Expand Up @@ -213,41 +214,41 @@ func (p *Parser) parseHostname() (string, error) {

// http://tools.ietf.org/html/rfc3164#section-4.1.3
func (p *Parser) parseTag() (string, error) {

var b byte
var endOfTag bool
var bracketOpen bool
var tag []byte
var err error
var found bool

from := p.cursor

for {
var enough bool

previous := p.cursor
// "The TAG is a string of ABNF alphanumeric characters that MUST NOT exceed 32 characters."
limit := int(
math.Min(
float64(p.l),
float64(p.cursor+32),
),
)

for p.cursor < limit {
b = p.buff[p.cursor]
bracketOpen = (b == '[')
endOfTag = (b == ':' || b == ' ')

// XXX : parse PID ?
if bracketOpen {
tag = p.buff[from:p.cursor]
found = true
if b == ' ' {
p.cursor++
break
}

if endOfTag {
if !found {
tag = p.buff[from:p.cursor]
found = true
}

if b == '[' || b == ']' || b == ':' || enough {
enough = true
p.cursor++
break
continue
}

tag = append(tag, b)
p.cursor++
}

if (p.cursor < p.l) && (p.buff[p.cursor] == ' ') {
p.cursor++
if len(tag) == 0 {
p.cursor = previous
}

return string(tag), err
Expand Down
Loading