Control: tags  -1 + patch

Hello.

This problem has reproduced in fpm2  0.79-3 i386 on my laptop PC.

I investgated the source code and found that combination of 
two facts listed below have caused the problem.


1. Negative integer appeared in the columns_order setting in a
   newly created $HOME/.fpm/fpm.ini file on the application's
   launch when there is not at first.

2. Segmentation fault may occur if some values in columns_order
    setting are out of range while reading the $HOME/.fpm/fpm.ini.

I created a two patches. They fix the above two causes.
Please find the attachments.


1. Default value will be set according to the default
   column order for when the application's first launch.

2. Range check for columns_order values is added
   while reading the $HOME/.fpm/fpm.ini. If the values get
   out of the range, it will fallback to its default value.

I would like to release these patches under tha same license
 as the original one,GPL2 or higher.    

Best regards
---
Kubo Hiroshi <h-k...@geisya.or.jp>
From: Hiroshi Kubo <h-k...@geisya.or.jp>
Bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=647440
Subject: Fix for segmentation fault when reading broken columns_order in fpm.ini
Description: A range check for columns_order values is added
 while reading the $HOME/.fpm/fpm.ini. If the value gets
 out of the range, it will be reaplaced by the default value.
--- a/src/fpm.c
+++ b/src/fpm.c
@@ -1081,7 +1081,7 @@
 	    columns_order = g_list_append (columns_order, GINT_TO_POINTER (FPM_USER));
 	} else {
 	    for (i = 0; i < count; i++)
-		columns_order = g_list_append (columns_order, GINT_TO_POINTER (columns[i]));
+	      columns_order = g_list_append (columns_order, GINT_TO_POINTER (FPM_COLUMNS_ORDER_FALLBACK_VALUE(columns[i], i)));
 	    g_free(columns);
 	}
 
--- a/src/fpm.h
+++ b/src/fpm.h
@@ -42,6 +42,13 @@
 #define FPM_NOTES	 6
 #define FPM_LAUNCHER	 7
 
+/** A filter for column definition read from ini file. 
+	@param i columns_order value
+	@param j column position in the columns_order array
+ */
+#define FPM_COLUMNS_ORDER_FALLBACK_VALUE(c,i) (((c<FPM_NUM_COLS) && (c>=FPM_DATA_POINTER)) ? (c) : ((gint) (i)+1))
+
+
 enum {  ACTION_RUN_LAUNCHER,
 	ACTION_COPY_USERNAME,
 	ACTION_COPY_PASSWORD,
From: Hiroshi Kubo <h-k...@geisya.or.jp>
Bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=647440
Subject: Fix for stopp to write broken columns_order values in initial output of fpm.ini.
Description: A fix for stopping broken columns_order value in initial output of fpm.ini.
 When writing an initial fpm.ini file, default value for columns_order will be written.
--- a/src/fpm.c
+++ b/src/fpm.c
@@ -1203,14 +1203,14 @@
 	}
 	g_list_free(columns);
 
-	i = 0;
-	columns = g_list_first(columns_order);
-	while(columns != NULL) {
-	    columns_order_tmp[i] = GPOINTER_TO_INT(columns->data);
-	    columns = g_list_next(columns);
-	    i++;
-	}
+    }
 
+    i = 0;
+    columns = g_list_first(columns_order);
+    while(columns != NULL) {
+        columns_order_tmp[i] = GPOINTER_TO_INT(columns->data);
+        columns = g_list_next(columns);
+	i++;
     }
 
     gchar *fpm_ini_file = g_build_filename (g_get_home_dir(), FPM_DIR, "fpm.ini", NULL);

Reply via email to