From: John Thacker Date: Sun, 12 Oct 2025 19:00:35 +0000 (-0400) Subject: wireshark-pidl: Warn appropriately on unsupported switch_is discriminants X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f20f86781e5843b0c02b993da93c7f7736970ccb;p=thirdparty%2Fsamba.git wireshark-pidl: Warn appropriately on unsupported switch_is discriminants From the Wireshark development branch: commit 448a0d6a239f3f274d3a3a3a39ea9c6ce7fd2611 Author: John Thacker Date: Thu Oct 9 10:18:07 2025 -0400 pidl: Warn appropriately on unsupported switch_is discriminants Microsoft's MIDL supports switch_is discriminants which have limited C-language expressions including conditionals, logical, relational, and arithmetic expressions. [1] Some of the distributed IDL files include such expressions. The current handling in PIDL's Wireshark NDR.pm only supports a single identifier (possibly a pointer), which appears to be the way it is defined in the original DCE IDL. [2,3] In addition, the switch_is discriminant may simply be misspelled or otherwise not found when parsing, leading to an empty array reference. Test for the empty array in order to produce a helpful warning message with the filename and line number, instead of unhelpful Perl warnings. This does not provide support for the construct not affect the generated dissectors at all, only reduces 4 unclear warnings into a single useful warning. Before: Use of uninitialized value $name in string ne at /home/johnthacker/wireshark/tools/pidl/lib/Parse/ Pidl/Wireshark/NDR.pm line 516. Use of uninitialized value in string eq at /home/johnthacker/wireshark/tools/pidl/lib/Parse/Pidl/W ireshark/NDR.pm line 525. Use of uninitialized value $name in string ne at /home/johnthacker/wireshark/tools/pidl/lib/Parse/ Pidl/Wireshark/NDR.pm line 527. Use of uninitialized value $name in string ne at /home/johnthacker/wireshark/tools/pidl/lib/Parse/ Pidl/Wireshark/NDR.pm line 531. After: drsuapi.idl:828: warning: ctr switch_is discriminant `level|(type<<16)' not found. (Only single id entifiers are supported, not expressions as in MIDL.) [1] - https://learn.microsoft.com/en-us/windows/win32/midl/switch-is [2] - https://pubs.opengroup.org/onlinepubs/9629399/chap4.htm#tagcjh_08_02_12 [3] - https://pubs.opengroup.org/onlinepubs/9629399/chap4.htm#tagcjh_08_04 Signed-off-by: John Thacker Reviewed-by: Stefan Metzmacher Reviewed-by: Andreas Schneider --- diff --git a/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 5f374dd9146..f27d4f9850c 100644 --- a/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -477,7 +477,7 @@ sub Element($$$$$$) my ($call_code, $moreparam); my $param = 0; - if (defined $isoruseswitch) { + if (defined $isoruseswitch and @$isoruseswitch) { my $type = $isoruseswitch->[0]; my $name = $isoruseswitch->[1]; @@ -730,6 +730,9 @@ sub Struct($$$$) if (has_property($_, "switch_is")) { my $varswitch = $_->{PROPERTIES}->{switch_is}; $switch_info = $varswitchs->{$varswitch}; + if (not @$switch_info) { + warning($_->{ORIGINAL}, "`$v' switch_is discriminant `$varswitch' not found. (Only single identifiers are supported, not expressions as in MIDL.)"); + } } $res.="\t".$self->Element($_, $name, $ifname, $switch_info, %switch_hash)."\n\n";