Re: [Geeqie-devel] Collections - collect_io.c - possible bug

2011-01-21 Thread Laurent Monin
Colin Clark a écrit :
 Hi

 If one sets up a collection with a single file, then renames that file, 
 Geeqie will crash.

 I believe the problem is line 661 in collect_io.c where 'path' is freed. 
 This is coming from the call in line 161 where 'buf' is set to something 
 that should not be freed.

 At the moment I do not understand the collection code, but for me just 
 commenting out line 661 solves the problem.


 Colin Clark


   
Hi,

from what i see, this part of code is totally wrong.
We are trying to free mem used elsewhere due to code at lines 151-155 i 
think.
@buf is pointing to a random point in a string, in no case it should be 
freed.

I don't have time atm to fix it, let's see if Klaus can.

--
Zas



--
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
___
Geeqie-devel mailing list
Geeqie-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geeqie-devel


[Geeqie-devel] File rename function - possible data loss

2011-01-21 Thread Colin Clark

Hi

If multiple files are selected for renaming and the manual rename option 
is used, it is possible to input the same destination filename for more 
than one file.


If the operation is executed, files will be overwritten with no warning.

I don't think this should be permitted to happen with a program like 
Geeqie - inexperienced users should be given more protection.


I have attached a patch which might solve the problem. Perhaps someone 
else could review the code?



Colin Clark


diff --git a/src/filedata.c b/src/filedata.c
index 388037f..bd73058 100644
--- a/src/filedata.c
+++ b/src/filedata.c
@@ -2014,10 +2014,12 @@ gboolean file_data_sc_update_ci_unspecified_list(GList *fd_list, const gchar *de
  * it should detect all possible problems with the planned operation
  */
 
-gint file_data_verify_ci(FileData *fd)
+gint file_data_verify_ci(FileData *fd, GList *list)
 {
 	gint ret = CHANGE_OK;
 	gchar *dir;
+	GList *work = NULL;
+	FileData *fd1 = NULL;
 	
 	if (!fd-change)
 		{
@@ -2227,6 +2229,26 @@ gint file_data_verify_ci(FileData *fd)
 		g_free(dest_dir);
 		}
 		
+	/* During a rename operation, check if another destination file has
+	 * the same filename
+	 */
+ 	if(fd-change-type == FILEDATA_CHANGE_RENAME)
+		{
+		work = list;
+		while (work)
+			{
+			fd1 = work-data;
+			work = work-next;
+			if (fd1 != NULL  fd != fd1 )
+{
+if (!strcmp(fd-change-dest, fd1-change-dest))
+	{
+	ret |= CHANGE_WARN_DUPLICATE_DEST;
+	}
+}
+			}
+		}
+
 	fd-change-error = ret;
 	if (ret == 0) DEBUG_1(Change checked: OK: %s, fd-path);
 
@@ -2235,19 +2257,19 @@ gint file_data_verify_ci(FileData *fd)
 }
 
 
-gint file_data_sc_verify_ci(FileData *fd)
+gint file_data_sc_verify_ci(FileData *fd, GList *list)
 {
 	GList *work;
 	gint ret;
 
-	ret = file_data_verify_ci(fd);
+	ret = file_data_verify_ci(fd, list);
 
 	work = fd-sidecar_files;
 	while (work)
 		{
 		FileData *sfd = work-data;
 
-		ret |= file_data_verify_ci(sfd);
+		ret |= file_data_verify_ci(sfd, list);
 		work = work-next;
 		}
 
@@ -2330,6 +2352,12 @@ gchar *file_data_get_error_string(gint error)
 		g_string_append(result, _(there are unsaved metadata changes for the file));
 		}
 
+	if (error  CHANGE_WARN_DUPLICATE_DEST)
+		{
+		if (result-len  0) g_string_append(result, , );
+		g_string_append(result, _(another destination file has the same filename));
+		}
+
 	return g_string_free(result, FALSE);
 }
 
@@ -2356,7 +2384,7 @@ gint file_data_verify_ci_list(GList *list, gchar **desc, gboolean with_sidecars)
 		fd = work-data;
 		work = work-next;
 			
-		error = with_sidecars ? file_data_sc_verify_ci(fd) : file_data_verify_ci(fd);
+		error = with_sidecars ? file_data_sc_verify_ci(fd, list) : file_data_verify_ci(fd, list);
 		all_errors |= error;
 		common_errors = error;
 		
diff --git a/src/filedata.h b/src/filedata.h
index d3c5c63..03b3ae4 100644
--- a/src/filedata.h
+++ b/src/filedata.h
@@ -110,7 +110,7 @@ gboolean file_data_sc_update_ci_unspecified(FileData *fd, const gchar *dest_path
 
 gchar *file_data_get_error_string(gint error);
 
-gint file_data_verify_ci(FileData *fd);
+gint file_data_verify_ci(FileData *fd, GList *list);
 gint file_data_verify_ci_list(GList *list, gchar **desc, gboolean with_sidecars);
 
 gboolean file_data_perform_ci(FileData *fd);
@@ -120,7 +120,7 @@ void file_data_free_ci_list(GList *fd_list);
 
 void file_data_set_regroup_when_finished(FileData *fd, gboolean enable);
 
-gint file_data_sc_verify_ci(FileData *fd);
+gint file_data_sc_verify_ci(FileData *fd, GList *list);
 
 gboolean file_data_sc_perform_ci(FileData *fd);
 gboolean file_data_sc_apply_ci(FileData *fd);
diff --git a/src/typedefs.h b/src/typedefs.h
index cc10b54..c535908 100644
--- a/src/typedefs.h
+++ b/src/typedefs.h
@@ -159,6 +159,7 @@ typedef enum {
 	CHANGE_WARN_SAME   = 1  2,
 	CHANGE_WARN_CHANGED_EXT= 1  3,
 	CHANGE_WARN_UNSAVED_META   = 1  4,
+	CHANGE_WARN_DUPLICATE_DEST = 1  5,
 	CHANGE_ERROR_MASK  = (~0)  8, /* the values below are fatal errors */
 	CHANGE_NO_READ_PERM= 1  8,
 	CHANGE_NO_WRITE_PERM_DIR   = 1  9,
diff --git a/src/utilops.c b/src/utilops.c
index e32a18d..f6b2469 100644
--- a/src/utilops.c
+++ b/src/utilops.c
@@ -36,7 +36,7 @@
 
 #define DIALOG_WIDTH 750
 
-static GdkPixbuf *file_util_get_error_icon(FileData *fd, GtkWidget *widget);
+static GdkPixbuf *file_util_get_error_icon(FileData *fd, GList *list, GtkWidget *widget);
 
 /*
  *--
@@ -473,7 +473,7 @@ static GtkWidget *file_util_dialog_add_list(GtkWidget *box, GList *list, gboolea
 		gchar *sidecars;
 		
 		sidecars = with_sidecars ? file_data_sc_list_to_string(fd) : NULL;
-		GdkPixbuf *icon = file_util_get_error_icon(fd, view);
+		GdkPixbuf *icon = file_util_get_error_icon(fd, list, view);
 		gtk_list_store_append(store, iter);
 		gtk_list_store_set(store, iter,
    UTILITY_COLUMN_FD, fd,
@@ -893,7 +893,7 @@ void