diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2013-04-24 23:05:12 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-04-25 09:36:51 +0200 |
commit | 40dc35a65718050297b12c6e7c106866a44a3305 (patch) | |
tree | 9f15511acd633dfc87f11ffebd8fb9836520b533 | |
parent | 1f99eaf80e6c3124c871c416638d50c57199535e (diff) | |
download | ModemManager-40dc35a65718050297b12c6e7c106866a44a3305.tar.gz |
modem-helpers: ensure error is set when +CRM response parser doesn't match
-rw-r--r-- | src/mm-modem-helpers.c | 81 |
1 files changed, 44 insertions, 37 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 9652c6f4e..09bb71d79 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -2021,7 +2021,8 @@ mm_cdma_parse_crm_test_response (const gchar *reply, { gboolean result = FALSE; GRegex *r; - + GMatchInfo *match_info = NULL; + GError *match_error = NULL; /* Expected reply format is: * ---> AT+CRM=? @@ -2031,46 +2032,52 @@ mm_cdma_parse_crm_test_response (const gchar *reply, r = g_regex_new ("\\+CRM:\\s*\\((\\d+)-(\\d+)\\)", G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, 0, error); - if (r) { - GMatchInfo *match_info = NULL; - - if (g_regex_match_full (r, reply, strlen (reply), 0, 0, &match_info, error)) { - gchar *aux; - guint min_val = 0; - guint max_val = 0; - - aux = g_match_info_fetch (match_info, 1); - min_val = (guint) atoi (aux); - g_free (aux); - - aux = g_match_info_fetch (match_info, 2); - max_val = (guint) atoi (aux); - g_free (aux); - - if (min_val == 0 || - max_val == 0 || - min_val >= max_val) { - g_set_error (error, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Couldn't parse CRM range: " - "Unexpected range of RM protocols (%u,%u)", - min_val, - max_val); - } else { - *min = mm_cdma_get_rm_protocol_from_index (min_val, error); - if (*min != MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN) { - *max = mm_cdma_get_rm_protocol_from_index (max_val, error); - if (*max != MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN) - result = TRUE; - } + g_assert (r != NULL); + + if (g_regex_match_full (r, reply, strlen (reply), 0, 0, &match_info, &match_error)) { + gchar *aux; + guint min_val = 0; + guint max_val = 0; + + aux = g_match_info_fetch (match_info, 1); + min_val = (guint) atoi (aux); + g_free (aux); + + aux = g_match_info_fetch (match_info, 2); + max_val = (guint) atoi (aux); + g_free (aux); + + if (min_val == 0 || + max_val == 0 || + min_val >= max_val) { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't parse CRM range: " + "Unexpected range of RM protocols (%u,%u)", + min_val, + max_val); + } else { + *min = mm_cdma_get_rm_protocol_from_index (min_val, error); + if (*min != MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN) { + *max = mm_cdma_get_rm_protocol_from_index (max_val, error); + if (*max != MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN) + result = TRUE; } } - - g_match_info_free (match_info); - g_regex_unref (r); + } else if (match_error) { + g_propagate_error (error, match_error); + } else { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't parse CRM range: response didn't match (%s)", + reply); } + g_match_info_free (match_info); + g_regex_unref (r); + return result; } |