mc crash fix when '\n' is in the directory name



Hello,

the following "uglydir" patch prevents mc from hang when it displays
directory with newline '\n' character in the name. As far as I have
tested, mc hangs in this case only in non-UTF-8 mode. The original patch
by Karel Zak. I adapted it for the recent mc CVS version and let it
correct the name only in non-UTF-8 case, otherwise it replaces UTF-8
characters by '?'.

For bug reproduction and testing please see bug #127164.

Jindrich

-- 
Jindrich Novy <jnovy redhat com>, http://people.redhat.com/jnovy/
--- mc-4.6.1-20041020/src/screen.c.uglydir	2004-10-22 10:35:22.790664184 +0200
+++ mc-4.6.1-20041020/src/screen.c	2004-10-22 10:37:30.740212896 +0200
@@ -860,6 +860,14 @@ show_dir (WPanel *panel)
 #ifndef UTF8
     trim (strip_home_and_password (panel->cwd), tmp,
 	  min(max (panel->widget.cols - 7, 0), 200));
+    
+    if (tmp && *tmp) {
+	char *s = tmp;
+	do {
+             if (!is_printable (*s))
+	         *s = '?';
+        } while (*++s);
+    }
 #else /* UTF8 */
     {
 	char *tmp2 = g_strdup(panel->cwd);
--- mc-4.6.1-20041020/src/subshell.c.uglydir	2004-09-25 15:46:23.000000000 +0200
+++ mc-4.6.1-20041020/src/subshell.c	2004-10-22 10:35:22.863653088 +0200
@@ -951,6 +951,22 @@ feed_subshell (int how, int fail_on_erro
 
 	    subshell_cwd[bytes - 1] = 0;	/* Squash the final '\n' */
 
+	    if (*subshell_cwd && current_panel && current_panel->cwd && strcmp(current_panel->cwd, subshell_cwd) &&
+			strchr(current_panel->cwd, '\n'))
+	    {
+                /* Expected CWD is diffrent and it contains line break. 
+	         * We need to read rest of CWD, because previous read() 
+	         * returns first line only.
+	         */
+	        int rbytes;
+	
+	        subshell_cwd[bytes-1] = '\n';  
+                rbytes = read(subshell_pipe[READ], (subshell_cwd+bytes), 
+			                              MC_MAXPATHLEN-bytes);
+	        if (rbytes)
+		     subshell_cwd[bytes+rbytes-1] = 0;  /* Squash the final '\n' */
+	    }
+	
 	    synchronize ();
 
 	    subshell_ready = TRUE;


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