Changeset 3654:9eb775ff3c55

Show
Ignore:
Timestamp:
2004-04-12 14:43:32 (5 years ago)
Author:
Thomas Roessler <roessler@…>
Branch:
HEAD
Message:

Don't open a file for writing that we have unlinked before. Reported
embarassingly long ago by Jarno Huuskonen <Jarno.Huuskonen@…>.

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • attach.c

    r3505 r3654  
    109109            goto bailout; 
    110110        } 
    111         unlink_newfile = 1; 
     111        else 
     112          unlink_newfile = 1; 
    112113      } 
    113114      else 
     
    174175            fclose (tfp); 
    175176            mutt_unlink (a->filename);   
    176             mutt_rename_file (tempfile, a->filename);  
     177            if (mutt_rename_file (tempfile, a->filename) != 0)  
     178            { 
     179              mutt_perror _("Failure to rename file."); 
     180              goto bailout; 
     181            } 
    177182 
    178183            mutt_free_body (&b); 
     
    236241            goto bailout; 
    237242        } 
    238         unlink_newfile = 1; 
     243        else 
     244          unlink_newfile = 1; 
    239245      } 
    240246      else 
     
    608614    rc = mutt_do_pager (descrip, pagerfile, 
    609615                        M_PAGER_ATTACHMENT | (is_message ? M_PAGER_MESSAGE : 0), &info); 
     616    *pagerfile = '\0'; 
    610617  } 
    611618  else 
  • lib.c

    r3499 r3654  
    182182void mutt_unlink (const char *s) 
    183183{ 
     184  int fd; 
     185  int flags; 
    184186  FILE *f; 
    185187  struct stat sb; 
    186188  char buf[2048]; 
     189 
     190  /* Defend against symlink attacks */ 
     191   
     192#ifdef O_NOFOLLOW  
     193  flags = O_RDWR | O_NOFOLLOW; 
     194#else 
     195  flags = O_RDWR; 
     196#endif 
    187197   
    188198  if (stat (s, &sb) == 0) 
    189199  { 
    190     if ((f = fopen (s, "r+"))) 
     200    if ((fd = open (s, flags)) < 0) 
     201      return; 
     202    if ((f = fdopen (fd, "r+"))) 
    191203    { 
    192204      unlink (s);