Wireshark-dev: Re: [Wireshark-dev] Should tvb always be != NULL
From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Fri, 3 Oct 2008 00:34:06 -0700

On Oct 3, 2008, at 12:25 AM, Jaap Keuter wrote:

Bug 2934 brings to light an interesting question: Should proto_tree_add_??? always have a valid tvb? Sounds logical for every call that adds a value, but not so much for _add_text(). The bug states that there are dissectors which make
that call without a tvb, and this leads to a crash.
Should the (epan and other) code be prepared for tvb == NULL, or should we
DISSECTOR_ASSERT(tvb)?

If tvb is null, how can the range of bytes in the top-level packet data corresponding to the item being entered into the protocol tree be determined? The offset passed to proto_tree_add_xxx is relative to the beginning of a tvbuff.

I guess if the length of the field is 0, tvb could be null; a zero- length field is used for, among other things, fields that don't correspond to any data in the packet.