Skip to content
Snippets Groups Projects
Commit cc1fd897 authored by Russell Jancewicz's avatar Russell Jancewicz
Browse files

Merge pull request #38 from j3ffhubb/principal_exists_segfault

Fix a segfault when calling .principal_exists with an invalid principal
parents 18054ac8 c744a2b5
No related branches found
No related tags found
No related merge requests found
...@@ -86,9 +86,10 @@ static PyObject *PyKAdminObject_principal_exists(PyKAdminObject *self, PyObject ...@@ -86,9 +86,10 @@ static PyObject *PyKAdminObject_principal_exists(PyKAdminObject *self, PyObject
krb5_principal princ = NULL; krb5_principal princ = NULL;
char *client_name = NULL; char *client_name = NULL;
PyObject *result = NULL; PyObject *result = Py_False;
kadm5_principal_ent_rec entry; kadm5_principal_ent_rec entry;
int entry_initialized = 0;
if (!PyArg_ParseTuple(args, "s", &client_name)) if (!PyArg_ParseTuple(args, "s", &client_name))
return NULL; return NULL;
...@@ -102,7 +103,11 @@ static PyObject *PyKAdminObject_principal_exists(PyKAdminObject *self, PyObject ...@@ -102,7 +103,11 @@ static PyObject *PyKAdminObject_principal_exists(PyKAdminObject *self, PyObject
} }
retval = kadm5_get_principal(self->server_handle, princ, &entry, KADM5_PRINCIPAL); retval = kadm5_get_principal(self->server_handle, princ, &entry, KADM5_PRINCIPAL);
if (retval == KADM5_OK) { result = Py_True; }
if (retval == KADM5_OK) {
result = Py_True;
entry_initialized = 1;
}
else if (retval == KADM5_UNK_PRINC) { result = Py_False; } else if (retval == KADM5_UNK_PRINC) { result = Py_False; }
else { else {
PyKAdminError_raise_error(retval, "kadm5_get_principal"); PyKAdminError_raise_error(retval, "kadm5_get_principal");
...@@ -113,7 +118,10 @@ static PyObject *PyKAdminObject_principal_exists(PyKAdminObject *self, PyObject ...@@ -113,7 +118,10 @@ static PyObject *PyKAdminObject_principal_exists(PyKAdminObject *self, PyObject
cleanup: cleanup:
krb5_free_principal(self->context, princ); krb5_free_principal(self->context, princ);
kadm5_free_principal_ent(self->server_handle, &entry);
if(entry_initialized) {
kadm5_free_principal_ent(self->server_handle, &entry);
}
Py_XINCREF(result); Py_XINCREF(result);
return result; return result;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment