[gnome-commander/gcmd-1-2-8] Fixed problem #620650 (buffer overflow in load_fav_apps())



commit 42280c17bd2d06a5a3e187408a6a89046014707d
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Thu Jun 10 20:47:18 2010 +0200

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

 NEWS                      |    1 +
 doc/C/gnome-commander.xml |    3 ++
 src/gnome-cmd-data.cc     |   54 +++++++++++++++++++++-----------------------
 3 files changed, 30 insertions(+), 28 deletions(-)
---
diff --git a/NEWS b/NEWS
index ad5bc97..3b86324 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,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 ccb97b5..cbdfb55 100644
--- a/doc/C/gnome-commander.xml
+++ b/doc/C/gnome-commander.xml
@@ -6045,6 +6045,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 568ca17..11eac66 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -19,6 +19,9 @@
 */
 
 #include <config.h>
+
+#include <fstream>
+
 #include <libgnomevfs/gnome-vfs.h>
 #include <libgnomevfs/gnome-vfs-volume-monitor.h>
 #include <libgnomevfs/gnome-vfs-volume.h>
@@ -209,7 +212,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);
@@ -726,47 +729,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 (), ".gnome-commander", 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]