cinterion: make sure FALSE sets GError in provcfg_response_to_cid()
The g_regex_match_full() method may return FALSE without setting the GError, so that case needs to be considered. Reported by Jan Mazura. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/347
This commit is contained in:
@@ -1514,12 +1514,24 @@ mm_cinterion_provcfg_response_to_cid (const gchar *response,
|
||||
g_autoptr(GRegex) r = NULL;
|
||||
g_autoptr(GMatchInfo) match_info = NULL;
|
||||
g_autofree gchar *mno = NULL;
|
||||
GError *inner_error = NULL;
|
||||
|
||||
r = g_regex_new ("\\^SCFG:\\s*\"MEopMode/Prov/Cfg\",\\s*\"([0-9a-zA-Z*]*)\"", 0, 0, NULL);
|
||||
g_assert (r != NULL);
|
||||
|
||||
if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, error))
|
||||
g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error);
|
||||
|
||||
if (inner_error) {
|
||||
g_prefix_error (&inner_error, "Failed to match Prov/Cfg response: ");
|
||||
g_propagate_error (error, inner_error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!g_match_info_matches (match_info)) {
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"Couldn't match Prov/Cfg response");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
mno = mm_get_string_unquoted_from_match_info (match_info, 1);
|
||||
if (mno && modem_family == MM_CINTERION_MODEM_FAMILY_IMT) {
|
||||
|
@@ -1602,45 +1602,57 @@ test_smoni_response_to_signal (void)
|
||||
typedef struct {
|
||||
const gchar *str;
|
||||
MMCinterionModemFamily modem_family;
|
||||
gdouble expected_cid;
|
||||
gboolean success;
|
||||
guint expected_cid;
|
||||
} ProvcfgResponseTest;
|
||||
|
||||
|
||||
static const ProvcfgResponseTest provcfg_response_tests[] = {
|
||||
{
|
||||
|
||||
.str = "^SCFG: \"MEopMode/Prov/Cfg\",\"vdfde\"",
|
||||
.modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT,
|
||||
.success = TRUE,
|
||||
.expected_cid = 1,
|
||||
},
|
||||
{
|
||||
|
||||
.str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"attus\"",
|
||||
.modem_family = MM_CINTERION_MODEM_FAMILY_IMT,
|
||||
.success = TRUE,
|
||||
.expected_cid = 1,
|
||||
},
|
||||
{
|
||||
|
||||
.str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"2\"",
|
||||
.modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT,
|
||||
.success = TRUE,
|
||||
.expected_cid = 3,
|
||||
},
|
||||
{
|
||||
|
||||
.str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"vzwdcus\"",
|
||||
.modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT,
|
||||
.success = TRUE,
|
||||
.expected_cid = 3,
|
||||
},
|
||||
{
|
||||
|
||||
.str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"tmode\"",
|
||||
.modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT,
|
||||
.success = TRUE,
|
||||
.expected_cid = 2,
|
||||
},
|
||||
{
|
||||
.str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"fallback*\"",
|
||||
.modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT,
|
||||
.success = TRUE,
|
||||
.expected_cid = 1,
|
||||
},
|
||||
{
|
||||
/* commas not allowed by the regex */
|
||||
.str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"something,with,commas\"",
|
||||
.modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT,
|
||||
.success = FALSE,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1660,9 +1672,14 @@ test_provcfg_response (void)
|
||||
NULL,
|
||||
&cid,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (result);
|
||||
g_assert_cmpuint (cid, ==, provcfg_response_tests[i].expected_cid);
|
||||
if (provcfg_response_tests[i].success) {
|
||||
g_assert_no_error (error);
|
||||
g_assert (result);
|
||||
g_assert_cmpuint (cid, ==, provcfg_response_tests[i].expected_cid);
|
||||
} else {
|
||||
g_assert (error);
|
||||
g_assert (!result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user