[tracker/tracker-0.6] Bug NB#119123 - tracker-indexer is crashing.
- From: Carlos Garnacho <carlosg src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker/tracker-0.6] Bug NB#119123 - tracker-indexer is crashing.
- Date: Mon, 1 Jun 2009 07:36:43 -0400 (EDT)
commit 2a03fd44e54fbac7cc4e72d241378f2de824377d
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Jun 1 13:27:34 2009 +0200
Bug NB#119123 - tracker-indexer is crashing.
Make sure we also escape '%' chars in filenames, so sqlite doesn't think they
are parameters to be passed. Also improve performance of
tracker_escape_db_string() to be O(n) in all cases.
---
src/libtracker-common/tracker-utils.c | 49 ++++++++++++++++++++++-----------
1 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/src/libtracker-common/tracker-utils.c b/src/libtracker-common/tracker-utils.c
index 1ac52ee..b1bb538 100644
--- a/src/libtracker-common/tracker-utils.c
+++ b/src/libtracker-common/tracker-utils.c
@@ -106,33 +106,50 @@ gchar *
tracker_escape_db_string (const gchar *str,
gboolean add_quotes)
{
- GStrv strv;
- gchar *escaped;
+ gchar *escaped, *p;
+ guint len;
if (!str) {
return NULL;
}
- if (!g_utf8_strchr (str, -1, '\'')) {
- if (G_LIKELY (add_quotes)) {
- return g_strdup_printf ("'%s'", str);
- } else {
- return g_strdup (str);
- }
+ /* Ensure there's enough room for escaped chars */
+ len = (strlen (str) * 2) + 1;
+
+ if (G_LIKELY (add_quotes)) {
+ len += 2;
+ }
+
+ p = escaped = g_new0 (char, len);
+
+ if (G_LIKELY (add_quotes)) {
+ *p = '\'';
+ p++;
}
- strv = g_strsplit (str, "'", -1);
- escaped = g_strjoinv ("''", strv);
- g_strfreev (strv);
+ while (*str) {
+ switch (*str) {
+ case '\'':
+ case '%':
+ /* These chars need to be twice in the escaped string */
+ *p = *str;
+ p++;
+ /* Fall through */
+ default:
+ *p = *str;
+ p++;
+ }
+
+ str++;
+ }
if (G_LIKELY (add_quotes)) {
- gchar *p;
-
- p = escaped;
- escaped = g_strdup_printf ("'%s'", escaped);
- g_free (p);
+ *p = '\'';
+ p++;
}
+ *p = '\0';
+
return escaped;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]