Wireshark mailing list archives
Re: pcapng, must opt_comment string be 0-terminated?
From: Jose Pedro Oliveira <jpo () di uminho pt>
Date: Mon, 02 Jan 2012 19:44:24 +0000
On 2012-01-02 08:16, Michael Tuexen wrote:
On Jan 2, 2012, at 3:53 AM, Guy Harris wrote:On Jan 1, 2012, at 3:00 PM, Martin Kaiser wrote:In a pcapng file, does the string stored in an opt_comment option have to be 0-terminated? I couldn't find anything explicit about this in the specification. Pcapng options have a length field, therefore I'd guess the 0 termination is not required. What do you think?The Wireshark code to read pcap-NG files uses g_strndup() to make copies of the various "UTF-8 string[s]", so the strings in the file don't have to be null-terminated, and I would read the *lack* of any mention of null-termination in the spec as an indication thatI think g_strndup() is for being secure. Even if the spec requires the string to be 0 terminated, you never know if the file you read conforms to the spec. Since the option has a length field, using g_strndup() is the way to go.they don't have to be null-terminated. I'll send the spec maintainers a note asking about this, and suggesting that the spec indicate that all strings are counted (but shouldn't contain a null byte).Hmm, I wouldn't mind if they are 0-terminiated, I even thought they are. However, it would be great if it would be described explicitly in the spec.
The NTAR library [1] code expects the strings to be NUL terminated, at least the NUL char is counted as a valid char (option length) when written to file: NTAR source file: option_writers.c ---------- ... int write_option_string(ntar_option *option, void* buffer,size_t *buffer_size) ... /* +1 is used for the trailing \0 */ string_len = strlen(option->data) + 1; ... opt.option_length = (u_int16)(string_len); ... memcpy(buffer_char, option->data, string_len); buffer_char += string_len; if (align_bytes > 0) memset(buffer_char, 0, align_bytes); ... ---------- Regards, jpo [1] - http://www.winpcap.org/ntar/ written by one of the PCAP-NG spec maintainers. -- José Pedro Oliveira * mailto:jpo () di uminho pt * ___________________________________________________________________________ Sent via: Wireshark-dev mailing list <wireshark-dev () wireshark org> Archives: http://www.wireshark.org/lists/wireshark-dev Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev mailto:wireshark-dev-request () wireshark org?subject=unsubscribe
Current thread:
- pcapng, must opt_comment string be 0-terminated? Martin Kaiser (Jan 01)
- Re: pcapng, must opt_comment string be 0-terminated? Guy Harris (Jan 01)
- Re: pcapng, must opt_comment string be 0-terminated? Michael Tuexen (Jan 02)
- Re: pcapng, must opt_comment string be 0-terminated? Jose Pedro Oliveira (Jan 02)
- Re: pcapng, must opt_comment string be 0-terminated? Martin Kaiser (Jan 03)
- Re: [Wireshark-dev] pcapng, must opt_comment string be 0-terminated? Chris Maynard (Jan 05)
- Re: [Wireshark-dev] pcapng, must opt_comment string be 0-terminated? Chris Maynard (Jan 05)
- Re: pcapng, must opt_comment string be 0-terminated? Michael Tuexen (Jan 02)
- Re: pcapng, must opt_comment string be 0-terminated? Guy Harris (Jan 01)