[gnac/devel] Code hardening



commit d2629e53b8ebaac6ab2732fefbe994418ea0584c
Author: Benoît Dupasquier <bdupasqu src gnome org>
Date:   Fri Nov 5 09:06:16 2010 +0000

    Code hardening
    
    If the key folder_hierarchy_pattern does not exist in gconf, a NULL
    value will be returned. libgnac_output_build_output was not checking for
    the existence of folder_hierarchy_pattern before using it, yielding to a
    potential segfault.
    Thanks to Brian Yoder for reporting the issue.

 libgnac/libgnac-output.c |   45 ++++++++++++++++++---------------------------
 1 files changed, 18 insertions(+), 27 deletions(-)
---
diff --git a/libgnac/libgnac-output.c b/libgnac/libgnac-output.c
index fd6f5af..d2291b3 100644
--- a/libgnac/libgnac-output.c
+++ b/libgnac/libgnac-output.c
@@ -340,35 +340,16 @@ libgnac_output_rename_pattern_process(LibgnacRenamePattern  *pattern,
 
 
 static gchar *
-libgnac_output_get_filename(GFile                *source, 
-                            const gchar          *rename_pattern, 
-                            GError              **error)
-{
-  /*
-static gchar *
-libgnac_output_get_filename(GFile *input_file,
-                            LibgnacOutputConfig *config, 
-                            GError              **error)
+libgnac_output_get_filename(GFile        *source,
+                            const gchar  *rename_pattern,
+                            GError      **error)
 {
-*/
-
   GError      *err = NULL;
   LibgnacTags *tags = NULL;
   gchar       *output = NULL;
 
   tags = libgnac_metadata_extract(metadata, source, NULL);
-  if (!tags) 
-  {
-    output = libgnac_output_remove_extension_from_file(source, &err);
-    if (err) 
-    {
-      libgnac_debug("Unable to remove extension");
-      g_propagate_error(error, err);
-      return NULL;
-    }
-  } 
-  else 
-  {
+  if (tags) {
     libgnac_output_rename_patterns_init(tags);
 
     output = g_strdup(rename_pattern);
@@ -378,6 +359,15 @@ libgnac_output_get_filename(GFile *input_file,
                     (GFunc)libgnac_output_rename_pattern_process, &output);
   }
 
+  if (!output) {
+    output = libgnac_output_remove_extension_from_file(source, &err);
+    if (err) {
+      libgnac_debug("Unable to remove extension");
+      g_propagate_error(error, err);
+      return NULL;
+    }
+  }
+
   return output;
 }
 
@@ -390,9 +380,9 @@ libgnac_output_finalize(void)
 
 
 GFile *
-libgnac_output_build_output(GFile  *source,
-                            LibgnacOutputConfig   *config,
-                            GError               **error)
+libgnac_output_build_output(GFile                *source,
+                            LibgnacOutputConfig  *config,
+                            GError              **error)
 {
   GFile  *destination;
   GError *output_error = NULL;
@@ -438,7 +428,8 @@ libgnac_output_build_output(GFile  *source,
   }
 
   /* check whether we have to build a folder hierarchy */
-  if (!g_str_equal(g_strstrip(config->folder_hierarchy), "")) 
+  if (config->folder_hierarchy
+      && !g_str_equal(g_strstrip(config->folder_hierarchy), ""))
   {
     /* replace all known patterns by their value */
     g_slist_foreach(rename_patterns,



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