]> git.proxmox.com Git - pve-cluster.git/commitdiff
get tasklist: unpack null-terminated C string before decoding as JSON
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 15 May 2021 11:00:46 +0000 (13:00 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 16 May 2021 14:12:35 +0000 (16:12 +0200)
This was always an "issue", but with Perl 5.28, from our Debian Buster
based release, decode_json just ignored the \0 NUL byte.

For example:
```
perl -w -MJSON -e 'my $raw = "[]\0"; print to_json(decode_json($raw), {pretty=>1});'

```
will get you the following error on perl 5.32
```
garbage after JSON object, at character offset 2 (before "\x{0}") at -e line 1.
```

Note, I did not find anything related in the perldelta aricles for
the 28 -> 30 or 30 -> 32 update, the first one made a bigger jump for
the JSON module version used, so possibly a change there.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
data/PVE/Cluster.pm

index 3df2dbe3a3b5d20cd00e29e0990bd5dfd3930fde..4d09c60c955b682800f71baf97942b5695fe0b5e 100644 (file)
@@ -398,7 +398,8 @@ sub get_tasklist {
            if (!$cache || !$ver || !$cache->{version} || ($cache->{version} != $ver)) {
                my $tasks = [];
                if (my $raw = $ipcc_get_status->("tasklist", $node)) {
-                   $tasks = decode_json($raw);
+                   my $json_str = unpack("Z*", $raw);
+                   $tasks = decode_json($json_str);
                }
                push @$res, @$tasks;
                $tasklistcache->{$node} = {