From 80ed66dc17a5beb3606f8d4801852df434d723c0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabian=20Gr=C3=BCnbichler?= Date: Thu, 21 Dec 2023 16:30:24 +0100 Subject: [PATCH] fix #5141: network parser: fix accidental RE result re-use MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit $1 and friends are not cleared if a RE fails to match, in which case they will contain the captured values from a previous successful match in the same scope. deduplicate the two branches to avoid accidental re-introduction. Signed-off-by: Fabian Grünbichler --- src/PVE/INotify.pm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm index 601e651..6432295 100644 --- a/src/PVE/INotify.pm +++ b/src/PVE/INotify.pm @@ -1073,16 +1073,27 @@ sub __read_etc_network_interfaces { $ifaces->{$1}->{exists} = 0; $d->{exists} = 0; } - } elsif ($iface =~ m/^(\S+)\.(\d+)$/ || $d->{'vlan-raw-device'}) { + } elsif ($iface =~ m/^(\S+)\.(\d+)$/) { $d->{type} = 'vlan'; my ($dev, $id) = ($1, $2); $d->{'vlan-raw-device'} = $dev if defined($dev) && !$d->{'vlan-raw-device'}; + $d->{'vlan-id'} = $id if $id; # VLAN id 0 is not valid, so truthy check it is - if (!$id && $iface =~ m/^vlan(\d+)$/) { # VLAN id 0 is not valid, so truthy check it is - $id = $1; + my $raw_iface = $d->{'vlan-raw-device'}; + + if (defined ($ifaces->{$raw_iface})) { + $d->{exists} = $ifaces->{$raw_iface}->{exists}; + } else { + $ifaces->{$raw_iface}->{exists} = 0; + $d->{exists} = 0; + } + } elsif ($d->{'vlan-raw-device'}) { + $d->{type} = 'vlan'; + + if ($iface =~ m/^vlan(\d+)$/) { + $d->{'vlan-id'} = $1 if $1; # VLAN id 0 is not valid, so truthy check it is } - $d->{'vlan-id'} = $id if $id; my $raw_iface = $d->{'vlan-raw-device'}; -- 2.39.5