[evolution-data-server/gnome-2-28] Bug #597816 - Do not crash on incorrect parameters used in sexp to SQL



commit b7f31dc8b09574e2f89f6b4e98802f1d7f50079b
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jan 4 15:18:56 2010 +0100

    Bug #597816 - Do not crash on incorrect parameters used in sexp to SQL

 camel/camel-search-sql-sexp.c |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/camel/camel-search-sql-sexp.c b/camel/camel-search-sql-sexp.c
index 3490085..a9bbcc2 100644
--- a/camel/camel-search-sql-sexp.c
+++ b/camel/camel-search-sql-sexp.c
@@ -210,6 +210,8 @@ eval_eq(struct _ESExp *f, gint argc, struct _ESExpTerm **argv, gpointer data)
 		g_string_append (str, " )");
 		r->value.string = str->str;
 		g_string_free(str, FALSE);
+	} else {
+		r->value.string = g_strdup ("(0)");
 	}
 	return r;
 }
@@ -458,12 +460,17 @@ user_flag(struct _ESExp *f, gint argc, struct _ESExpResult **argv, gpointer data
 
 	d(printf("executing user-flag: %d", argc));
 
-	tstr = g_strdup_printf("%c%s%c", '%', argv[0]->value.string, '%');
-	qstr = get_db_safe_string(tstr);
-	g_free(tstr);
 	r = e_sexp_result_new(f, ESEXP_RES_STRING);
-	r->value.string = g_strdup_printf("(labels LIKE %s)", qstr);
-	g_free(qstr);
+
+	if (argc != 1) {
+		r->value.string = g_strdup ("(0)");
+	} else {
+		tstr = g_strdup_printf("%%%s%%", argv[0]->value.string);
+		qstr = get_db_safe_string(tstr);
+		g_free(tstr);
+		r->value.string = g_strdup_printf("(labels LIKE %s)", qstr);
+		g_free(qstr);
+	}
 
 	return r;
 }
@@ -476,10 +483,15 @@ system_flag (struct _ESExp *f, gint argc, struct _ESExpResult **argv, gpointer d
 
 	d(printf("executing system-flag: %d", argc));
 
-	tstr = camel_db_get_column_name(argv[0]->value.string);
 	r = e_sexp_result_new(f, ESEXP_RES_STRING);
-	r->value.string = g_strdup_printf("(%s = 1)", tstr);
-	g_free(tstr);
+
+	if (argc != 1) {
+		r->value.string = g_strdup ("(0)");
+	} else {
+		tstr = camel_db_get_column_name(argv[0]->value.string);
+		r->value.string = g_strdup_printf("(%s = 1)", tstr);
+		g_free(tstr);
+	}
 
 	return r;
 }



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