]> git.proxmox.com Git - pve-manager.git/commitdiff
vzdump: generate notes: die upon unexpected escape character or variable
authorFabian Ebner <f.ebner@proxmox.com>
Wed, 27 Apr 2022 15:41:16 +0000 (17:41 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 28 Apr 2022 12:16:33 +0000 (14:16 +0200)
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/VZDump.pm

index 5f78746dbf3bd7a70da46f3bbef0f773767e9baf..fcbd87d5a63f5b2c3c5f89118928b93df9329570 100644 (file)
@@ -80,16 +80,20 @@ my $generate_notes = sub {
        vmid => $task->{vmid},
     };
 
-    my $unescape = {
-       '\\\\' => '\\', # replace \\ by \
-       '\n' => "\n", # turn literal \n into real newline
+    my $unescape = sub {
+       my ($char) = @_;
+       return '\\' if $char eq '\\';
+       return "\n" if $char eq 'n';
+       die "unexpected escape character '$char'\n";
     };
 
-    $notes_template =~ s/(\Q\\\E|\Q\n\E)/$unescape->{$1}/g;
+    $notes_template =~ s/\\(.)/$unescape->($1)/eg;
 
     my $vars = join('|', keys $info->%*);
     $notes_template =~ s/\{\{($vars)\}\}/\Q$info->{$1}\E/g;
 
+    die "unexpected variable name '$1'" if $notes_template =~ m/\{\{([^\s]+)\}\}/;
+
     return $notes_template;
 };
 
@@ -1042,9 +1046,13 @@ sub exec_backup_task {
 
            if ($opts->{'notes-template'} && $opts->{'notes-template'} ne '') {
                debugmsg('info', "adding notes to backup", $logfd);
-               my $notes = $generate_notes->($opts->{'notes-template'}, $task);
-               eval { PVE::Storage::update_volume_attribute($cfg, $volid, 'notes', $notes) };
-               debugmsg('warn', "unable to add notes - $@", $logfd) if $@;
+               my $notes = eval { $generate_notes->($opts->{'notes-template'}, $task); };
+               if (my $err = $@) {
+                   debugmsg('warn', "unable to add notes - $err", $logfd);
+               } else {
+                   eval { PVE::Storage::update_volume_attribute($cfg, $volid, 'notes', $notes) };
+                   debugmsg('warn', "unable to add notes - $@", $logfd) if $@;
+               }
            }
 
            if ($opts->{protected}) {