Skip to content

Commit

Permalink
pidl/NDR/Parser: also do range checks on the array size
Browse files Browse the repository at this point in the history
metze
(cherry picked from commit afaa5f6)
  • Loading branch information
metze-samba authored and kseeger committed Apr 10, 2012
1 parent 9657f7c commit ffb8d8e
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,20 @@ sub ParseArrayPullGetSize($$$$$$)
$self->pidl("size_$e->{NAME}_$l->{LEVEL_INDEX} = $size;");
my $array_size = "size_$e->{NAME}_$l->{LEVEL_INDEX}";

if (my $range = has_property($e, "range")) {
my ($low, $high) = split(/,/, $range, 2);
if ($low < 0) {
warning(0, "$low is invalid for the range of an array size");
}
if ($low == 0) {
$self->pidl("if ($array_size > $high) {");
} else {
$self->pidl("if ($array_size < $low || $array_size > $high) {");
}
$self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value out of range\");");
$self->pidl("}");
}

return $array_size;
}

Expand All @@ -348,13 +362,14 @@ sub ParseArrayPullGetLength($$$$$$;$)
$array_size = $self->ParseArrayPullGetSize($e, $l, $ndr, $var_name, $env);
}

my $array_length = $array_size;
if ($l->{IS_VARYING}) {
my $length = "ndr_get_array_length($ndr, " . get_pointer_to($var_name) .")";
$self->pidl("length_$e->{NAME}_$l->{LEVEL_INDEX} = $length;");
$array_length = "length_$e->{NAME}_$l->{LEVEL_INDEX}";
if (not $l->{IS_VARYING}) {
return $array_size;
}

my $length = "ndr_get_array_length($ndr, " . get_pointer_to($var_name) .")";
$self->pidl("length_$e->{NAME}_$l->{LEVEL_INDEX} = $length;");
my $array_length = "length_$e->{NAME}_$l->{LEVEL_INDEX}";

if (my $range = has_property($e, "range")) {
my ($low, $high) = split(/,/, $range, 2);
if ($low < 0) {
Expand Down

0 comments on commit ffb8d8e

Please sign in to comment.