From 960310f8b13387fe89c4db0c0dc5fd671ac5896d Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Fri, 4 Feb 2011 12:40:33 -0600 Subject: sms: Be more paranoid when loading SMS settings --- src/sms.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/sms.c b/src/sms.c index 8e3b0570..96adea16 100644 --- a/src/sms.c +++ b/src/sms.c @@ -141,7 +141,7 @@ static const char *sms_bearer_to_string(int bearer) return "cs-preferred"; }; - return "unknown"; + return NULL; } static gboolean sms_bearer_from_string(const char *str, int *bearer) @@ -1746,7 +1746,7 @@ static void mw_watch(struct ofono_atom *atom, static void sms_load_settings(struct ofono_sms *sms, const char *imsi) { - GError *error = NULL; + GError *error; sms->settings = storage_open(imsi, SETTINGS_STORE); @@ -1755,28 +1755,45 @@ static void sms_load_settings(struct ofono_sms *sms, const char *imsi) sms->imsi = g_strdup(imsi); + error = NULL; sms->ref = g_key_file_get_integer(sms->settings, SETTINGS_GROUP, - "NextReference", NULL); - if (sms->ref >= 65536) + "NextReference", &error); + + if (error || sms->ref > 65536) { sms->ref = 1; + g_key_file_set_integer(sms->settings, SETTINGS_GROUP, + "NextReference", sms->ref); + } + error = NULL; sms->use_delivery_reports = g_key_file_get_boolean(sms->settings, SETTINGS_GROUP, - "UseDeliveryReports", NULL); + "UseDeliveryReports", &error); + + if (error) + g_key_file_set_boolean(sms->settings, SETTINGS_GROUP, + "UseDeliveryReports", + sms->use_delivery_reports); + error = NULL; sms->bearer = g_key_file_get_integer(sms->settings, SETTINGS_GROUP, "Bearer", &error); - if (error) + + if (error || sms_bearer_to_string(sms->bearer) == NULL) { sms->bearer = 3; /* Default to CS then PS */ + g_key_file_set_integer(sms->settings, SETTINGS_GROUP, + "Bearer", sms->bearer); + } + error = NULL; sms->alphabet = g_key_file_get_integer(sms->settings, SETTINGS_GROUP, - "Alphabet", NULL); - if (sms_alphabet_to_string(sms->alphabet) != NULL) - return; + "Alphabet", &error); - sms->alphabet = SMS_ALPHABET_DEFAULT; - g_key_file_set_integer(sms->settings, SETTINGS_GROUP, "Alphabet", - sms->alphabet); + if (error || sms_alphabet_to_string(sms->alphabet) == NULL) { + sms->alphabet = SMS_ALPHABET_DEFAULT; + g_key_file_set_integer(sms->settings, SETTINGS_GROUP, + "Aphabet", sms->alphabet); + } } static void bearer_init_callback(const struct ofono_error *error, void *data) -- cgit v1.2.3