summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2010-09-21 05:41:37 +0200
committerKarolin Seeger <kseeger@samba.org>2012-04-10 20:35:30 +0200
commitb375838e12a4d8bd39e9ca077db27ab71e05b0ec (patch)
tree9219cc4667648605cb59b31b73e4c2a8ba10e5de
parenta3dc832aa0b77d639ef3cc5f2a208b8765acdb4c (diff)
downloadsamba-b375838e12a4d8bd39e9ca077db27ab71e05b0ec.tar.gz
pidl:NDR/Parser: fix range() for arrays
metze (cherry picked from commit bea4948acb4bbee2fbf886adeb53edbc84de96da) (cherry picked from commit b48e41cb5541bec34333f94fc21bcd6c47018869)
-rw-r--r--pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm33
1 files changed, 32 insertions, 1 deletions
diff --git a/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
index a05f2851786..8ab2967ea5a 100644
--- a/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
@@ -865,7 +865,10 @@ sub ParseDataPull($$$$$$$)
$self->pidl("NDR_CHECK(".TypeFunctionName("ndr_pull", $l->{DATA_TYPE})."($ndr, $ndr_flags, $var_name));");
- if (my $range = has_property($e, "range")) {
+ my $pl = GetPrevLevel($e, $l);
+
+ my $range = has_property($e, "range");
+ if ($range and $pl->{TYPE} ne "ARRAY") {
$var_name = get_value_of($var_name);
my $signed = Parse::Pidl::Typelist::is_signed($l->{DATA_TYPE});
my ($low, $high) = split(/,/, $range, 2);
@@ -1010,6 +1013,20 @@ sub ParseElementPullLevel
} elsif ($l->{TYPE} eq "ARRAY") {
my $length = $self->ParseArrayPullHeader($e, $l, $ndr, $var_name, $env);
+ 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 ($length > $high) {");
+ } else {
+ $self->pidl("if ($length < $low || $length > $high) {");
+ }
+ $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value out of range\");");
+ $self->pidl("}");
+ }
+
my $nl = GetNextLevel($e, $l);
if (is_charset_array($e,$l)) {
@@ -1073,6 +1090,20 @@ sub ParseElementPullLevel
$length = "ndr_get_array_length($ndr, " . get_pointer_to($var_name) .")";
}
+ 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 ($length > $high) {");
+ } else {
+ $self->pidl("if ($length < $low || $length > $high) {");
+ }
+ $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value out of range\");");
+ $self->pidl("}");
+ }
+
$var_name = get_array_element($var_name, $counter);
$self->ParseMemCtxPullStart($e, $l, $ndr, $array_name);