[PATCH 1/2] libmbim-glib, message: handle unknown status when setting error
Ben Chan
benchan at chromium.org
Tue Feb 6 14:06:51 UTC 2018
Hi Aleksander,
What do you think about this two patches?
Thanks
Ben
On Wed, Jan 31, 2018, 9:56 PM Ben Chan <benchan at chromium.org> wrote:
> g_set_error_literal() requires a non-NULL 'message' argument. Passing
> mbim_status_error_get_string() as the 'message' argument to
> g_set_error_literal() could result in an assertion as
> mbim_status_error_get_string() returns NULL for a status code without an
> associated MbimStatusError enum.
> ---
> src/libmbim-glib/mbim-message.c | 40
> ++++++++++++++++++++++++----------------
> 1 file changed, 24 insertions(+), 16 deletions(-)
>
> diff --git a/src/libmbim-glib/mbim-message.c
> b/src/libmbim-glib/mbim-message.c
> index 06b9eb8..0ab4667 100644
> --- a/src/libmbim-glib/mbim-message.c
> +++ b/src/libmbim-glib/mbim-message.c
> @@ -59,6 +59,26 @@ bytearray_apply_padding (GByteArray *buffer,
> }
> }
>
> +static void
> +set_error_from_status (GError **error,
> + MbimStatusError status)
> +{
> + const gchar *error_string;
> +
> + error_string = mbim_status_error_get_string (status);
> + if (error_string)
> + g_set_error_literal (error,
> + MBIM_STATUS_ERROR,
> + status,
> + error_string);
> + else
> + g_set_error (error,
> + MBIM_STATUS_ERROR,
> + status,
> + "Unknown status 0x%08x",
> + status);
> +}
> +
>
> /*****************************************************************************/
>
> GType
> @@ -1605,10 +1625,7 @@ mbim_message_open_done_get_result (const
> MbimMessage *self,
> if (status == MBIM_STATUS_ERROR_NONE)
> return TRUE;
>
> - g_set_error_literal (error,
> - MBIM_STATUS_ERROR,
> - status,
> - mbim_status_error_get_string (status));
> + set_error_from_status (error, status);
> return FALSE;
> }
>
> @@ -1701,10 +1718,7 @@ mbim_message_close_done_get_result (const
> MbimMessage *self,
> if (status == MBIM_STATUS_ERROR_NONE)
> return TRUE;
>
> - g_set_error_literal (error,
> - MBIM_STATUS_ERROR,
> - status,
> - mbim_status_error_get_string (status));
> + set_error_from_status (error, status);
> return FALSE;
> }
>
> @@ -2066,10 +2080,7 @@ mbim_message_command_done_get_result (const
> MbimMessage *self,
> if (status == MBIM_STATUS_ERROR_NONE)
> return TRUE;
>
> - g_set_error_literal (error,
> - MBIM_STATUS_ERROR,
> - status,
> - mbim_status_error_get_string (status));
> + set_error_from_status (error, status);
> return FALSE;
> }
>
> @@ -2238,9 +2249,6 @@ mbim_message_response_get_result (const MbimMessage
> *self,
> return TRUE;
>
> /* Build error */
> - g_set_error_literal (error,
> - MBIM_STATUS_ERROR,
> - status,
> - mbim_status_error_get_string (status));
> + set_error_from_status (error, status);
> return FALSE;
> }
> --
> 2.16.0.rc1.238.g530d649a79-goog
>
> _______________________________________________
> libmbim-devel mailing list
> libmbim-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/libmbim-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libmbim-devel/attachments/20180206/9de2d6a9/attachment.html>
More information about the libmbim-devel
mailing list