libselinux: remove rpm_execcon from SWIG wrappers

The Python wrapper of rpm_execcon() has several flaws:
* An invalid call like selinux.rpm_execcon() triggers a segmentation
  fault.
* The size of the buffer which is allocated to copy argv and envp is
  too small to hold all the values.
* This allocated memory is leaked if one argument of rpm_execon() is not
  a sequence of bytes.

The Ruby wrapper has no such flaws but can not be used as it is because
it misses some glue code to convert argv and envp arguments to char
*const [] values (even though the destructor is present!).

As it is not possible to remove rpm_execcon() without changing
libselinux soname (it would be an ABI break) like b67fefd991
("libselinux: set DISABLE_RPM default to y.") tried to do, disable this
interface locally in the SWIG wrappers.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
This commit is contained in:
Nicolas Iooss 2016-11-05 21:55:32 +01:00 committed by Stephen Smalley
parent 1ce3e23b89
commit 581dde735a
2 changed files with 10 additions and 46 deletions

View File

@ -1,6 +1,11 @@
/* Author: James Athey
*/
/* Never build rpm_execcon interface */
#ifndef DISABLE_RPM
#define DISABLE_RPM
#endif
%module selinux
%{
#include "selinux/selinux.h"
@ -153,42 +158,5 @@ def install(src, dest):
}
}
%typemap(in) char * const [] {
int i, size;
PyObject * s;
if (!PySequence_Check($input)) {
PyErr_SetString(PyExc_ValueError, "Expected a sequence");
return NULL;
}
size = PySequence_Size($input);
$1 = (char**) malloc(size + 1);
for(i = 0; i < size; i++) {
if (!PyString_Check(PySequence_GetItem($input, i))) {
PyErr_SetString(PyExc_ValueError, "Sequence must contain only strings");
return NULL;
}
}
for(i = 0; i < size; i++) {
s = PySequence_GetItem($input, i);
$1[i] = (char*) malloc(PyString_Size(s) + 1);
strcpy($1[i], PyString_AsString(s));
}
$1[size] = NULL;
}
%typemap(freearg,match="in") char * const [] {
int i = 0;
while($1[i]) {
free($1[i]);
i++;
}
free($1);
}
%include "selinuxswig_python_exception.i"
%include "selinuxswig.i"

View File

@ -2,6 +2,11 @@
Based on selinuxswig_python.i by James Athey
*/
/* Never build rpm_execcon interface */
#ifndef DISABLE_RPM
#define DISABLE_RPM
#endif
%module selinux
%{
#include "selinux/selinux.h"
@ -40,13 +45,4 @@
}
}
%typemap(freearg,match="in") char * const [] {
int i = 0;
while($1[i]) {
free($1[i]);
i++;
}
free($1);
}
%include "selinuxswig.i"