]> The Tcpdump Group git mirrors - libpcap/commitdiff
TESTrun: Add more reject tests with pcap_ether_hostton().
authorDenis Ovsienko <[email protected]>
Thu, 17 Apr 2025 11:07:12 +0000 (12:07 +0100)
committerDenis Ovsienko <[email protected]>
Mon, 21 Apr 2025 20:35:11 +0000 (21:35 +0100)
pcap_ether_hostton() returns an allocated 48-bit binary MAC address,
which ought to be freed no matter if the attempt to use it was
successful or not.  The latter case stands for several code paths that
start at gen_scode(), invoke pcap_ether_hostton() and eventually
bpf_error(); each of these ought to arrange a means to free the memory.
Some of these code paths are already covered with tests, add tests to
cover the remaining code paths and make the problem space completely
visible to Valgrind.

testprogs/TESTrun

index 6df429e650c63cd6a74c9d5797b664b23eb57669..1ae06f66f796ef6dcff93eebe96813e3f9c2a2a5 100755 (executable)
@@ -14718,15 +14718,18 @@ my @reject_tests = (
                expr => "decnet host ${nonexistent}",
                errstr => "invalid DECnet address '${nonexistent}'",
        },
+       # gen_scode() -> case Q_GATEWAY -> pcap_nametoaddrinfo() == NULL
+       # Invokes bpf_error() after pcap_ether_hostton().
        {
                name => 'gateway_noipv4_noipv6',
                skip => skip_config_def1 ('INET6') ||
-                       skip_no_ethers() ||
-                       skip_no_hosts(),
+                       skip_no_ethers(),
                DLT => 'EN10MB',
                expr => 'gateway eth-noipv4-noipv6.host123.libpcap.test',
                errstr => 'unknown host', # no IPv4 address in /etc/hosts
        },
+       # gen_scode() -> case Q_GATEWAY -> pcap_nametoaddrinfo() == NULL
+       # Invokes bpf_error() after pcap_ether_hostton().
        {
                name => 'gateway_noipv4_ipv6',
                skip => skip_config_def1 ('INET6') ||
@@ -15261,6 +15264,44 @@ sub pquals_without {
        return list_with_without \%pqual_features, shift, 0;
 }
 
+# "dir" qualifiers
+my %dqual_features = (
+       src => {
+       },
+       dst => {
+       },
+       'src or dst' => {
+       },
+       'src and dst' => {
+       },
+       addr1 => {
+               wlan => 1,
+       },
+       addr2 => {
+               wlan => 1,
+       },
+       addr3 => {
+               wlan => 1,
+       },
+       addr4 => {
+               wlan => 1,
+       },
+       ra => {
+               wlan => 1,
+       },
+       ta => {
+               wlan => 1,
+       },
+);
+
+sub dquals_with {
+       return list_with_without \%dqual_features, shift, 1;
+}
+
+sub dquals_without {
+       return list_with_without \%dqual_features, shift, 0;
+}
+
 # All DLTs pcap_datalink_name_to_val() recognizes, ordered by name.
 my %DLTfeatures = (
        A429 => {
@@ -15767,6 +15808,12 @@ sub DLTs_without {
        return list_with_without \%DLTfeatures, shift, 0;
 }
 
+sub DLT_feature {
+       my $name = shift;
+       my $feature = shift;
+       return item_with_without $DLTfeatures{$name}, $feature, 1;
+}
+
 # gen_load_internal() -> default
 foreach (pquals_without 'index') {
        push @reject_tests, {
@@ -15888,7 +15935,8 @@ foreach (pquals_without 'host') {
        # (IPv6 networks cannot have names)
 }
 
-# ID -> gen_scode() -> gen_gateway() -> default
+# ID -> gen_scode() -> case Q_GATEWAY -> gen_gateway() -> default
+# Invokes bpf_error() after pcap_ether_hostton().
 foreach (pquals_without 'gateway') {
        push @reject_tests, {
                skip => skip_config_def1 ('INET6') ||
@@ -15901,6 +15949,31 @@ foreach (pquals_without 'gateway') {
        };
 }
 
+foreach (DLTs_without 'link_host_mac48') {
+       # ID -> gen_scode() -> case Q_GATEWAY -> gen_gateway() -> case Q_DEFAULT -> default
+       # Invokes bpf_error() after pcap_ether_hostton().
+       push @reject_tests, {
+               name => "gateway_ipv4_noipv6_${_}",
+                       skip => skip_config_def1 ('INET6') ||
+                               skip_no_ethers() ||
+                               skip_no_hosts(),
+               DLT => $_,
+               expr => 'gateway eth-ipv4-noipv6.host123.libpcap.test',
+               errstr => '\'gateway\' supported only on',
+       };
+       # ID -> gen_scode() -> case Q_GATEWAY -> gen_gateway() -> case Q_DEFAULT -> default
+       # Invokes bpf_error() after pcap_ether_hostton().
+       push @reject_tests, {
+               name => "gateway_ipv4_ipv6_${_}",
+                       skip => skip_config_def1 ('INET6') ||
+                               skip_no_ethers() ||
+                               skip_no_hosts(),
+               DLT => $_,
+               expr => 'gateway eth-ipv4-ipv6.host123.libpcap.test',
+               errstr => '\'gateway\' supported only on',
+       };
+}
+
 foreach my $pq (pquals_without '') {
        # HID -> gen_ncode() -> case Q_GATEWAY
        push @reject_tests, {
@@ -16112,6 +16185,20 @@ foreach (DLTs_without 'wlan') {
        };
 }
 
+# gen_scode() -> case Q_HOST -> proto == Q_LINK -> non-WLAN case -> gen_mac48hostop() -> default case
+# Invokes bpf_error() after pcap_ether_hostton().
+foreach my $DLT (DLTs_without '') {
+       next if ! DLT_feature ($DLT, 'link_host_mac48') || DLT_feature ($DLT, 'wlan');
+       push @reject_tests, {
+               name => "link_${_}_name_${DLT}",
+               skip => skip_no_ethers(),
+               DLT => $DLT,
+               expr => "link $_ eth-noipv4-noipv6.host123.libpcap.test",
+               errstr => "'$_' is valid for 802.11 syntax only",
+       } foreach dquals_with 'wlan';
+       last if $only_short;
+}
+
 # gen_acode() -> default
 foreach (DLTs_without 'link_host_mac8') {
        push @reject_tests, {