mirror of
https://github.com/SELinuxProject/selinux
synced 2025-01-13 00:40:52 +00:00
This patch fixes python parsing.
Eliminates a potential memory leaks.
This commit is contained in:
parent
851266c180
commit
756013edc5
@ -310,8 +310,9 @@ static PyObject *init(PyObject *self __attribute__((unused)), PyObject *args) {
|
||||
}
|
||||
|
||||
#define RETURN(X) \
|
||||
PyTuple_SetItem(result, 0, Py_BuildValue("i", X)); \
|
||||
return result;
|
||||
{ \
|
||||
return Py_BuildValue("iO", (X), Py_None); \
|
||||
}
|
||||
|
||||
static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args) {
|
||||
char *reason_buf = NULL;
|
||||
@ -329,10 +330,6 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args
|
||||
struct sepol_av_decision avd;
|
||||
int rc;
|
||||
int i=0;
|
||||
PyObject *result = PyTuple_New(2);
|
||||
if (!result) return NULL;
|
||||
Py_INCREF(Py_None);
|
||||
PyTuple_SetItem(result, 1, Py_None);
|
||||
|
||||
if (!PyArg_ParseTuple(args,(char *)"sssO!:audit2why",&scon,&tcon,&tclassstr,&PyList_Type, &listObj))
|
||||
return NULL;
|
||||
@ -343,22 +340,21 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args
|
||||
/* should raise an error here. */
|
||||
if (numlines < 0) return NULL; /* Not a list */
|
||||
|
||||
if (!avc) {
|
||||
if (!avc)
|
||||
RETURN(NOPOLICY)
|
||||
}
|
||||
|
||||
rc = sepol_context_to_sid(scon, strlen(scon) + 1, &ssid);
|
||||
if (rc < 0) {
|
||||
if (rc < 0)
|
||||
RETURN(BADSCON)
|
||||
}
|
||||
|
||||
rc = sepol_context_to_sid(tcon, strlen(tcon) + 1, &tsid);
|
||||
if (rc < 0) {
|
||||
if (rc < 0)
|
||||
RETURN(BADTCON)
|
||||
}
|
||||
|
||||
tclass = string_to_security_class(tclassstr);
|
||||
if (!tclass) {
|
||||
if (!tclass)
|
||||
RETURN(BADTCLASS)
|
||||
}
|
||||
|
||||
/* Convert the permission list to an AV. */
|
||||
av = 0;
|
||||
|
||||
@ -378,21 +374,20 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args
|
||||
#endif
|
||||
|
||||
perm = string_to_av_perm(tclass, permstr);
|
||||
if (!perm) {
|
||||
if (!perm)
|
||||
RETURN(BADPERM)
|
||||
}
|
||||
|
||||
av |= perm;
|
||||
}
|
||||
|
||||
/* Reproduce the computation. */
|
||||
rc = sepol_compute_av_reason_buffer(ssid, tsid, tclass, av, &avd, &reason, &reason_buf, 0);
|
||||
if (rc < 0) {
|
||||
if (rc < 0)
|
||||
RETURN(BADCOMPUTE)
|
||||
}
|
||||
|
||||
if (!reason) {
|
||||
if (!reason)
|
||||
RETURN(ALLOW)
|
||||
}
|
||||
|
||||
if (reason & SEPOL_COMPUTEAV_TE) {
|
||||
avc->ssid = ssid;
|
||||
avc->tsid = tsid;
|
||||
@ -405,23 +400,23 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args
|
||||
RETURN(TERULE)
|
||||
}
|
||||
} else {
|
||||
PyTuple_SetItem(result, 0, Py_BuildValue("i", BOOLEAN));
|
||||
PyObject *outboollist;
|
||||
struct boolean_t *b = bools;
|
||||
int len=0;
|
||||
while (b->name) {
|
||||
len++; b++;
|
||||
}
|
||||
b = bools;
|
||||
PyObject *outboollist = PyTuple_New(len);
|
||||
outboollist = PyList_New(len);
|
||||
len=0;
|
||||
while(b->name) {
|
||||
PyObject *bool = Py_BuildValue("(si)", b->name, b->active);
|
||||
PyTuple_SetItem(outboollist, len++, bool);
|
||||
PyObject *bool_ = Py_BuildValue("(si)", b->name, b->active);
|
||||
PyList_SetItem(outboollist, len++, bool_);
|
||||
b++;
|
||||
}
|
||||
free(bools);
|
||||
PyTuple_SetItem(result, 1, outboollist);
|
||||
return result;
|
||||
/* 'N' steals the reference to outboollist */
|
||||
return Py_BuildValue("iN", BOOLEAN, outboollist);
|
||||
}
|
||||
}
|
||||
|
||||
@ -432,7 +427,7 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args
|
||||
free(reason_buf);
|
||||
return result;
|
||||
}
|
||||
RETURN(CONSTRAINT);
|
||||
RETURN(CONSTRAINT)
|
||||
}
|
||||
|
||||
if (reason & SEPOL_COMPUTEAV_RBAC)
|
||||
|
Loading…
Reference in New Issue
Block a user