[PATCH 1/2] libmbim-glib,message: handle unknown status when setting error

Aleksander Morgado aleksander at aleksander.es
Tue Feb 6 17:02:57 UTC 2018


On Thu, Feb 1, 2018 at 6:56 AM, 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.
> ---

Pushed to git master and stable branches.

>  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
>



-- 
Aleksander
https://aleksander.es


More information about the libmbim-devel mailing list