Wireshark mailing list archives

Re: Proper private_data usage


From: Jeff Morriss <jeff.morriss.ws () gmail com>
Date: Tue, 15 Oct 2013 12:38:29 -0400

On 10/15/13 12:00, Christopher Maynard wrote:
What is the proper, safe and recommended way to use pinfo->private_data?

If you look at the TCP dissector, you see the following:

         pd_save = pinfo->private_data;
         TRY {
             (*dissect_pdu)(next_tvb, pinfo, tree);
         }
         CATCH_NONFATAL_ERRORS {
             /*  Restore the private_data structure in case one of the
              *  called dissectors modified it (and, due to the exception,
              *  was unable to restore it).
              */
             pinfo->private_data = pd_save;
             show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE);
         }
         ENDTRY;

I did not check all dissectors, but this is certainly not done for all of
them.  I guess the question I have is, should it?  Is this the recommended
approach?

I started adding that back in r34408 (because I was getting a crash after a malformed packet exception). At the time I went through most of the dissectors and tried to make the same change (e.g., r34436 but I think there were more revisions). Of course I may have missed some and of course that was a long time ago and new dissectors have arrived...

But, yes, I think that when using private_data the restoration is necessary: otherwise if you have multiple PDUs in one frame then an exception in one of the early PDUs will cause the private_data to be wrong when the next PDU is dissected.

This is one of the reasons not to use private_data at all.

___________________________________________________________________________
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: