ndr/py_security: mod patch reports errors
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 27 Oct 2023 00:19:47 +0000 (13:19 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 1 Nov 2023 20:10:46 +0000 (20:10 +0000)
We can, so we might as well.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/librpc/ndr/py_security.c

index 9b1e95e0f48ceeede98d29d1b84c75e1c353a837..9c292c39234a8f9460d13da96a95d147182f281d 100644 (file)
@@ -564,17 +564,29 @@ static PyMethodDef py_mod_security_extra_methods[] = {
        {0}
 };
 
-static void py_mod_security_patch(PyObject *m)
+static bool py_mod_security_patch(PyObject *m)
 {
+       int ret;
        int i;
        for (i = 0; py_mod_security_extra_methods[i].ml_name; i++) {
                PyObject *descr = PyCFunction_New(&py_mod_security_extra_methods[i], NULL);
-               PyModule_AddObject(m, py_mod_security_extra_methods[i].ml_name,
-                                  descr);
+               ret = PyModule_AddObject(m, py_mod_security_extra_methods[i].ml_name,
+                                        descr);
+               if (ret != 0) {
+                       return false;
+               }
        }
+       return true;
 }
 
-#define PY_MOD_SECURITY_PATCH py_mod_security_patch
+#define PY_MOD_SECURITY_PATCH(m)                       \
+       do {                                            \
+               bool _ok = py_mod_security_patch(m);    \
+               if (! _ok) {                            \
+                       Py_XDECREF(m);                  \
+                       return NULL;                    \
+               }                                       \
+       } while(0)
 
 static PyObject *py_security_ace_equal(PyObject *py_self, PyObject *py_other, int op)
 {