port-serial: ensure the port object is valid after BUFFER_FULL handling

The BUFFER_FULL signal handler is effectively working in the same way
as the response buffer processor, in both cases we may have scheduled
the completion of the serial command, and that in turn may end up
fully disposing the port object. We must make sure the port object is
valid for as long as we need it in this function, so we take a
reference while processing the response buffer.

Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/535
This commit is contained in:
Aleksander Morgado
2022-04-04 10:13:06 +02:00
parent 210fa8bf35
commit 19f389949c
+7 -7
View File
@@ -1017,13 +1017,6 @@ common_input_available (MMPortSerial *self,
serial_debug (self, "<--", buf, bytes_read);
g_byte_array_append (self->priv->response, (const guint8 *) buf, bytes_read);
/* Make sure the response doesn't grow too long */
if ((self->priv->response->len > SERIAL_BUF_SIZE) && self->priv->spew_control) {
/* Notify listeners and then trim the buffer */
g_signal_emit (self, signals[BUFFER_FULL], 0, self->priv->response);
g_byte_array_remove_range (self->priv->response, 0, (SERIAL_BUF_SIZE / 2));
}
/* See if we can parse anything. The response parsing may actually
* schedule the completion of a serial command, and that in turn may end
* up fully disposing this serial port object. In order to cope with
@@ -1032,6 +1025,13 @@ common_input_available (MMPortSerial *self,
* we should be keeping this socket/iochannel source or not. */
g_object_ref (self);
{
/* Make sure the response doesn't grow too long */
if ((self->priv->response->len > SERIAL_BUF_SIZE) && self->priv->spew_control) {
/* Notify listeners and then trim the buffer */
g_signal_emit (self, signals[BUFFER_FULL], 0, self->priv->response);
g_byte_array_remove_range (self->priv->response, 0, (SERIAL_BUF_SIZE / 2));
}
parse_response_buffer (self);
/* If we didn't end up closing the iochannel/socket in the previous