[gnome-commander] Fixed problem #620650 (buffer overflow in load_fav_apps())



commit 9a273d4c7fd4bc22e9d5bb781671580bb8226b2c
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Thu Jun 10 20:36:33 2010 +0200

    Fixed problem #620650 (buffer overflow in load_fav_apps())

 NEWS                      |    1 +
 doc/C/gnome-commander.xml |    3 ++
 src/gnome-cmd-data.cc     |   51 ++++++++++++++++++++------------------------
 3 files changed, 27 insertions(+), 28 deletions(-)
---
diff --git a/NEWS b/NEWS
index db02c93..4fe3605 100644
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,7 @@ gnome-commander 1.2.8.7
 
 Bug fixes:
  * Fixed problem #540438 (no GUI message if meld cannot be executed)
+ * Fixed problem #620650 (buffer overflow in load_fav_apps())
 
 
 ===================================
diff --git a/doc/C/gnome-commander.xml b/doc/C/gnome-commander.xml
index 7a79f82..f7bb674 100644
--- a/doc/C/gnome-commander.xml
+++ b/doc/C/gnome-commander.xml
@@ -7036,6 +7036,9 @@
                         <listitem>
                             <para>Fixed problem #540438 (no GUI message if meld cannot be executed)</para>
                         </listitem>
+                        <listitem>
+                            <para>Fixed problem #620650 (buffer overflow in load_fav_apps())</para>
+                        </listitem>
                     </itemizedlist>
                 </para>
             </entry>
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index 97ebc46..e1df881 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -238,7 +238,7 @@ inline void save_fav_apps (const gchar *fname)
                 gint handles_multiple = gnome_cmd_app_get_handles_multiple (app);
                 gint requires_terminal = gnome_cmd_app_get_requires_terminal (app);
 
-                fprintf (fd, "%s %s %s %d %s %d %d %d\n",
+                fprintf (fd, "%s\t%s\t%s\t%d\t%s\t%d\t%d\t%d\n",
                          name, cmd, icon_path,
                          target, pattern_string,
                          handles_uris, handles_multiple, requires_terminal);
@@ -656,47 +656,42 @@ inline void load_fav_apps (const gchar *fname)
 {
     gnome_cmd_data.priv->fav_apps = NULL;
     gchar *path = g_build_filename (g_get_home_dir (), "." PACKAGE, fname, NULL);
-    FILE *fd = fopen (path, "r");
-    if (fd)
+
+    ifstream f(path);
+    string line;
+
+    while (getline(f,line))
     {
-        int ret;
-        gchar name[256], cmd[256], icon_path[256], pattern_string[256];
-        gint target, handles_uris, handles_multiple, requires_terminal;
+        gchar **a = g_strsplit_set (line.c_str()," \t",-1);
 
-        do
+        if (g_strv_length (a)==8)
         {
-            ret = fscanf (fd, "%s %s %s %d %s %d %d %d\n",
-                          name, cmd, icon_path,
-                          &target, pattern_string,
-                          &handles_uris, &handles_multiple, &requires_terminal);
+            guint target, handles_uris, handles_multiple, requires_terminal;
 
-            if (ret == 8)
+            if (string2uint (a[3], target) &&
+                string2uint (a[5], handles_uris) &&
+                string2uint (a[6], handles_multiple) &&
+                string2uint (a[7], requires_terminal))
             {
-                gchar *name2      = gnome_vfs_unescape_string (name, NULL);
-                gchar *cmd2       = gnome_vfs_unescape_string (cmd, NULL);
-                gchar *icon_path2 = gnome_vfs_unescape_string (icon_path, NULL);
-                gchar *pattern_string2 = gnome_vfs_unescape_string (pattern_string, NULL);
+                gchar *name      = gnome_vfs_unescape_string (a[0], NULL);
+                gchar *cmd       = gnome_vfs_unescape_string (a[1], NULL);
+                gchar *icon_path = gnome_vfs_unescape_string (a[2], NULL);
+                gchar *pattern   = gnome_vfs_unescape_string (a[4], NULL);
 
                 gnome_cmd_data.priv->fav_apps = g_list_append (
                     gnome_cmd_data.priv->fav_apps,
                     gnome_cmd_app_new_with_values (
-                        name2, cmd2, icon_path2,
-                        (AppTarget) target, pattern_string2,
-                        handles_uris, handles_multiple, requires_terminal));
+                        name, cmd, icon_path, (AppTarget) target, pattern, handles_uris, handles_multiple, requires_terminal));
 
-                g_free (name2);
-                g_free (cmd2);
-                g_free (icon_path2);
-                g_free (pattern_string2);
+                g_free (name);
+                g_free (cmd);
+                g_free (icon_path);
+                g_free (pattern);
             }
         }
-        while (ret == 8);
 
-        fclose (fd);
+        g_strfreev (a);
     }
-    else
-        if (errno != ENOENT)
-            warn_print ("Failed to open the file %s for reading\n", path);
 
     g_free (path);
 }



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