]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
wireshark-pidl: Warn appropriately on unsupported switch_is discriminants
authorJohn Thacker <johnthacker@gmail.com>
Sun, 12 Oct 2025 19:00:35 +0000 (15:00 -0400)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 5 Nov 2025 10:08:28 +0000 (10:08 +0000)
From the Wireshark development branch:

    commit 448a0d6a239f3f274d3a3a3a39ea9c6ce7fd2611
    Author: John Thacker <johnthacker@gmail.com>
    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 <johnthacker@gmail.com>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
pidl/lib/Parse/Pidl/Wireshark/NDR.pm

index 5f374dd914631307aca65698ddcbd7e835e303b2..f27d4f9850cff2b5f394a9c3cf9d1c369c7d0ef3 100644 (file)
@@ -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";