summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Chan <benchan@chromium.org>2018-01-31 21:56:40 -0800
committerAleksander Morgado <aleksander@aleksander.es>2018-02-06 18:01:49 +0100
commit87ecbf8ea8de17309c8a88bb5b831a7348c3b523 (patch)
tree586d4339fafbb4766255d0c087d0fdd9404bff4b
parent2bf7eae99e81fae932ca672f8148dbac2eb59a5c (diff)
libmbim-glib,message: handle unknown status when setting error
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. (cherry picked from commit 2e99e5f8a8cf2e73cea971abae35731b80249941)
-rw-r--r--src/libmbim-glib/mbim-message.c40
1 files 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;
}