Text  |   XML   |   Visible Warnings:

Irssi : Irssi analysis 1 : File System Race Condition  at dcc-get.c:239

Categories: POSIX.RACE.TOCTTOU CWE:367
Warning ID: 2197.2202
Procedure: sig_dccget_connected
Trace: View
Modified: Wed Sep 2 11:52:17 2009   show details
 
Priority: None
State: None
Finding: None
Owner: None
  edit properties

Legend [ X ]
Warning Location
Contributes
Parse Error
Other Warning
Two or More Loop Iterations
On Execution Path
Comment
Macro
Preprocessor
Include
Keyword
Preprocessed Away

Source  |  Language: C Hide Legend     
ProblemLineSource
   /u1/paul/SATE/2010/c/irssi/irssi-0.8.14/src/irc/dcc/dcc-get.c
   Enter sig_dccget_connected
 174 void sig_dccget_connected(GET_DCC_REC *dcc) 
 175 {
 176         struct stat statbuf;
 177         char *fname, *tempfname, *str;
 178         int ret, ret_errno, temphandle, old_umask;
 179  
 180         if (!dcc->from_dccserver) {
 181                 if (net_geterror(dcc->handle) != 0) {
 182                         /* error connecting */ 
 183                         signal_emit("dcc error connect", 1, dcc);
 184                         dcc_destroy(DCC(dcc));
 185                         return;
 186                 }
 187  
 188                 g_source_remove(dcc->tagconn);
 189                 dcc->tagconn = -1;
 190         }
 191  
 192         g_free_not_null(dcc->file);
 193         dcc->file = dcc_get_download_path(dcc->arg);
 194  
 195         /* if some plugin wants to change the file name/path here.. */ 
 196         signal_emit("dcc get receive", 1, dcc);
 197  
true198         if (stat(dcc->file, &statbuf) == 0 &&
 199             dcc->get_type == DCC_GET_RENAME) {
 200                 /* file exists, rename.. */ 
 201                 fname = dcc_get_rename_file(dcc->file);
 202                 g_free(dcc->file);
 203                 dcc->file = fname;
 204         }
 205  
 206         if (dcc->get_type != DCC_GET_RESUME) {
 207                 int dcc_file_create_mode = octal2dec(settings_get_int("dcc_file_create_mode"));
 208  
 209                 /* we want to overwrite the file, remove it here.
 210                    if it gets created after this, we'll fail. */ 
 211                 unlink(dcc->file);   /* File System Race Condition (ID: 2200.2205) */
 212  
 213                 /* just to make sure we won't run into race conditions 
 214                    if download_path is in some global temp directory */ 
 215                 tempfname = g_strconcat(dcc->file, ".XXXXXX", NULL);
 216  
 217                 old_umask = umask(0077);
 218                 temphandle = mkstemp(tempfname);   /* Insecure Temporary File (ID: 611.611) */
 219                 umask(old_umask);
 220  
 221                 if (temphandle == -1)
 222                         ret = -1;
 223                 else 
 224                         ret = fchmod(temphandle, dcc_file_create_mode);
 225  
 226                 if (ret != -1) {
 227                         ret = link(tempfname, dcc->file);   /* File System Race Condition (ID: 2198.2203) */
 228  
 229                         if (ret == -1 &&
 230                             /* Linux */ 
 231                             (errno == EPERM ||
 232                              /* FUSE */ 
 233                              errno == ENOSYS ||
 234                              /* BSD */ 
 235                              errno == EOPNOTSUPP)) {
 236                                 /* hard links aren't supported - some people 
 237                                    want to download stuff to FAT/NTFS/etc 
 238                                    partitions, so fallback to rename() */ 
*dcc->file is checked by path name239                                 ret = rename(tempfname, dcc->file);     /* File System Race Condition */
Preconditions
((char*)$param_1)[248] != 0
Postconditions
$unknown_526138' is checked by path name
dcc' = $param_1
dcc_file_create_mode' = 0
errno' = 95
next_uniq_id' = next_uniq_id + 1
old_umask' = 63
ret' = -1
tempfname' = &$unknown_526141
temphandle' != -1




Change Warning 2197.2202 : File System Race Condition

Priority:
State:
Finding:
Owner:
Note: