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

UnmarshallBinary produces broken Message part #1

Open
makickerking opened this issue Sep 27, 2016 · 2 comments
Open

UnmarshallBinary produces broken Message part #1

makickerking opened this issue Sep 27, 2016 · 2 comments

Comments

@makickerking
Copy link

Hi @crewjam,

thanks for making that code available.

I'm currently experimenting with using your library to parse syslog messages that are received via a HTTPS endpoint, i.e. the client is sending messages via a HTTP POST.

In my ServeHTTP function, I'm doing basically this:

        scanner := bufio.NewScanner(req.Body)
        for scanner.Scan() {
            b := scanner.Bytes()
            if len(b) > 0 {
                var m *rfc5424.Message = &rfc5424.Message{}
                if err = m.UnmarshalBinary(b); err != nil {
                    fmt.Printf("cannot parse msg: %v\n", err)
                } else {
                    h.msgQueue <- *m
                }
            }
        }
        req.Body.Close()

But using this, the Message field gets screwed up if more than one syslog line is sent in the request body.

Looking at func (m *Message) UnmarshalBinary(inputBuffer []byte) I fear that the assignment

      m.Message = r.Bytes()

is unsafe and should be replaced by

    m.Message = make([]byte, len(r.Bytes()))
    copy(m.Message, r.Bytes())

Best

Michael

@crewjam
Copy link
Owner

crewjam commented Sep 27, 2016

Hi Michael,

Thanks for the report. Any chance of a PR? :)

Cheers,

Ross

crewjam added a commit that referenced this issue Oct 8, 2016
@tonimelisma
Copy link

Is this issue fixed? Is the library still maintained @crewjam ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants