summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamie McCracken <jamiemcc@src.gnome.org>2007-08-19 00:31:33 +0000
committerJamie McCracken <jamiemcc@src.gnome.org>2007-08-19 00:31:33 +0000
commit9c24a06b9ec4792742efa0effb8ada4cf0508932 (patch)
tree8ad53fb152727855c3568d8a25fabef2cad76bf2
parent2e5494bf8514c3c24cfce8f758e4b12e8381a0a1 (diff)
downloadtracker-9c24a06b9ec4792742efa0effb8ada4cf0508932.tar.gz
added safeguards to help prevent crashers when indexing
svn path=/trunk/; revision=786
-rw-r--r--ChangeLog3
-rw-r--r--src/tracker-extract/tracker-extract-html.c35
-rw-r--r--src/tracker-extract/tracker-extract-imagemagick.c2
-rw-r--r--src/trackerd/tracker-apps.c14
4 files changed, 35 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 461166e31..c131ed095 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,8 @@
2007-08-19 Patch from Marcus Fritzsch <fritschy at googlemail com>
* Added option to skip mounted directories when indexing
-
+ * added safeguards to html and imagemagick extractors to prevent crashers
+ * added safeguard to app indexing
2007-08-19 Michael Biebl <mbiebl at gmail com>
diff --git a/src/tracker-extract/tracker-extract-html.c b/src/tracker-extract/tracker-extract-html.c
index 99292ea87..1231f6873 100644
--- a/src/tracker-extract/tracker-extract-html.c
+++ b/src/tracker-extract/tracker-extract-html.c
@@ -26,8 +26,8 @@
#include <libxml/HTMLparser.h>
typedef enum {
- READ_TITLE,
- } tag_type;
+ READ_TITLE,
+} tag_type;
typedef struct {
GHashTable *metadata;
@@ -37,27 +37,31 @@ typedef struct {
gboolean
has_attribute( const xmlChar ** atts, const char *attr, const char*val )
{
- if (atts == NULL || attr == NULL || val == NULL)
- return FALSE;
+ if (! (atts && attr && val)) {
+ return FALSE;
+ }
int i;
- for ( i = 0; atts[i]; i+=2 )
- {
+ for ( i = 0; atts[i] && atts[i+1]; i+=2 ) {
if ( strcasecmp((char*)atts[i],attr) == 0 ) {
- if ( !val || strcasecmp((char*)atts[i+1],val) == 0 ) {
+ if (strcasecmp((char*)atts[i+1],val) == 0) {
return TRUE;
}
}
}
+
return FALSE;
}
const xmlChar *
lookup_attribute( const xmlChar **atts, const char *attr )
{
+ if (!atts || !attr) {
+ return NULL;
+ }
+
int i;
- for ( i = 0; atts[i]; i+=2 )
- {
+ for ( i = 0; atts[i] && atts[i+1]; i+=2 ) {
if ( strcasecmp((char*)atts[i],attr) == 0 ) {
return atts[i+1];
}
@@ -69,27 +73,40 @@ lookup_attribute( const xmlChar **atts, const char *attr )
void
startElement (void * info, const xmlChar * name, const xmlChar ** atts)
{
+ if (! (info && name && atts)) {
+ return;
+ }
+
/* Look for RDFa triple describing the license */
if ( strcasecmp((char*)name,"a") == 0 ) {
+
/* This tag is a license. Ignore, however, if it is referring to another document */
if ( has_attribute(atts,"rel","license") && !has_attribute(atts,"about",NULL) ) {
+
const xmlChar *href = lookup_attribute(atts,"href");
if ( href ) {
g_hash_table_insert (((HTMLParseInfo *)info)->metadata, g_strdup ("File:License"),
g_strdup( (char*)href ));
}
}
+
} else if ( strcasecmp((char*)name,"title") == 0 ) {
+
((HTMLParseInfo *)info)->current = READ_TITLE;
+
} else if ( strcasecmp((char*)name,"meta") == 0 ) {
+
if ( has_attribute(atts,"name","Author") ) {
+
const xmlChar *author = lookup_attribute(atts,"content");
if ( author ) {
g_hash_table_insert (((HTMLParseInfo *)info)->metadata, g_strdup ("Doc:Author"),
g_strdup( (char*)author ));
}
}
+
if ( has_attribute(atts,"name","DC.Description") ) {
+
const xmlChar *desc = lookup_attribute(atts,"content");
if ( desc ) {
g_hash_table_insert (((HTMLParseInfo *)info)->metadata, g_strdup ("Doc:Comments"),
diff --git a/src/tracker-extract/tracker-extract-imagemagick.c b/src/tracker-extract/tracker-extract-imagemagick.c
index 8eec802f4..2db24cdfe 100644
--- a/src/tracker-extract/tracker-extract-imagemagick.c
+++ b/src/tracker-extract/tracker-extract-imagemagick.c
@@ -34,6 +34,8 @@ tracker_extract_imagemagick (gchar *filename, GHashTable *metadata)
gchar **lines;
gint exit_status;
+ g_return_if_fail (filename != NULL);
+
/* imagemagick crashes trying to extract from xcf files */
if (g_str_has_suffix (filename, ".xcf")) {
return;
diff --git a/src/trackerd/tracker-apps.c b/src/trackerd/tracker-apps.c
index 9253cbac6..e4706dff3 100644
--- a/src/trackerd/tracker-apps.c
+++ b/src/trackerd/tracker-apps.c
@@ -92,7 +92,7 @@ tracker_db_index_application (DBConnection *db_con, FileInfo *info)
GKeyFile *key_file = NULL;
gchar *type = NULL;
- gboolean is_hidden = TRUE;
+ gboolean is_hidden = FALSE;
char *hidden = NULL;
gchar *tmp_str = NULL;
gchar desktop_entry[] = { "Desktop Entry" };
@@ -125,9 +125,10 @@ tracker_db_index_application (DBConnection *db_con, FileInfo *info)
if (hidden) {
is_hidden = (strcasecmp (hidden, "true") == 0);
g_free (hidden);
+ hidden = NULL;
}
- if (!hidden && type && (strcasecmp (type, "Application") == 0)) {
+ if (!is_hidden && type && (strcasecmp (type, "Application") == 0)) {
meta_table = g_hash_table_new (g_str_hash, g_str_equal);
@@ -163,9 +164,7 @@ tracker_db_index_application (DBConnection *db_con, FileInfo *info)
tracker_add_metadata_to_table (meta_table, app_mime_type, g_strdup (*array));
}
- if (mimes) {
- g_strfreev (mimes);
- }
+ g_strfreev (mimes);
}
if ((categories = g_key_file_get_string_list (key_file, desktop_entry, "Categories", NULL, NULL)) != NULL) {
@@ -175,10 +174,7 @@ tracker_db_index_application (DBConnection *db_con, FileInfo *info)
tracker_add_metadata_to_table (meta_table, app_categories, g_strdup (*array));
}
-
- if (categories) {
- g_strfreev (categories);
- }
+ g_strfreev (categories);
}
char *fname = g_path_get_basename (info->uri);