Skip to content

Commit

Permalink
Check return value of __pycomps_arg_to_char and add a test
Browse files Browse the repository at this point in the history
It fixes a crash when the conversion to char is not successful.
  • Loading branch information
kontura authored and m-blaha committed Aug 10, 2021
1 parent b11abfc commit 7b42c5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libcomps/src/python/src/pycomps.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,10 @@ PyObject* PyCOMPS_filter_arches(PyObject *self, PyObject *other) {
for (Py_ssize_t x=0; x < PyList_Size(other); x++) {
item = PyList_GetItem(other, x);
char *str;
__pycomps_arg_to_char(item, &str);
if (__pycomps_arg_to_char(item, &str)) {
COMPS_OBJECT_DESTROY(arches);
return NULL;
}
comps_objlist_append_x(arches, (COMPS_Object*)comps_str_x(str));
}
} else {
Expand Down
5 changes: 5 additions & 0 deletions libcomps/src/python/tests/__test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,11 @@ def test_arches(self):
comps5.fromxml_str(s)
self.assertTrue(comps == comps5)

def test_arches_invalid_input(self):
INVALID_UTF8_CHAR = '\udcfd'
c = libcomps.Comps()
self.assertRaises(TypeError, c.arch_filter, [INVALID_UTF8_CHAR])

#@unittest.skip("")
def test_validate(self):
c = libcomps.Comps()
Expand Down

0 comments on commit 7b42c5e

Please sign in to comment.