tracker r1999 - in branches/indexer-split: . src/tracker-indexer src/tracker-indexer/modules



Author: mr
Date: Tue Aug  5 10:46:32 2008
New Revision: 1999
URL: http://svn.gnome.org/viewvc/tracker?rev=1999&view=rev

Log:
	* src/tracker-indexer/modules/evolution.c: Use g_try_malloc0
	instead of just g_malloc0 so we don't try to allocate rediculous
	lengths of memory and abort. Also, if we can't parse the file, we
	now return NULL metadata and continue as usual.

	* src/tracker-indexer/tracker-indexer.c: Improved messaging.


Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/src/tracker-indexer/modules/evolution.c
   branches/indexer-split/src/tracker-indexer/tracker-indexer.c

Modified: branches/indexer-split/src/tracker-indexer/modules/evolution.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/modules/evolution.c	(original)
+++ branches/indexer-split/src/tracker-indexer/modules/evolution.c	Tue Aug  5 10:46:32 2008
@@ -186,7 +186,10 @@
                                 continue;
                         }
 
-                        str = g_malloc0 (len);
+                        str = g_try_malloc0 (len);
+                        if (!str) {
+                                return FALSE;
+                        }
 
                         if (fread (str, len - 1, 1, summary) != 1) {
                                 g_free (str);
@@ -826,10 +829,15 @@
                 return NULL;
         }
 
-        read_summary (data->summary,
-                      SUMMARY_TYPE_STRING, &uid, /* message uid */
-                      SUMMARY_TYPE_UINT32, &flags, /* flags */
-                      -1);
+        uid = NULL;
+
+        if (!read_summary (data->summary,
+                           SUMMARY_TYPE_STRING, &uid,   /* message uid */
+                           SUMMARY_TYPE_UINT32, &flags, /* flags */
+                           -1)) {
+                g_free (uid);
+                return NULL;
+        }
 
         if (flags & EVOLUTION_MESSAGE_JUNK ||
             flags & EVOLUTION_MESSAGE_DELETED) {
@@ -837,16 +845,27 @@
                 return NULL;
         }
 
-        read_summary (data->summary,
-                      SUMMARY_TYPE_UINT32, NULL, /* size */
-                      SUMMARY_TYPE_TIME_T, NULL, /* date sent */
-                      SUMMARY_TYPE_TIME_T, &date, /* date received */
-                      SUMMARY_TYPE_STRING, &subject, /* subject */
-                      SUMMARY_TYPE_STRING, &from, /* from */
-                      SUMMARY_TYPE_STRING, &to, /* to */
-                      SUMMARY_TYPE_STRING, &cc, /* cc */
-                      SUMMARY_TYPE_STRING, NULL, /* mlist */
-                      -1);
+        subject = NULL;
+        from = NULL;
+        to = NULL;
+        cc = NULL;
+
+        if (!read_summary (data->summary,
+                           SUMMARY_TYPE_UINT32, NULL,     /* size */
+                           SUMMARY_TYPE_TIME_T, NULL,     /* date sent */
+                           SUMMARY_TYPE_TIME_T, &date,    /* date received */
+                           SUMMARY_TYPE_STRING, &subject, /* subject */
+                           SUMMARY_TYPE_STRING, &from,    /* from */
+                           SUMMARY_TYPE_STRING, &to,      /* to */
+                           SUMMARY_TYPE_STRING, &cc,      /* cc */
+                           SUMMARY_TYPE_STRING, NULL,     /* mlist */
+                           -1)) {
+                g_free (subject);
+                g_free (from);
+                g_free (to);
+                g_free (cc);
+                return NULL;
+        }
 
 	metadata = tracker_metadata_new ();
         get_imap_uri (file, &dirname, &basename);
@@ -874,45 +893,70 @@
         g_free (to);
         g_free (cc);
 
-        read_summary (data->summary,
-                      SUMMARY_TYPE_INT32, NULL,
-                      SUMMARY_TYPE_INT32, NULL,
-                      SUMMARY_TYPE_UINT32, &count,
-                      -1);
+        if (!read_summary (data->summary,
+                           SUMMARY_TYPE_INT32, NULL,
+                           SUMMARY_TYPE_INT32, NULL,
+                           SUMMARY_TYPE_UINT32, &count,
+                           -1)) {
+                goto corruption;
+        }
 
         /* references */
         for (i = 0; i < count; i++) {
-                read_summary (data->summary,
-                              SUMMARY_TYPE_INT32, NULL,
-                              SUMMARY_TYPE_INT32, NULL,
-                              -1);
+                if (read_summary (data->summary,
+                                  SUMMARY_TYPE_INT32, NULL,
+                                  SUMMARY_TYPE_INT32, NULL,
+                                  -1)) {
+                        continue;
+                }
+
+                goto corruption;
         }
 
-        read_summary (data->summary, SUMMARY_TYPE_UINT32, &count, -1);
+        if (!read_summary (data->summary, SUMMARY_TYPE_UINT32, &count, -1)) {
+                goto corruption;
+        }
 
         /* user flags */
         for (i = 0; i < count; i++) {
-                read_summary (data->summary, SUMMARY_TYPE_STRING, NULL, -1);
+                if (read_summary (data->summary, SUMMARY_TYPE_STRING, NULL, -1)) {
+                        continue;
+                }
+
+                goto corruption;
         }
 
-        read_summary (data->summary, SUMMARY_TYPE_UINT32, &count, -1);
+        if (!read_summary (data->summary, SUMMARY_TYPE_UINT32, &count, -1)) {
+                goto corruption;
+        }
 
         /* user tags */
         for (i = 0; i < count; i++) {
-                read_summary (data->summary,
-                              SUMMARY_TYPE_STRING, NULL,
-                              SUMMARY_TYPE_STRING, NULL,
-                              -1);
+                if (read_summary (data->summary,
+                                  SUMMARY_TYPE_STRING, NULL,
+                                  SUMMARY_TYPE_STRING, NULL,
+                                  -1)) {
+                        continue;
+                }
+
+                goto corruption;
         }
 
         /* server flags */
-        read_summary (data->summary,
-                      SUMMARY_TYPE_UINT32, NULL,
-                      -1);
+        if (!read_summary (data->summary,
+                           SUMMARY_TYPE_UINT32, NULL,
+                           -1)) {
+                goto corruption;
+        }
 
         skip_content_info (data->summary);
 
         return metadata;
+
+corruption:
+        /* assume corruption */
+        tracker_metadata_free (metadata);
+        return NULL;
 }
 
 void

Modified: branches/indexer-split/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-indexer.c	(original)
+++ branches/indexer-split/src/tracker-indexer/tracker-indexer.c	Tue Aug  5 10:46:32 2008
@@ -1007,7 +1007,7 @@
 	g_free (basename);
 
 	if (service_id < 1) {
-		g_message ("Cannot delete file: it doesnt exist in DB");
+		g_message ("Can not delete file, it doesnt exist in DB");
 		return;
 	}
 



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