Bug #710997 - Check some return values before use
authorMurray Cumming <murrayc@openismus.com>
Tue, 25 Feb 2014 15:14:29 +0000 (16:14 +0100)
committerMilan Crha <mcrha@redhat.com>
Tue, 25 Feb 2014 15:14:29 +0000 (16:14 +0100)
Check that some return values are not NULL before using them,
in functions that do not check, such as strcmp(), or before
dereferencing.

addressbook/backends/file/e-book-backend-file.c
addressbook/libedata-book/e-book-backend-sqlitedb-test.c
addressbook/libedata-book/e-book-backend-sqlitedb.c
calendar/backends/file/e-cal-backend-file.c
calendar/backends/http/e-cal-backend-http.c
calendar/libecal/e-cal-client.c
calendar/libedata-cal/e-cal-backend-intervaltree.c
calendar/libedata-cal/e-cal-backend.c

index 958c3e7..87cd8b9 100644 (file)
@@ -963,7 +963,7 @@ book_view_thread (gpointer data)
        fields_of_interest = e_data_book_view_get_fields_of_interest (book_view);
        meta_contact = uid_rev_fields (fields_of_interest);
 
-       if ( !strcmp (query, "(contains \"x-evolution-any-field\" \"\")")) {
+       if (query && !strcmp (query, "(contains \"x-evolution-any-field\" \"\")")) {
                e_data_book_view_notify_progress (book_view, -1, _("Loading..."));
        } else {
                e_data_book_view_notify_progress (book_view, -1, _("Searching..."));
index ba56ddb..3d39147 100644 (file)
@@ -96,7 +96,7 @@ search_db (EBookBackendSqliteDB *ebsdb,
        g_print ("%s - query: %s \n", type, sexp);
        op = type;
        vcards = e_book_backend_sqlitedb_search (ebsdb, folderid, sexp, NULL, NULL, NULL, &error);
-       if (error)
+       if (error || !vcards)
                return;
 
        s_data = vcards->data;
index 9a3b4e6..7f5396c 100644 (file)
@@ -1832,7 +1832,7 @@ e_book_backend_sqlitedb_new_full (const gchar *path,
        indexed_fields = e_source_backend_summary_setup_get_indexed_fields (setup, &index_types, &n_indexed_fields);
 
        /* No specified summary fields indicates the default summary configuration should be used */
-       if (n_fields <= 0) {
+       if (n_fields <= 0 || !fields) {
                ebsdb = e_book_backend_sqlitedb_new (path, emailid, folderid, folder_name, store_vcard, error);
                g_free (fields);
                g_free (index_types);
@@ -3553,7 +3553,7 @@ convert_string_value (EBookBackendSqliteDB *ebsdb,
                ptr = normal;
        }
 
-       while ((c = *ptr++)) {
+       while (ptr && (c = *ptr++)) {
                if (c == '\'') {
                        g_string_append_c (str, '\'');
                } else if ((c == '%' || c == '^') && match != MATCH_REGEX) {
index c793db5..0583060 100644 (file)
@@ -1679,7 +1679,7 @@ e_cal_backend_file_get_object_list (ECalBackendSync *backend,
        match_data.as_string = TRUE;
        match_data.backend = E_CAL_BACKEND (backend);
 
-       if (!strcmp (sexp, "#t"))
+       if (sexp && !strcmp (sexp, "#t"))
                match_data.search_needed = FALSE;
 
        match_data.obj_sexp = e_cal_backend_sexp_new (sexp);
@@ -1870,7 +1870,7 @@ e_cal_backend_file_start_view (ECalBackend *backend,
        match_data.obj_sexp = e_data_cal_view_get_sexp (query);
        match_data.view = query;
 
-       if (!strcmp (match_data.query, "#t"))
+       if (match_data.query && !strcmp (match_data.query, "#t"))
                match_data.search_needed = FALSE;
 
        if (!match_data.obj_sexp) {
@@ -3683,7 +3683,7 @@ test_query_by_scanning_all_objects (ECalBackendFile *cbfile,
        match_data.as_string = TRUE;
        match_data.backend = E_CAL_BACKEND (cbfile);
 
-       if (!strcmp (sexp, "#t"))
+       if (sexp && !strcmp (sexp, "#t"))
                match_data.search_needed = FALSE;
 
        match_data.obj_sexp = e_cal_backend_sexp_new (sexp);
index bd910e3..296d7d4 100644 (file)
@@ -268,10 +268,13 @@ notify_and_remove_from_cache (gpointer key,
        ECalComponent *comp = e_cal_component_new_from_string (calobj);
        ECalComponentId *id = e_cal_component_get_id (comp);
 
-       e_cal_backend_store_remove_component (cbhttp->priv->store, id->uid, id->rid);
-       e_cal_backend_notify_component_removed (E_CAL_BACKEND (cbhttp), id, comp, NULL);
+       if (id) {
+               e_cal_backend_store_remove_component (cbhttp->priv->store, id->uid, id->rid);
+               e_cal_backend_notify_component_removed (E_CAL_BACKEND (cbhttp), id, comp, NULL);
+
+               e_cal_component_free_id (id);
+       }
 
-       e_cal_component_free_id (id);
        g_object_unref (comp);
 
        return TRUE;
index 2458324..02940a5 100644 (file)
@@ -2362,13 +2362,15 @@ generate_instances (ECalClient *client,
                                continue;
                        }
 
-                       ci->start = icaltime_as_timet_with_zone (
-                               *dtstart.value, start_zone);
+                       if (dtstart.value) {
+                               ci->start = icaltime_as_timet_with_zone (
+                                       *dtstart.value, start_zone);
+                       }
 
                        if (dtend.value)
                                ci->end = icaltime_as_timet_with_zone (
                                        *dtend.value, end_zone);
-                       else if (icaltime_is_date (*dtstart.value))
+                       else if (dtstart.value && icaltime_is_date (*dtstart.value))
                                ci->end = time_day_end (ci->start);
                        else
                                ci->end = ci->start;
index 97e64b0..3a72dc4 100644 (file)
@@ -588,9 +588,9 @@ e_intervaltree_remove (EIntervalTree *tree,
                        const gchar *uid,
                        const gchar *rid)
 {
-       EIntervalNode *y;
-       EIntervalNode *x;
-       EIntervalNode *z;
+       EIntervalNode *y = NULL;
+       EIntervalNode *x = NULL;
+       EIntervalNode *z = NULL;
        EIntervalNode *nil, *root;
        gchar *key;
 
@@ -609,21 +609,23 @@ e_intervaltree_remove (EIntervalTree *tree,
 
        y = ((z->left == nil) || (z->right == nil)) ? z :
                intervaltree_node_next (tree, z);
+       g_return_val_if_fail (y, FALSE);
        x = (y->left == nil) ? y->right : y->left;
+       g_return_val_if_fail (x, FALSE);
        /* y is to be spliced out. x is it's only child */
 
        x->parent = y->parent;
 
-       if (root == x->parent)
+       if (root && root == x->parent)
                root->left = x;
-       else {
+       else if (y->parent) {
                if (y == y->parent->left)
                        y->parent->left = x;
                else
                        y->parent->right = x;
        }
 
-       if (y != z) {
+       if (z && y != z) {
                /* y (the succesor of z) is the node to be spliced out */
                g_return_val_if_fail (y != tree->priv->nil, FALSE);
 
@@ -634,10 +636,13 @@ e_intervaltree_remove (EIntervalTree *tree,
                y->parent = z->parent;
                z->left->parent = z->right->parent = y;
 
-               if (z == z->parent->left)
-                       z->parent->left = y;
-               else
-                       z->parent->right = y;
+               if (z->parent) {
+                       if (z == z->parent->left)
+                               z->parent->left = y;
+                       else
+                               z->parent->right = y;
+
+               }
 
                fixup_min_max_fields (tree, x->parent);
 
index 109b5d7..a7374f0 100644 (file)
@@ -4477,11 +4477,14 @@ e_cal_backend_empty_cache (ECalBackend *backend,
 
                id = e_cal_component_get_id (comp);
 
-               e_cal_backend_cache_remove_component (cache, id->uid, id->rid);
+               if (id) {
+                       e_cal_backend_cache_remove_component (cache, id->uid, id->rid);
 
-               e_cal_backend_notify_component_removed (backend, id, comp, NULL);
+                       e_cal_backend_notify_component_removed (backend, id, comp, NULL);
+
+                       e_cal_component_free_id (id);
+               }
 
-               e_cal_component_free_id (id);
                g_object_unref (comp);
        }