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

nf9/ipfix fields of type String are copied to the JSON output as-is, without handling special charachters #175

Open
dbardbar opened this issue Dec 29, 2022 · 1 comment

Comments

@dbardbar
Copy link
Contributor

dbardbar commented Dec 29, 2022

The nf9/ipfix protocols have many fields of type 'string'. The code today just takes the string as it appears in the packet and puts it in the JSON output.
There are various special characters that cannot be written to JSON as-is, for example double-quote. These need to be properly escaped.

One possible solution is to keep the existing manual marshaling code, but change this
case string:
b.WriteByte('"')
b.WriteString(m.DataSets[i][j].Value.(string))
b.WriteByte('"')

to use Go's built-in json.Marshel function, like so:

case string:
	var asJson, _ = json.Marshal(m.DataSets[i][j].Value.(string))
	b.Write(asJson)

My measurements show that this has minimal impact on performance.

Another option would be to properly encode special characters manually.

@dbardbar
Copy link
Contributor Author

As an example of a ipfix with special characters, see attached. The ApplicationName and ApplicationDesc elements have fixed-size, and so the exporter added nulls at the end of string, which is something which must not be put directly into the JSON.
This is just one case, which could be solved by trimming the string, but other cases where the string might contain other special chars, obviously won't be handled by trimming.
ipfix_null_padding_of_string.zip

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

1 participant