Skip to content

Segmentation Fault in Message.MarshalJSON #2

@marc921

Description

@marc921

Using the library as

import (
     nmsg "github.com/farsightsec/go-nmsg/cgo-nmsg"
)

I have experienced segmentation faults

[signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0x7f3435645bbf]

coming from nmsg.Message.MarshalJSON function, called with roughly these steps:

// Receiving messages from UDP connection
reader, err := net.ListenUDP("udp", &src)
input := nmsg.NewInput(h.reader)
// msg is of type *nmsg.Message
msg, err := input.Read()
jsonBytes, err := msg.MarshalJSON()  // SIGSEGV is thrown

This does not happen on all received messages, only few of them. I have not been able to capture a faulty message.
Any advice would be greatly appreciated in that regard too.

I have been looking in the nmsg library C code (message.c) but could not find the source of the error.
I wondered if faulty messages had a special type, attribute or value that made them fall in special edge cases, but could not log it from Go-accessible library functions on nmsg.Message type.

Expected behaviour:
MarshalJSON should return a non-nil error instead of panicking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions