pidl/ndr/python: avoid memory errors in getsetters
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 1 Aug 2019 23:29:55 +0000 (23:29 +0000)
committerNoel Power <npower@samba.org>
Tue, 6 Aug 2019 18:17:11 +0000 (18:17 +0000)
This:

   $ python3 -c'from samba.dcerpc import lsa; x = lsa.EnumAccounts(); x.in_handle'

should not raise a MemoryError, which is very unfriendly given that
'x.in_handle' is just named, not called, as far as the user is
concerned. Returning None is the proper thing.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Noel Power <npower@samba.org>
Autobuild-User(master): Noel Power <npower@samba.org>
Autobuild-Date(master): Tue Aug  6 18:17:11 UTC 2019 on sn-devel-184

pidl/lib/Parse/Pidl/Samba4/Python.pm

index 97c417adf35c4e8dc2f750f28041c3509c26092e..8d5de31e7bb2f9f4bad77051b5f6ce6436178415 100644 (file)
@@ -201,6 +201,14 @@ sub PythonElementGetSet($$$$$$) {
        $self->indent;
        $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(obj);");
        $self->pidl("PyObject *py_$e->{NAME};");
+       my $l = $e->{LEVELS}[0];
+       if ($l->{TYPE} eq "POINTER") {
+               $self->pidl("if ($varname == NULL) {");
+               $self->indent;
+               $self->pidl("Py_RETURN_NONE;");
+               $self->deindent;
+               $self->pidl("}");
+       }
        $self->ConvertObjectToPython("pytalloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}", "return NULL;");
        $self->pidl("return py_$e->{NAME};");
        $self->deindent;