core: don't crash on error if response is NULL

Various bits of the code didn't check if response was valid
or not during error conditions, and when an error occurs
sometimes it'll be NULL (since not all errors are translated
errors from the modem, some are serial or general ones).  We
have to make sure we don't try to use response->str when
response doesn't exist.

Found in the generic CDMA code likely as a result of
d5d9eec2b5 but was a bug long
before that commit happened anyway.
This commit is contained in:
Dan Williams
2011-12-07 17:07:46 -06:00
parent c1e64f1a33
commit 2af1a612e9
6 changed files with 13 additions and 7 deletions
+3 -1
View File
@@ -730,7 +730,9 @@ enap_poll_response (MMAtSerialPort *port,
count = GPOINTER_TO_UINT (mm_callback_info_get_data (info, "mbm-enap-poll-count"));
if (sscanf (response->str, "*ENAP: %d", &state) == 1 && state == 1) {
if ( response
&& sscanf (response->str, "*ENAP: %d", &state) == 1
&& state == 1) {
/* Success! Connected... */
mm_generic_gsm_connect_complete (MM_GENERIC_GSM (info->modem), NULL, info);
return;
+2 -1
View File
@@ -72,12 +72,13 @@ custom_init_response_cb (MMPluginBaseSupportsTask *task,
guint32 *out_level,
gpointer user_data)
{
const char *p = response->str;
const char *p;
if (error)
return tries <= 4 ? TRUE : FALSE;
/* Note the lack of a ':' on the GMR; the X200 doesn't send one */
g_assert (response);
p = mm_strip_tag (response->str, "AT+GMR");
if (*p == 'L') {
/* X200 modems have a GMR firmware revision that starts with 'L', and
+2 -1
View File
@@ -70,12 +70,13 @@ custom_init_response_cb (MMPluginBaseSupportsTask *task,
guint32 *out_level,
gpointer user_data)
{
const char *p = response->str;
const char *p;
if (error)
return tries <= 4 ? TRUE : FALSE;
/* Note the lack of a ':' on the GMR; the X200 doesn't send one */
g_assert (response);
p = mm_strip_tag (response->str, "AT+GMR");
if (*p != 'L') {
/* X200 modems have a GMR firmware revision that starts with 'L', and
+3 -2
View File
@@ -988,7 +988,6 @@ get_signal_quality_done (MMAtSerialPort *port,
{
MMGenericCdmaPrivate *priv;
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
char *reply = response->str;
/* If the modem has already been removed, return without
* scheduling callback */
@@ -1008,6 +1007,7 @@ get_signal_quality_done (MMAtSerialPort *port,
return;
}
} else {
const char *reply = response->str;
int quality, ber;
/* Got valid reply */
@@ -1273,7 +1273,7 @@ serving_system_done (MMAtSerialPort *port,
gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
char *reply = response->str;
char *reply;
int class = 0, sid = 99999, num;
unsigned char band = 'Z';
gboolean success = FALSE;
@@ -1288,6 +1288,7 @@ serving_system_done (MMAtSerialPort *port,
goto out;
}
reply = response->str;
if (strstr (reply, "+CSS: "))
reply += 6;
+1 -1
View File
@@ -350,7 +350,7 @@ pin_check_done (MMAtSerialPort *port,
info->error = g_error_new (MM_MODEM_ERROR,
MM_MODEM_ERROR_GENERAL,
"Could not parse PIN request response '%s'",
response->str);
response ? response->str : "(unknown)");
}
}
+2 -1
View File
@@ -553,9 +553,10 @@ info_item_done (MMCallbackInfo *info,
const char *tag2,
const char *desc)
{
const char *p = response->str;
const char *p;
if (!error) {
p = response->str;
if (tag)
p = mm_strip_tag (p, tag);
if (tag2)