pidl:Python: protect for loops against $length being an expression instead of a scala...
authorStefan Metzmacher <metze@samba.org>
Thu, 11 Jun 2015 06:54:11 +0000 (08:54 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 12 Jun 2015 15:08:19 +0000 (17:08 +0200)
This changes

for (value_cntr_1 = 0; value_cntr_1 < r->out.length?*r->out.length:0; value_cntr_1++) {

into:

for (value_cntr_1 = 0; value_cntr_1 < (r->out.length?*r->out.length:0); value_cntr_1++) {

it fixes a possible endless loop resulting in a crash.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
pidl/lib/Parse/Pidl/Samba4/Python.pm

index 1d271bfa5253dd83772863bf405d5f3fea8d8971..b0a7099f1cf684fb93782b17567eb9d78a483b57 100644 (file)
@@ -1349,7 +1349,7 @@ sub ConvertObjectToPythonLevel($$$$$$)
                        $self->indent;
                        my $counter = "$e->{NAME}_cntr_$l->{LEVEL_INDEX}";
                        $self->pidl("int $counter;");
-                       $self->pidl("for ($counter = 0; $counter < $length; $counter++) {");
+                       $self->pidl("for ($counter = 0; $counter < ($length); $counter++) {");
                        $self->indent;
                        my $member_var = "py_$e->{NAME}_$l->{LEVEL_INDEX}";
                        $self->pidl("PyObject *$member_var;");