[PATCH 1/2] telit: make sure QSS status values read are always known

Aleksander Morgado aleksander at aleksander.es
Fri Jun 2 11:10:49 UTC 2017


Given that the MMTelitQssStatus enums are mapped directly to the
values read from the #QSS response, we need to make sure that we never
return a value for which we don't have an enum defined.

Also, use set_error() instead of the propagate_error() + error_new()
combo.
---
 plugins/telit/mm-modem-helpers-telit.c            | 20 +++++++++++++++-----
 plugins/telit/tests/test-mm-modem-helpers-telit.c |  1 +
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/plugins/telit/mm-modem-helpers-telit.c b/plugins/telit/mm-modem-helpers-telit.c
index a58644d1..5a7ecb79 100644
--- a/plugins/telit/mm-modem-helpers-telit.c
+++ b/plugins/telit/mm-modem-helpers-telit.c
@@ -590,6 +590,7 @@ mm_telit_get_band_flags_from_string (const gchar *flag_str,
 
 /*****************************************************************************/
 /* #QSS? response parser */
+
 MMTelitQssStatus
 mm_telit_parse_qss_query (const gchar *response,
                           GError **error)
@@ -599,11 +600,20 @@ mm_telit_parse_qss_query (const gchar *response,
 
     qss_status = QSS_STATUS_UNKNOWN;
     if (sscanf (response, "#QSS: %d,%d", &qss_mode, &qss_status) != 2) {
-        g_propagate_error (error,
-                           g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
-                                        "Could not parse \"#QSS?\" response: %s",
-                                        response));
+        g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+                     "Could not parse \"#QSS?\" response: %s", response);
+        return QSS_STATUS_UNKNOWN;
     }
 
-    return (MMTelitQssStatus)qss_status;
+    switch (qss_status) {
+    case QSS_STATUS_SIM_REMOVED:
+    case QSS_STATUS_SIM_INSERTED:
+    case QSS_STATUS_SIM_INSERTED_AND_UNLOCKED:
+    case QSS_STATUS_SIM_INSERTED_AND_READY:
+        return (MMTelitQssStatus) qss_status;
+    default:
+        g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+                     "Unknown QSS status value given: %d", qss_status);
+        return QSS_STATUS_UNKNOWN;
+    }
 }
diff --git a/plugins/telit/tests/test-mm-modem-helpers-telit.c b/plugins/telit/tests/test-mm-modem-helpers-telit.c
index dba635a2..e42467ea 100644
--- a/plugins/telit/tests/test-mm-modem-helpers-telit.c
+++ b/plugins/telit/tests/test-mm-modem-helpers-telit.c
@@ -518,6 +518,7 @@ static QssParseTest qss_parse_tests [] = {
     {"#QSS: 0, 3", QSS_STATUS_SIM_INSERTED_AND_READY, NULL},
     {"#QSS: 0", QSS_STATUS_UNKNOWN, "Could not parse \"#QSS?\" response: #QSS: 0"},
     {"QSS:0,1", QSS_STATUS_UNKNOWN, "Could not parse \"#QSS?\" response: QSS:0,1"},
+    {"#QSS: 0,5", QSS_STATUS_UNKNOWN, "Unknown QSS status value given: 5"},
 };
 
 static void
-- 
2.13.0



More information about the ModemManager-devel mailing list