Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
python: Avoid crash if callback parameters cannot be built
In the case that building the parameters to the Python event callback
fails, args was returned as NULL.  We immediately tried to call
Py_INCREF on this which crashed.  Returning NULL means the Python
function threw an exception, so print the exception and return (there
is no way to return an error here - the event is lost).

Reported-by: Yonatan Shtarkman
See: https://listman.redhat.com/archives/libguestfs/2023-February/030653.html
  • Loading branch information
rwmjones committed Feb 14, 2023
1 parent 43bb5c4 commit 6ef5837
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions python/handle.c
Expand Up @@ -134,18 +134,21 @@ guestfs_int_py_event_callback_wrapper (guestfs_h *g,
args = Py_BuildValue ("(Kis#O)",
(unsigned PY_LONG_LONG) event, event_handle,
buf, buf_len, py_array);
Py_INCREF (args);
if (args == NULL) {
PyErr_PrintEx (0);
goto out;
}

Py_INCREF (args);
py_r = PyObject_CallObject (py_callback, args);

Py_DECREF (args);

if (py_r != NULL)
Py_DECREF (py_r);
else
/* Callback threw an exception: print it. */
PyErr_PrintEx (0);

out:
PyGILState_Release (py_save);
}

Expand Down

0 comments on commit 6ef5837

Please sign in to comment.