Ticket #3025: mc-tmpdir-creation_race_condition_fix.patch

File mc-tmpdir-creation_race_condition_fix.patch, 1.5 KB (added by Polynomial-C, 11 years ago)
  • lib/vfs/interface.c

    diff -uNr a/lib/vfs/interface.c b/lib/vfs/interface.c
    a b  
    844844 
    845845    canonicalize_pathname (buffer); 
    846846 
    847     if (lstat (buffer, &st) == 0) 
     847    /* Try to create directory */ 
     848    if (mkdir (buffer, S_IRWXU) != 0) 
    848849    { 
    849         /* Sanity check for existing directory */ 
    850         if (!S_ISDIR (st.st_mode)) 
    851             error = _("%s is not a directory\n"); 
    852         else if (st.st_uid != getuid ()) 
    853             error = _("Directory %s is not owned by you\n"); 
    854         else if (((st.st_mode & 0777) != 0700) && (chmod (buffer, 0700) != 0)) 
    855             error = _("Cannot set correct permissions for directory %s\n"); 
    856     } 
    857     else 
    858     { 
    859         /* Need to create directory */ 
    860         if (mkdir (buffer, S_IRWXU) != 0) 
     850        if (errno == EEXIST && lstat (buffer, &st) == 0) 
    861851        { 
     852            /* Sanity check for existing directory */ 
     853            if (!S_ISDIR (st.st_mode)) 
     854                error = _("%s is not a directory\n"); 
     855            else if (st.st_uid != getuid ()) 
     856                error = _("Directory %s is not owned by you\n"); 
     857            else if (((st.st_mode & 0777) != 0700) && (chmod (buffer, 0700) != 0)) 
     858                error = _("Cannot set correct permissions for directory %s\n"); 
     859        } else { 
    862860            fprintf (stderr, 
    863861                     _("Cannot create temporary directory %s: %s\n"), 
    864862                     buffer, unix_error_string (errno));