Python pidl: avoid segfault with "del obj->attr"
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 4 May 2016 04:51:37 +0000 (16:51 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 9 May 2016 23:43:15 +0000 (01:43 +0200)
Deleting an attribute in Python (using the "del" statement) is (at
some stages along a winding path, for C objects) converted into
setting the attribute to NULL. Not None, actual NULL. The way we
handled this NULL was to dereference it. This changes the behaviour to
raising an AttributeError, which is more or less what Python does in
similar situations with builtin objects.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
pidl/lib/Parse/Pidl/Samba4/Python.pm

index 9e39167eb7e7337cde266afdc42a76aa6e0cbf56..f43e4d624433e218aab63fdd60c4953b9f015792 100644 (file)
@@ -1218,6 +1218,14 @@ sub ConvertObjectFromPythonLevel($$$$$$$$)
                $pl = GetPrevLevel($e, $pl);
        }
 
+        $self->pidl("if ($py_var == NULL) {");
+        $self->indent;
+        $self->pidl("PyErr_Format(PyExc_AttributeError, \"Cannot delete NDR object: " .
+                    mapTypeName($var_name) . "\");");
+        $self->pidl($fail);
+        $self->deindent;
+        $self->pidl("}");
+
        if ($l->{TYPE} eq "POINTER") {
                if ($l->{POINTER_TYPE} ne "ref") {
                        $self->pidl("if ($py_var == Py_None) {");