sms: prevent crash if date is out of range
g_date_time_new, and g_date_time_new_utc return NULL if inputs are out of range, and currently mm_new_iso8601_time passes the GDateTime created by those two functions to date_time_format_iso8601 without checking for NULL values, causing a g_date_time_format_iso8601 crash if PDU data is corrupted with wrong date. To prevent this, mm_new_iso8601_time now can return NULL and set a new GError if GDateTime created by g_date_time_new is NULL. Fixes #546
This commit is contained in:
@@ -1201,6 +1201,7 @@ mm_cinterion_parse_ctzu_urc (GMatchInfo *match_info,
|
||||
MMNetworkTimezone **tzp,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = TRUE;
|
||||
guint year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, dst = 0;
|
||||
gint tz = 0;
|
||||
|
||||
@@ -1229,7 +1230,9 @@ mm_cinterion_parse_ctzu_urc (GMatchInfo *match_info,
|
||||
/* Return ISO-8601 format date/time string */
|
||||
*iso8601p = mm_new_iso8601_time (year, month, day, hour,
|
||||
minute, second,
|
||||
TRUE, tz * 15);
|
||||
TRUE, tz * 15,
|
||||
error);
|
||||
ret = (*iso8601p != NULL);
|
||||
}
|
||||
|
||||
if (tzp) {
|
||||
@@ -1245,7 +1248,7 @@ mm_cinterion_parse_ctzu_urc (GMatchInfo *match_info,
|
||||
if (tzp && mm_get_uint_from_match_info (match_info, 8, &dst))
|
||||
mm_network_timezone_set_dst_offset (*tzp, dst * 60);
|
||||
|
||||
return TRUE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -1228,6 +1228,9 @@ gboolean mm_huawei_parse_nwtime_response (const gchar *response,
|
||||
mm_get_uint_from_match_info (match_info, 6, &second) &&
|
||||
mm_get_int_from_match_info (match_info, 7, &tz) &&
|
||||
mm_get_uint_from_match_info (match_info, 8, &dt)) {
|
||||
|
||||
ret = TRUE;
|
||||
|
||||
/* adjust year */
|
||||
if (year < 100)
|
||||
year += 2000;
|
||||
@@ -1240,7 +1243,9 @@ gboolean mm_huawei_parse_nwtime_response (const gchar *response,
|
||||
/* Return ISO-8601 format date/time string */
|
||||
*iso8601p = mm_new_iso8601_time (year, month, day, hour,
|
||||
minute, second,
|
||||
TRUE, (tz * 15) + (dt * 60));
|
||||
TRUE, (tz * 15) + (dt * 60),
|
||||
error);
|
||||
ret = (*iso8601p != NULL);
|
||||
}
|
||||
if (tzp) {
|
||||
*tzp = mm_network_timezone_new ();
|
||||
@@ -1248,7 +1253,6 @@ gboolean mm_huawei_parse_nwtime_response (const gchar *response,
|
||||
mm_network_timezone_set_dst_offset (*tzp, dt * 60);
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
} else {
|
||||
g_set_error_literal (error,
|
||||
MM_CORE_ERROR,
|
||||
@@ -1312,14 +1316,19 @@ gboolean mm_huawei_parse_time_response (const gchar *response,
|
||||
mm_get_uint_from_match_info (match_info, 4, &hour) &&
|
||||
mm_get_uint_from_match_info (match_info, 5, &minute) &&
|
||||
mm_get_uint_from_match_info (match_info, 6, &second)) {
|
||||
ret = TRUE;
|
||||
|
||||
/* adjust year */
|
||||
if (year < 100)
|
||||
year += 2000;
|
||||
|
||||
/* Return ISO-8601 format date/time string */
|
||||
if (iso8601p)
|
||||
if (iso8601p) {
|
||||
*iso8601p = mm_new_iso8601_time (year, month, day, hour,
|
||||
minute, second, FALSE, 0);
|
||||
ret = TRUE;
|
||||
minute, second, FALSE, 0,
|
||||
error);
|
||||
ret = (*iso8601p != NULL);
|
||||
}
|
||||
} else {
|
||||
g_set_error_literal (error,
|
||||
MM_CORE_ERROR,
|
||||
|
||||
@@ -1569,6 +1569,7 @@ parse_tlts_query_reply (const gchar *response,
|
||||
MMNetworkTimezone **tz,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = TRUE;
|
||||
gint year;
|
||||
gint month;
|
||||
gint day;
|
||||
@@ -1649,11 +1650,13 @@ parse_tlts_query_reply (const gchar *response,
|
||||
g_date_time_get_minute (adjusted),
|
||||
g_date_time_get_second (adjusted),
|
||||
TRUE,
|
||||
offset);
|
||||
offset,
|
||||
error);
|
||||
ret = (*iso8601 != NULL);
|
||||
}
|
||||
|
||||
g_date_time_unref (adjusted);
|
||||
return TRUE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static MMNetworkTimezone *
|
||||
|
||||
@@ -1431,13 +1431,13 @@ parse_nwltime_reply (const char *response,
|
||||
mm_get_int_from_match_info (match_info, 8, &utc_offset)) {
|
||||
|
||||
result = mm_new_iso8601_time (year, month, day, hour, minute, second,
|
||||
TRUE, utc_offset * 60);
|
||||
TRUE, utc_offset * 60, error);
|
||||
if (out_tz) {
|
||||
*out_tz = mm_network_timezone_new ();
|
||||
mm_network_timezone_set_offset (*out_tz, utc_offset * 60);
|
||||
}
|
||||
|
||||
success = TRUE;
|
||||
success = (result != NULL);
|
||||
} else {
|
||||
g_set_error_literal (error,
|
||||
MM_CORE_ERROR,
|
||||
|
||||
@@ -1656,7 +1656,7 @@ parse_time (const gchar *response,
|
||||
mm_get_uint_from_match_info (match_info, 4, &hour) &&
|
||||
mm_get_uint_from_match_info (match_info, 5, &minute) &&
|
||||
mm_get_uint_from_match_info (match_info, 6, &second)) {
|
||||
result = mm_new_iso8601_time (year, month, day, hour, minute, second, FALSE, 0);
|
||||
result = mm_new_iso8601_time (year, month, day, hour, minute, second, FALSE, 0, error);
|
||||
} else {
|
||||
g_set_error (error,
|
||||
MM_CORE_ERROR,
|
||||
|
||||
Reference in New Issue
Block a user