]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
wireshark-pidl: Check for undefined SwitchType first
authorJohn Thacker <johnthacker@gmail.com>
Sun, 12 Oct 2025 19:07:00 +0000 (15:07 -0400)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 5 Nov 2025 10:08:28 +0000 (10:08 +0000)
From the Wireshark development branch:

    commit edc98c1b537cbd7b8fb35cdb8b61b7dd000a1544
    Author: John Thacker <johnthacker@gmail.com>
    Date:   Thu Oct 9 18:31:35 2025 -0400

        pidl: Check for undefined SwitchType first

        If the switch type is not defined (e.g. in a union with no
        discriminant) check for that first instead of doing a bunch of
        comparisons with an uninitialized scalar variable. Doesn't change
        the dissector results, but prevents a bunch of Perl warnings:

        Use of uninitialized value $t in hash element at /wireshark/tools/pidl/lib/Parse/Pidl/Typelist.pm
    line 194.
        Use of uninitialized value in string eq at /wireshark/tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm l
    ine 480.
        Use of uninitialized value in string eq at /wireshark/tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm l
    ine 482.
        Use of uninitialized value in string eq at /wireshark/tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm l
    ine 484.

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 f27d4f9850cff2b5f394a9c3cf9d1c369c7d0ef3..667199ecbd58909cdc8a31a87eb11f930eeb262f 100644 (file)
@@ -450,21 +450,23 @@ sub SwitchType($$;$)
 {
        my ($e, $type, $nodiscriminant) = @_;
 
-       my $switch_dt =  getType($type);
        my $switch_type = undef;
-       if ($switch_dt->{DATA}->{TYPE} eq "ENUM") {
-               $switch_type = Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA});
-       } elsif ($switch_dt->{DATA}->{TYPE} eq "BITMAP") {
-               $switch_type = Parse::Pidl::Typelist::bitmap_type_fn($switch_dt->{DATA});
-       } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") {
-               if (defined $e->{SWITCH_TYPE}) {
-                       $switch_type = "$e->{SWITCH_TYPE}";
-               } else {
-                       $switch_type = "$switch_dt->{DATA}->{NAME}";
-               }
-       } elsif (not defined $e->{SWITCH_TYPE}) {
+       if (not defined($type)) {
                $switch_type = $nodiscriminant;
-       }
+       } else {
+                my $switch_dt =  getType($type);
+                if ($switch_dt->{DATA}->{TYPE} eq "ENUM") {
+                        $switch_type = Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA});
+                } elsif ($switch_dt->{DATA}->{TYPE} eq "BITMAP") {
+                        $switch_type = Parse::Pidl::Typelist::bitmap_type_fn($switch_dt->{DATA});
+                } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") {
+                        if (defined $e->{SWITCH_TYPE}) {
+                                $switch_type = "$e->{SWITCH_TYPE}";
+                        } else {
+                                $switch_type = "$switch_dt->{DATA}->{NAME}";
+                        }
+                }
+        }
 
        return $switch_type
 }