Commit 152d03a2 authored by Michael Catanzaro's avatar Michael Catanzaro
Browse files

Fix crash when importing bookmarks from Firefox

The problem is the strings returned by get_firefox_profiles() are freed
with g_free(), which is correct, but we are actually returning pointers
into the middle of the allocated region, rather than pointers to the
start of the string. Truncating a string using pointer arithmetic is a
nice trick for unowned strings, but for owned strings it doesn't work.

(cherry picked from commit 7e31b93d937625602e910d7397d00cc6082a37be)
parent 2d549d17
...@@ -138,22 +138,24 @@ static gchar * ...@@ -138,22 +138,24 @@ static gchar *
get_path (GIOChannel *channel) get_path (GIOChannel *channel)
{ {
gchar *line; gchar *line;
gchar *path; const gchar *path;
gchar *result;
gsize length; gsize length;
do { do {
g_io_channel_read_line (channel, &line, &length, NULL, NULL); g_io_channel_read_line (channel, &line, &length, NULL, NULL);
if (g_str_has_prefix (line, "Path")) { if (g_str_has_prefix (line, "Path")) {
path = g_strdup (line); path = line;
/* Extract value (e.g. Path=Value\n -> Value) */ /* Extract value (e.g. Path=Value\n -> Value) */
path = strchr (path, '='); path = strchr (path, '=');
path++; path++;
path[strcspn (path, "\n")] = 0; ((gchar *)path)[strcspn (path, "\n")] = '\0';
result = g_strdup (path);
g_free (line); g_free (line);
return path; return result;
} }
g_free (line); g_free (line);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment