s4-python: PyErr_SetString() will crash on NULL strings
authorAndrew Tridgell <tridge@samba.org>
Mon, 19 Apr 2010 03:43:53 +0000 (13:43 +1000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 19 Apr 2010 06:34:14 +0000 (16:34 +1000)
use nt_errstr() when no error available

source4/auth/credentials/pycredentials.c
source4/libnet/py_net.c

index c5cca4fb327aa8318bbe8e74cf690fea9ff96174..361e4c9a1f1c082539a465aa0ccf1a04b763535c 100644 (file)
@@ -283,7 +283,7 @@ static PyObject *py_creds_get_named_ccache(py_talloc_Object *self, PyObject *arg
                return PyCredentialCacheContainer_from_ccache_container(ccc);
        }
 
-       PyErr_SetString(PyExc_RuntimeError, error_string);
+       PyErr_SetString(PyExc_RuntimeError, error_string?error_string:"NULL");
 
        talloc_free(event_ctx);
        return NULL;
index ec41ca38a8d3c0431ad3e44923ef215d3ae0dacf..6bd4c0ca847660297ff35b4cfe1c05564bae2af9 100644 (file)
@@ -52,7 +52,7 @@ static PyObject *py_net_join(py_net_Object *self, PyObject *args, PyObject *kwar
 
        status = libnet_Join(self->libnet_ctx, mem_ctx, &r);
        if (NT_STATUS_IS_ERR(status)) {
-               PyErr_SetString(PyExc_RuntimeError, r.out.error_string);
+               PyErr_SetString(PyExc_RuntimeError, r.out.error_string?r.out.error_string:nt_errstr(status));
                talloc_free(mem_ctx);
                return NULL;
        }
@@ -93,7 +93,8 @@ static PyObject *py_net_set_password(py_net_Object *self, PyObject *args, PyObje
 
        status = libnet_SetPassword(self->libnet_ctx, mem_ctx, &r);
        if (NT_STATUS_IS_ERR(status)) {
-               PyErr_SetString(PyExc_RuntimeError, r.generic.out.error_string);
+               PyErr_SetString(PyExc_RuntimeError,
+                               r.generic.out.error_string?r.generic.out.error_string:nt_errstr(status));
                talloc_free(mem_ctx);
                return NULL;
        }
@@ -127,7 +128,8 @@ static PyObject *py_net_export_keytab(py_net_Object *self, PyObject *args, PyObj
 
        status = libnet_export_keytab(self->libnet_ctx, mem_ctx, &r);
        if (NT_STATUS_IS_ERR(status)) {
-               PyErr_SetString(PyExc_RuntimeError, r.out.error_string);
+               PyErr_SetString(PyExc_RuntimeError,
+                               r.out.error_string?r.out.error_string:nt_errstr(status));
                talloc_free(mem_ctx);
                return NULL;
        }
@@ -164,7 +166,8 @@ static PyObject *py_net_time(py_net_Object *self, PyObject *args, PyObject *kwar
 
        status = libnet_RemoteTOD(self->libnet_ctx, mem_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
-               PyErr_SetString(PyExc_RuntimeError, r.generic.out.error_string);
+               PyErr_SetString(PyExc_RuntimeError,
+                               r.generic.out.error_string?r.generic.out.error_string:nt_errstr(status));
                talloc_free(mem_ctx);
                return NULL;
        }
@@ -204,7 +207,7 @@ static PyObject *py_net_user_create(py_net_Object *self, PyObject *args, PyObjec
 
        status = libnet_CreateUser(self->libnet_ctx, mem_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
-               PyErr_SetString(PyExc_RuntimeError, r.out.error_string);
+               PyErr_SetString(PyExc_RuntimeError, r.out.error_string?r.out.error_string:nt_errstr(status));
                talloc_free(mem_ctx);
                return NULL;
        }
@@ -238,7 +241,7 @@ static PyObject *py_net_user_delete(py_net_Object *self, PyObject *args, PyObjec
 
        status = libnet_DeleteUser(self->libnet_ctx, mem_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
-               PyErr_SetString(PyExc_RuntimeError, r.out.error_string);
+               PyErr_SetString(PyExc_RuntimeError, r.out.error_string?r.out.error_string:nt_errstr(status));
                talloc_free(mem_ctx);
                return NULL;
        }