Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Ethereal-dev: Re: [Ethereal-dev] tvbuff questions and conclusions...

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <gharris@xxxxxxxxxxxx>
Date: Mon, 12 Mar 2001 21:40:27 -0800
> void
> dissect_vjc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
> {
> 
>         int new_len = 0, old_len = 0;
>         int offset =0;
>         char *pd = 0;
> 
>                 pd =  tvb_get_ptr(tvb, offset, 4);
> 
>                 old_len = tvb_length_remaining(tvb, offset);
> 
>                 if ( (new_len = slhc_uncompress(slcomp, pd, old_len)) <= 0) {

So where does "slhc_uncompress()" put the resulting data?

NOTE: "in the array pointed to by 'pd'" is the wrong answer.  There is
*NO* guarantee that it will always be the case that the pointer you get
back from "tvb_get_ptr()" will point to writable data (it might, for
example, be in a region of memory mapped read-only), and there is *NO*
guarantee that overwriting that data won't cause other code to get
confused, and there is *NO* guarantee that you will have more than
"old_len" bytes worth of room to put that data!

Gilbert, should "tvb_get_ptr()" be changed to return a "const guint8 *",
to make it harder for code to scribble on the data in a tvbuff?

What you want to do here is to have "slhc_uncompress()" write to a
*newly allocated* chunk of memory, and to create a new "real data"
tvbuff, with 'tvb_new_real_data()", referring to that tvbuff;
subdissectors would be handed *that* tvbuff.

Unfortunately, this will require the stuff Jeff Foster's working on, to
support multiple chunks of packet data for the same packet; until that's
done, you won't have the infrastructure necessary to do VJ uncompression
correctly.  Patience is a virtue....