This issue was migrated from bug 2981 in our old bug tracker.
Original bug information:
Reporter: Peter Harris Status: RESOLVED FIXED Product: Wireshark Component: GTK+ UI OS: All Platform: All Version: Git
Attachments:
extensions.patch.bz2: Patch to add extension support to the X11 dissector README.X11: How to rebuild X11 extension dissectors extensions.patch2.bz2: Patch to add extension support, updated to r26786 extensions.patch3.bz2: Patch to add extension support v3: minor bug fix, updated to Wireshark r27564, Mesa mesa_7_1_rc4-8575-g17c7852 and xcb/proto 1.4-1-g8e5a650 gtk.pcap.bz2: Small capture from a GTK app extensions.patch4.bz2: Patch to add extension support v4: Use U for unreferenced variables/functions, fix infinite loop found by fuzz extensions.patch5.bz2: Patch to add extension support v5 extensions.patch6.bz2: Patch to add extension support v6 git-version.patch: Patch to add mesa and xcbproto versions to headers
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items 0
Show closed items
No child items are currently assigned. Use child items to break down this issue into smaller parts.
Linked items 0
Link issues together to show that they're related or that one is blocking others.
Learn more.
Copyright 1998-2008 Gerald Combs <gerald@wireshark.org> and contributors.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Compiled with GTK+ 2.12.11, with GLib 2.16.6, with libpcap 0.9.8, with libz
1.2.3.3, without POSIX capabilities, with libpcre 7.6, without SMI, without
c-ares, with ADNS, with Lua 5.1, with GnuTLS 2.4.1, with Gcrypt 1.4.1, with MIT
Kerberos, without PortAudio, without AirPcap.
Running on Linux 2.6.26-1-686, with libpcap version 0.9.8.
Built using gcc 4.3.2.
This patch adds extension support to the X11 dissector.I've removed the perl script from the make file, since the new one depends on perl 5.10, xcbproto (at least git as of today), and mesa (at least the mesa/src/mesa/glapi directory). It seemed easier to just add the generated header files to svn directly.If you would rather see this patch the other way around (keep running the generation scripts at 'make' time, and include mesa/glapi and xcbproto in the repository instead of the generated .h files), please let me know.
We often keep the scripts used to generate files in our source tree, but if there are various programs required to generate the files, I would say we can keep a skeleton of code in the tree then have a document that explains how to get the programs required to generate the code.
This sounds similar to our ASN.1 generated dissectors. When we make a change, we check in the updated code generator in asn1/<dissector name>/ and then we run it again locally and check in the updated files at the same time.
Created attachment 2792
Patch to add extension support v3: minor bug fix, updated to Wireshark r27564, Mesa mesa_7_1_rc4-8575-g17c7852 and xcb/proto 1.4-1-g8e5a650
I hadn't previously fuzz-tested this patch. It passed a couple of hours with the one capture file I have handy; I'll do some more fuzz-testing with a wider variety of captures when I get to the office tomorrow.
It didn't occur to me that anyone would need a sample capture until you asked; I forgot that some people still use Windows. While looking at this quick capture, I noticed a couple of minor errors. Fixed in version 3 (along with updating the upstream XML protocol descriptions to their latest versions).
(In reply to comment #7)
> It didn't occur to me that anyone would need a sample capture until you asked;
> I forgot that some people still use Windows. While looking at this quick
> capture, I noticed a couple of minor errors. Fixed in version 3 (along with
> updating the upstream XML protocol descriptions to their latest versions).
In fact I generally use X for most of my work (using Exceed in some cases ;-)) but I figured you might have sample captures with some of the more "exotic" extensions (if such things exist--I use X but don't pay much attention to how it works).
(It also occurs to me after some reflection that most distros install X with "-nolisten tcp" by default, which makes it a pain to capture X)
The most 'exotic' (mostly obsolete) extensions aren't covered by XCB yet, so there wouldn't be any dissection to test. :-) But, yeah, pretty much everything draws via RENDER these days, which makes core-X-only dissection less useful.
I'll see what I can dig up at the office. I should be able to capture a reasonable variety, although complete coverage isn't likely.
No need to cover everything, though the more the better--especially so it can be used for reference. (Maybe you could put the captures on the Wiki's SampleCaptures page, too?)Regarding the patch, I think it mostly looks good. I didn't review the Perl script but the code it puts out looks sane. One exception is the code coming out of:+ # The length parameter may be unused. Shut up compiler warning.+ # (Worse than that, since wireshark uses -Werror)+ print $impl " (void)length;\n";+ if (!@elements) {+ print $impl " (void)tvb;\n";+ print $impl " (void)offsetp;\n";+ print $impl " (void)t;\n";+ print $impl " (void)little_endian;\n";+ }The preferred method is to append _U_ to the unused parameter. In the case of 'tvb' and the others, this can be done since you know when they won't be used. 'length' is problematic because you don't really know if it will be used or not. I'm a little uncomfortable with the code as it is--I have this vague memory of some compilers warning about statements like that (something about statements with no effect?).Is it safe to mark a parameter with _U_ even if it may be used? Another way would be to simply assign the variable to itself. I forget what's the preferred method (assuming that we want to keep this dissector clean).
(In reply to comment #11) > Is it safe to mark a parameter with _U_ even if it may be used? Yes. A comment mentioning that it may be used would be helpful though. We have some generated dissectors (ASN.1?) that just mark everything as unused and use what they need if I remember correctly.
Created attachment 2799Patch to add extension support v4: Use _U_ for unreferenced variables/functions, fix infinite loop found by fuzzAh, I was unaware that Wireshark had the _U_ define. Thanks! Patch updated.I've uploaded a half a dozen .pcap files to the Wiki's SampleCaptures page. Fuzz testing over those files turned up an infinite loop in GLX/Render when the length field on the wire is invalid. Fixed in v4 of the patch.I did double-check the definition of _U_. It only appears to be defined for gcc. The attribute is described as useful for C++ objects where the constructor and destructor are important, but the object is otherwise never used, so it sounds safe to use it on variables/functions that are actually referenced.v4 also uses "static _U_" for a few functions that were previously non-static. This is a good thing: it cuts down on namespace pollution, and it should (in theory) allow the linker to eliminate a few of the functions (except on Windows, where it could already toss unreferenced functions, due to Windows forcing the equivalent of -fvisibility=hidden).I'm a little queasy about -Wall -Werror -- some day, gcc will start warning about something else (eg: non-system defines of reserved names (such as those that start with an underscore followed by a capital letter)), and the build will error. But that's beyond the scope of this particular patch.
(In reply to comment #13) > I've uploaded a half a dozen .pcap files to the Wiki's SampleCaptures page. > Fuzz testing over those files turned up an infinite loop in GLX/Render when the > length field on the wire is invalid. Fixed in v4 of the patch. Excellent. But I don't think this is a good way to fix it:+ len = VALUE16(tvb, *offsetp);[...]+ if (len < 4) {+ REPORT_DISSECTOR_BUG("Invalid glRender length");+ }+ len -= 4;It's not a dissector bug that the packet is malformed. You should either return or force an exception to be thrown (by trying to read beyond the end of the tvb).> v4 also uses "static _U_" for a few functions that were previously non-static. I assume those functions are unused because xcb or whatever defines the structures but doesn't use them? [Since this is generated code] why not just leave them out of the dissector until they become used?> I'm a little queasy about -Wall -Werror -- some day, gcc will start warning > about something else (eg: non-system defines of reserved names (such as those > that start with an underscore followed by a capital letter)), and the build > will error. But that's beyond the scope of this particular patch. It should be noted that we don't ship Wireshark with -Werror turned on. It's just there to keep developers honest between releases. So far turning it on has been a Good Thing in many ways.In continuing to review the code, I have a few more comments:- why abuse value_string?+static value_string bigreq_reply_funcs[] = {+ {0, (char *)bigreqEnable_Reply },+ { 0, NULL }+};[...]+ set_handler("BIG-REQUESTS", dispatch_bigreq, bigreq_errors, bigreq_events, bigreq_event_funcs, bigreq_reply_funcs);It would be nicer to just define your own structure to hold pointers to functions.- (Minor, but...) since this is generated code, why not get the indenting right?+ for (i = 0; i < count; i++) {+ proto_item *item;+ proto_tree *t;+ int f_root;(Not sure if that'll come out in HTML, but the 'int' line is indented 4 spaces but the proto_* are indented with a tab--8 spaces.)I may have more comments later--there's a lot of code here.
(In reply to comment #14) > (In reply to comment #13) > > I've uploaded a half a dozen .pcap files to the Wiki's SampleCaptures page. > > Fuzz testing over those files turned up an infinite loop in GLX/Render when the > > length field on the wire is invalid. Fixed in v4 of the patch. > > Excellent. But I don't think this is a good way to fix it: ...> + REPORT_DISSECTOR_BUG("Invalid glRender length"); > It's not a dissector bug that the packet is malformed. You should either > return or force an exception to be thrown (by trying to read beyond the end of > the tvb). I'd like to throw an error, so it shows up in red in wireshark. I need to read past the end of the tvb to do so? Ick.I'll make this change for v5.> > v4 also uses "static _U_" for a few functions that were previously non-static. > > I assume those functions are unused because xcb or whatever defines the > structures but doesn't use them? Well, xcb does use them - in the core protocol. I wanted to leave the core protocol dissector alone for now.> [Since this is generated code] why not just > leave them out of the dissector until they become used? Right now, I process the protocol description in a streamy and (mostly) stateless manner. Changing the generator to emit structures lazily would be a rather large change.> - why abuse value_string? ...> It would be nicer to just define your own structure to hold pointers to > functions. Yes, it would. I thought I was using value_string lookup functions, but it appears not. I'll make this change for v5.> - (Minor, but...) since this is generated code, why not get the indenting > right? I didn't do this initially because this is generated code - nobody should be editing it by hand anyway.To fix up the indenting I'll have to pass an extra parameter around (since the same function generates code at different indent levels).I'll make this change for v5.> I may have more comments later--there's a lot of code here. Thank you for your review. The code is much better already.
(In reply to comment #16)
> You can use expert_add_info_format() to add an error message to an item.
> Have a look in epan/expert.h for various options.
Created attachment 2809Patch to add extension support v5v5 of the patch has the following changes from v4: - reports malformed GLX/Render subrequest sizes via expert_add_info_format instead of REPORT_DISSECTOR_BUG - uses custom structures instead of abusing value_string - indents generated code for 'struct' functions properly. - implements xcb <union> support, prompted by: - omits unused structure dissectors via the brute-force method of blacklisting the ones that are never used.