sub pve_verify_vmid {
my ($vmid, $noerr) = @_;
- if ($vmid !~ m/^[1-9][0-9]+$/) {
+ if ($vmid !~ m/^[1-9][0-9]{2,8}$/) {
return undef if $noerr;
die "value does not look like a valid VM ID\n";
}
sub pve_verify_cidrv4 {
my ($cidr, $noerr) = @_;
- if ($cidr =~ m!^(?:$IPV4RE)(?:/(\d+))$! && ($1 > 7) && ($1 < 32)) {
+ if ($cidr =~ m!^(?:$IPV4RE)(?:/(\d+))$! && ($1 > 7) && ($1 <= 32)) {
return $cidr;
}
};
sub parse_property_string {
- my ($format, $data, $path) = @_;
+ my ($format, $data, $path, $additional_properties) = @_;
+
+ # In property strings we default to not allowing additional properties
+ $additional_properties = 0 if !defined($additional_properties);
my $default_key;
die "duplicate key in comma-separated list property: $default_key\n";
}
}
+ die "value without key, but schema does not define a default key\n" if !$default_key;
} else {
die "missing key in comma-separated list property\n";
}
}
my $errors = {};
- check_object($path, $format, $res, undef, $errors);
+ check_object($path, $format, $res, $additional_properties, $errors);
if (scalar(%$errors)) {
raise "format error\n", errors => $errors;
}
if (ref($format) ne 'HASH') {
my $schema = $format_list->{$format};
- die "not a valid format: $format" if !$schema;
+ die "not a valid format: $format\n" if !$schema;
$format = $schema;
}
# Skip default keys
if ($format->{$key}->{default_key}) {
if ($default_key) {
- warn "multiple default keys in schema ($default_key, $key)";
+ warn "multiple default keys in schema ($default_key, $key)\n";
} else {
$default_key = $key;
$skipped{$key} = 1;
}
foreach my $key (sort keys %$data) {
- die "invalid key: $key" if !$allowed{$key};
delete $required{$key};
next if $skipped{$key};
+ die "invalid key: $key\n" if !$allowed{$key};
my $typeformat = $format->{$key}->{format};
my $value = $data->{$key};
+ next if !defined($value);
$text .= $comma;
$comma = ',';
if ($typeformat && $typeformat eq 'disk-size') {
$text .= "$key=" . format_size($value);
} else {
+ die "illegal value with commas for $key\n" if $value =~ /,/;
$text .= "$key=$value";
}
}
if (my $missing = join(',', keys %required)) {
- die "missing properties: $missing";
+ die "missing properties: $missing\n";
}
return $text;