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



Hi Pavel,

On Mon, 2006-11-27 at 17:37 +0200, Pavel Tsekov wrote:
> Hello Jindrich,
> 
> On Mon, 27 Nov 2006, Jindrich Novy wrote:
> 
> > there is a breakage in util.c and utilunix.c related to temporary files
> > creation. The problem is that if a directory for temporary files cannot
> > be created mc ends up in infinite loop caused by:
> >
> > tmpbase = concat_dir_and_file (mc_tmpdir (), prefix);
> >
> > in mc_mkstemps() which then calls mc_tmpdir() back infinitely and ends
> > up in a stack underflow.
> >
> > The attached patch fixes it as it disables the creation of the temporary
> > files when the temp. directory couldn't be created.
> 
> Ok. But... what happens if any of the following
> error conditions occur ?
> 
>      if (lstat (buffer, &st) == 0) {
>          /* Sanity check for existing directory */
>          if (!S_ISDIR (st.st_mode))
>              error = _("%s is not a directory\n");
>          else if (st.st_uid != getuid ())
>              error = _("Directory %s is not owned by you\n");
>          else if (((st.st_mode & 0777) != 0700)
>                   && (chmod (buffer, 0700) != 0))
>              error = _("Cannot set correct permissions for directory 
> %s\n");
>      } else {
> 
> Wouldn't it cause the same loop as when mkdir() fails ?

Good point, I missed that. IMO only removal of the fallback will prevent
the infinite loop in any case as it shouldn't call mc_mkstemps() at all.
I'm sending patch for it.

Thoughts?

Jindrich
--- mc-2006-11-14-16/src/utilunix.c.tmpcrash	2005-07-27 17:03:25.000000000 +0200
+++ mc-2006-11-14-16/src/utilunix.c	2006-11-28 13:12:36.000000000 +0100
@@ -283,34 +283,11 @@
     if (!error) {
 	tmpdir = buffer;
     } else {
-	int test_fd;
-	char *test_fn;
-	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);
-	if (test_fd != -1) {
-	    close (test_fd);
-	    test_fd = open (test_fn, O_RDONLY);
-	    if (test_fd != -1) {
-		close (test_fd);
-		unlink (test_fn);
-		fallback_ok = 1;
-	    }
-	}
-
-	if (fallback_ok) {
-	    fprintf (stderr, _("Temporary files will be created in %s\n"),
-		     sys_tmp);
-	    error = NULL;
-	} else {
-	    fprintf (stderr, _("Temporary files will not be created\n"));
-	    tmpdir = "/dev/null/";
-	}
+	fprintf (stderr, _("Temporary files will not be created\n"));
+	tmpdir = "/dev/null/";
 
 	fprintf (stderr, "%s\n", _("Press any key to continue..."));
 	getc (stdin);


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