[evolution-data-server] Bug #710997 - Check some return values before use



commit b752152aa42a3c188451b8c2fc08aaf76c56cadf
Author: Murray Cumming <murrayc openismus com>
Date:   Tue Feb 25 16:14:29 2014 +0100

    Bug #710997 - Check some return values before use
    
    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    |    2 +-
 .../libedata-book/e-book-backend-sqlitedb-test.c   |    2 +-
 .../libedata-book/e-book-backend-sqlitedb.c        |    4 +-
 calendar/backends/file/e-cal-backend-file.c        |    6 ++--
 calendar/backends/http/e-cal-backend-http.c        |    9 ++++--
 calendar/libecal/e-cal-client.c                    |    8 ++++--
 calendar/libedata-cal/e-cal-backend-intervaltree.c |   25 ++++++++++++--------
 calendar/libedata-cal/e-cal-backend.c              |    9 ++++--
 8 files changed, 39 insertions(+), 26 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index 958c3e7..87cd8b9 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -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..."));
diff --git a/addressbook/libedata-book/e-book-backend-sqlitedb-test.c 
b/addressbook/libedata-book/e-book-backend-sqlitedb-test.c
index ba56ddb..3d39147 100644
--- a/addressbook/libedata-book/e-book-backend-sqlitedb-test.c
+++ b/addressbook/libedata-book/e-book-backend-sqlitedb-test.c
@@ -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;
diff --git a/addressbook/libedata-book/e-book-backend-sqlitedb.c 
b/addressbook/libedata-book/e-book-backend-sqlitedb.c
index 9a3b4e6..7f5396c 100644
--- a/addressbook/libedata-book/e-book-backend-sqlitedb.c
+++ b/addressbook/libedata-book/e-book-backend-sqlitedb.c
@@ -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) {
diff --git a/calendar/backends/file/e-cal-backend-file.c b/calendar/backends/file/e-cal-backend-file.c
index c793db5..0583060 100644
--- a/calendar/backends/file/e-cal-backend-file.c
+++ b/calendar/backends/file/e-cal-backend-file.c
@@ -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);
diff --git a/calendar/backends/http/e-cal-backend-http.c b/calendar/backends/http/e-cal-backend-http.c
index bd910e3..296d7d4 100644
--- a/calendar/backends/http/e-cal-backend-http.c
+++ b/calendar/backends/http/e-cal-backend-http.c
@@ -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;
diff --git a/calendar/libecal/e-cal-client.c b/calendar/libecal/e-cal-client.c
index 2458324..02940a5 100644
--- a/calendar/libecal/e-cal-client.c
+++ b/calendar/libecal/e-cal-client.c
@@ -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;
diff --git a/calendar/libedata-cal/e-cal-backend-intervaltree.c 
b/calendar/libedata-cal/e-cal-backend-intervaltree.c
index 97e64b0..3a72dc4 100644
--- a/calendar/libedata-cal/e-cal-backend-intervaltree.c
+++ b/calendar/libedata-cal/e-cal-backend-intervaltree.c
@@ -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);
 
diff --git a/calendar/libedata-cal/e-cal-backend.c b/calendar/libedata-cal/e-cal-backend.c
index 109b5d7..a7374f0 100644
--- a/calendar/libedata-cal/e-cal-backend.c
+++ b/calendar/libedata-cal/e-cal-backend.c
@@ -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);
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]