Commit b26fe50e by Mathijs van de Nes Committed by Victor M. Alvarez

Check if file is actually a file object (#32)

If it is not a file like object, the function would return -1. This
would eventually lead to a segmention fault later on.
parent 9fd9fd29
......@@ -1829,9 +1829,16 @@ static PyObject* yara_compile(
else if (file != NULL)
{
fd = dup(PyObject_AsFileDescriptor(file));
fh = fdopen(fd, "r");
error = yr_compiler_add_file(compiler, fh, NULL, NULL);
fclose(fh);
if (fd != -1) {
fh = fdopen(fd, "r");
error = yr_compiler_add_file(compiler, fh, NULL, NULL);
fclose(fh);
}
else {
result = PyErr_Format(
PyExc_TypeError,
"'file' is not a file object");
}
}
else if (sources_dict != NULL)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment