parse config: skip unknown sections and warn about their presence

Currently, keys in an unknown section will be interpreted as still
belonging to the last section and might erroneously overwrite values
in that way. Explicitly ignore unknown sections to avoid this while
warning the user.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Link: https://lore.proxmox.com/20250127112923.31703-7-f.ebner@proxmox.com
This commit is contained in:
Fiona Ebner 2025-01-27 12:29:13 +01:00 committed by Thomas Lamprecht
parent c80f968cc1
commit 248349f25e
3 changed files with 13 additions and 5 deletions

View File

@ -2251,8 +2251,16 @@ sub parse_vm_config {
$finish_description->(); $finish_description->();
$conf = $res->{snapshots}->{$section->{name}} = {}; $conf = $res->{snapshots}->{$section->{name}} = {};
next; next;
} elsif ($line =~ m/^\[([^\]]*)\]\s*$/i) {
my $unknown_section = $1;
$section = undef;
$finish_description->();
$handle_error->("vm $vmid - skipping unknown section: '$unknown_section'\n");
next;
} }
next if !defined($section);
if ($line =~ m/^\#(.*)$/) { if ($line =~ m/^\#(.*)$/) {
$descr = '' if !defined($descr); $descr = '' if !defined($descr);
$descr .= PVE::Tools::decode_text($1) . "\n"; $descr .= PVE::Tools::decode_text($1) . "\n";

View File

@ -5,7 +5,7 @@ ide2: lvm:vm-120-cloudinit,media=cdrom
ipconfig0: ip6=dhcp ipconfig0: ip6=dhcp
memory: 4096 memory: 4096
meta: creation-qemu=9.0.2,ctime=1725975013 meta: creation-qemu=9.0.2,ctime=1725975013
name: foo name: deb1223
net0: vmxnet3=BC:24:11:2C:69:EC,bridge=vnet0,firewall=1 net0: vmxnet3=BC:24:11:2C:69:EC,bridge=vnet0,firewall=1
numa: 0 numa: 0
ostype: l26 ostype: l26
@ -18,11 +18,11 @@ unused0: rbd:vm-120-disk-0
vmgenid: 7079e97c-50e3-4079-afe7-23e67566b946 vmgenid: 7079e97c-50e3-4079-afe7-23e67566b946
[PENDING] [PENDING]
bios: seabios bios: ovmf
[special:cloudinit] [special:cloudinit]
ipconfig0: ip=dhcp,ip6=dhcp ipconfig0: ip=dhcp,ip6=dhcp
name: bar name: deb122
[foo] [foo]
boot: order=scsi0 boot: order=scsi0
@ -32,7 +32,7 @@ ide2: lvm:vm-120-cloudinit,media=cdrom
ipconfig0: ip=dhcp,ip6=dhcp ipconfig0: ip=dhcp,ip6=dhcp
memory: 4096 memory: 4096
meta: creation-qemu=9.0.2,ctime=1725975013 meta: creation-qemu=9.0.2,ctime=1725975013
name: baz name: deb1223
net0: vmxnet3=BC:24:11:2C:69:EC,bridge=vnet0,firewall=1 net0: vmxnet3=BC:24:11:2C:69:EC,bridge=vnet0,firewall=1
numa: 0 numa: 0
ostype: l26 ostype: l26

View File

@ -1 +1 @@
vm 8006 - unable to parse config: [special:unknown123] vm 8006 - skipping unknown section: 'special:unknown123'