Re: [PATCH] mc crashes when temporary directory cannot be created



Hello Jindrich,

On Thu, 2006-11-30 at 20:04, Pavel Tsekov wrote:
> On Wed, 29 Nov 2006, Leonard den Ottolander wrote:
> 
> > Hello Jindrich,
> >
> > On Tue, 2006-11-28 at 13:21 +0100, Jindrich Novy wrote:
> >> IMO only removal of the fallback will prevent
> >> the infinite loop in any case as it shouldn't call mc_mkstemps() at all.
> >
> > That cure seems worse than the disease. Isn't the real problem the fact
> > that mc_mkstemps() blindly concats tmpdir to the prefix instead of
> > testing if mc_tmpdir() succeeded? Why not abort mc_mkstemps() if
> > mc_tmpdir() returns "/dev/null/"?
> >
> > What about the attached (untested) patch?
> >
> > By the way, could you please add the -p option to your diffs?
> 
> There is an even simpler cure. In mc_tmpdir() when executing
> the fallback code pass an absolute path to mc_mkstemps().
> This will prevent the loop. However I am not yet conviced
> that this is the best solution. I am still investigating.

I am attaching a patch which passes an absolute path to mc_mkstemps()
when invoked from mc_tmpdir(). What do you think about this fix ?
I may add a comment why it is necessary to call mc_mkstemps() with
an absolute path. By the way I think we should add a check whether 
the environment variable TMPDIR contains an absolute path. Anyway, I'll
leave this for another patch.

Index: src/utilunix.c
===================================================================
RCS file: /sources/mc/mc/src/utilunix.c,v
retrieving revision 1.88
diff -u -p -r1.88 utilunix.c
--- src/utilunix.c	27 Jul 2005 15:03:25 -0000	1.88
+++ src/utilunix.c	30 Dec 2006 18:44:22 -0000
@@ -280,19 +280,18 @@ mc_tmpdir (void)
 	}
     }
 
-    if (!error) {
-	tmpdir = buffer;
-    } else {
+    if (error != NULL) {
 	int test_fd;
-	char *test_fn;
+	char *test_fn, *fallback_prefix;
 	int fallback_ok = 0;
 
 	if (*error)
 	    fprintf (stderr, error, buffer);
 
 	/* Test if sys_tmp is suitable for temporary files */
-	tmpdir = sys_tmp;
-	test_fd = mc_mkstemps (&test_fn, "mctest", NULL);
+	fallback_prefix = g_strdup_printf ("%s/mctest", sys_tmp);
+	test_fd = mc_mkstemps (&test_fn, fallback_prefix, NULL);
+	g_free (fallback_prefix);
 	if (test_fd != -1) {
 	    close (test_fd);
 	    test_fd = open (test_fn, O_RDONLY);
@@ -306,16 +305,19 @@ mc_tmpdir (void)
 	if (fallback_ok) {
 	    fprintf (stderr, _("Temporary files will be created in %s\n"),
 		     sys_tmp);
+	    g_snprintf (buffer, sizeof (buffer), "%s", sys_tmp);
 	    error = NULL;
 	} else {
 	    fprintf (stderr, _("Temporary files will not be created\n"));
-	    tmpdir = "/dev/null/";
+	    g_snprintf (buffer, sizeof (buffer), "%s", "/dev/null/");
 	}
 
 	fprintf (stderr, "%s\n", _("Press any key to continue..."));
 	getc (stdin);
     }
 
+    tmpdir = buffer;
+
     if (!error)
 	mc_setenv ("MC_TMPDIR", tmpdir, 1);
 


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