[PATCH] pidl: Fix python generated code

Volker Lendecke Volker.Lendecke at SerNet.DE
Tue Jun 20 13:36:48 UTC 2017


Hi!

Review appreciated!

Thanks, Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From ec4dde185593d93d78afdda6e8fe21121ceb6420 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 20 Jun 2017 15:31:18 +0200
Subject: [PATCH] pidl: Fix array range checks in python output

Without this, we generated code like

if (ndr_table_dnsserver.num_calls < 0) {
        PyErr_SetString(PyExc_TypeError, "Internal Error, ndr_interface_call missing for py_DnssrvOperation_ndr_pack");
        return NULL;
}
call = &ndr_table_dnsserver.calls[0];

This does not really make sense, and Coverity found comparing the unsigned
num_calls against <0 a bit pointless.

Should fix 138 Coverity findings and make the code a bit more correct.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 pidl/lib/Parse/Pidl/Samba4/Python.pm | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 79beb2e..11b688d 100644
--- a/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -521,7 +521,8 @@ sub PythonFunctionStruct($$$$)
 	$self->pidl("DATA_BLOB blob;");
 	$self->pidl("enum ndr_err_code err;");
 	$self->pidl("");
-	$self->pidl("if (ndr_table_$iface\.num_calls < $fn->{OPNUM}) {");
+	$self->pidl("if (ndr_table_$iface\.num_calls < " . ($fn->{OPNUM}+1) .
+		    ") {");
 	$self->indent;
 	$self->pidl("PyErr_SetString(PyExc_TypeError, \"Internal Error, ndr_interface_call missing for py_$name\_ndr_pack\");");
 	$self->pidl("return NULL;");
@@ -633,7 +634,8 @@ sub PythonFunctionStruct($$$$)
 	$self->pidl("struct ndr_pull *pull = NULL;");
 	$self->pidl("enum ndr_err_code err;");
 	$self->pidl("");
-	$self->pidl("if (ndr_table_$iface\.num_calls < $fn->{OPNUM}) {");
+	$self->pidl("if (ndr_table_$iface\.num_calls < " . ($fn->{OPNUM}+1) . 
+		    ") {");
 	$self->indent;
 	$self->pidl("PyErr_SetString(PyExc_TypeError, \"Internal Error, ndr_interface_call missing for py_$name\_ndr_unpack\");");
 	$self->pidl("return NULL;");
@@ -797,7 +799,8 @@ sub PythonFunctionStruct($$$$)
 	$self->pidl("PyObject *ret;");
 	$self->pidl("char *retstr;");
 	$self->pidl("");
-	$self->pidl("if (ndr_table_$iface\.num_calls < $fn->{OPNUM}) {");
+	$self->pidl("if (ndr_table_$iface\.num_calls < " . ($fn->{OPNUM}+1) .
+		    ") {");
 	$self->indent;
 	$self->pidl("PyErr_SetString(PyExc_TypeError, \"Internal Error, ndr_interface_call missing for py_$name\_ndr_print\");");
 	$self->pidl("return NULL;");
-- 
2.1.4



More information about the samba-technical mailing list