Text   |  XML   |  ReML   |   Visible Warnings:

File System Race Condition  at file_wrappers.c:152

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

wtap_open_offline

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/file_access.c)expand/collapse
Show more  
 216  wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
 217                          gboolean do_random)
 218  {
 219          struct stat statb;
 220          wtap    *wth;
 221          unsigned int    i;
 222          gboolean use_stdin = FALSE;
 223   
 224          /* open standard input if filename is '-' */
 225          if (strcmp(filename, "-") == 0)
 226                  use_stdin = TRUE;
 227   
 228          /* First, make sure the file is valid */
 229          if (use_stdin) {
 230                  if (fstat(0, &statb) < 0) {
 231                          *err = errno;
 232                          return NULL;
 233                  }
 234          } else {
 235                  if (ws_stat(filename, &statb) < 0) {
 236                          *err = errno;
 237                          return NULL;
 238                  }
 239          }
 240          if (S_ISFIFO(statb.st_mode)) {
 241                  /*
 242                   * Opens of FIFOs are allowed only when not opening 
 243                   * for random access.
 244                   *
 245                   * XXX - currently, we do seeking when trying to find 
 246                   * out the file type, so we don't actually support
 247                   * opening FIFOs.  However, we may eventually 
 248                   * do buffering that allows us to do at least some
 249                   * file type determination even on pipes, so we
 250                   * allow FIFO opens and let things fail later when 
 251                   * we try to seek.
 252                   */
 253                  if (do_random) {
 254                          *err = WTAP_ERR_RANDOM_OPEN_PIPE;
 255                          return NULL;
 256                  }
 257          } else if (S_ISDIR(statb.st_mode)) {
 258                  /*
 259                   * Return different errors for "this is a directory"
 260                   * and "this is some random special file type", so 
 261                   * the user can get a potentially more helpful error.
 262                   */
 263                  *err = EISDIR;
 264                  return NULL;
 265          } else if (! S_ISREG(statb.st_mode)) {
 266                  *err = WTAP_ERR_NOT_REGULAR_FILE;
 267                  return NULL;
 268          }
 269   
 270          /*
 271           * We need two independent descriptors for random access, so 
 272           * they have different file positions.  If we're opening the
 273           * standard input, we can only dup it to get additional
 274           * descriptors, so we can't have two independent descriptors,
 275           * and thus can't do random access.
 276           */
 277          if (use_stdin && do_random) {
 278                  *err = WTAP_ERR_RANDOM_OPEN_STDIN;
 279                  return NULL;
 280          }
 281   
 282          errno = ENOMEM;
 283          wth = g_malloc(sizeof(wtap));
 284          if (wth == NULL) {
 285                  *err = errno;
 286                  return NULL;
 287          }
 288   
 289          /* Open the file */
 290          errno = WTAP_ERR_CANT_OPEN;
 291          if (use_stdin) {
 292                  /*
 293                   * We dup FD 0, so that we don't have to worry about
 294                   * an fclose or gzclose of wth->fh closing the standard 
 295                   * input of the process.
 296                   */
 297                  wth->fd = ws_dup(0);
 298  #ifdef _WIN32 
 299                  _setmode(wth->fd, O_BINARY);
 300  #endif
 301          } else 
 302                  wth->fd = ws_open(filename, O_RDONLY|O_BINARY, 0000 /* no creation so don't matter */);
 303          if (wth->fd < 0) {
 304                  *err = errno;
 305                  g_free(wth);
 306                  return NULL;
 307          }
 308          if (!(wth->fh = filed_open(wth->fd, "rb"))) {
 309                  *err = errno;
 310                  ws_close(wth->fd);
 311                  g_free(wth);
 312                  return NULL;
 313          }
 314   
 315          if (do_random) {
 316[+]                 if (!(wth->random_fh = file_open(filename, "rb"))) {
expand/collapse

file_open

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/file_wrappers.c)expand/collapse
Show more  
 122  file_open(const char *path, const char *mode)
 123  {
 124          int fd;
 125          FILE_T ft;
 126          int oflag;
 127   
 128          if (*mode == 'r') {
 129                  if (strchr(mode + 1, '+') != NULL)
 130                          oflag = O_RDWR;
 131                  else 
 132                          oflag = O_RDONLY;
 133          } else if (*mode == 'w') {
 134                  if (strchr(mode + 1, '+') != NULL)
 135                          oflag = O_RDWR|O_CREAT|O_TRUNC;
 136                  else 
 137                          oflag = O_RDONLY|O_CREAT|O_TRUNC;
 138          } else if (*mode == 'a') {
 139                  if (strchr(mode + 1, '+') != NULL)
 140                          oflag = O_RDWR|O_APPEND;
 141                  else 
 142                          oflag = O_RDONLY|O_APPEND;
 143          } else {
 144                  errno = EINVAL;
 145                  return NULL;
 146          }
 147  #ifdef _WIN32 
 148          if (strchr(mode + 1, 'b') != NULL)
 149                  oflag |= O_BINARY;
 150  #endif
 151          /* open file and do correct filename conversions */
 152          if ((fd = ws_open(path, oflag, 0666)) == -1)
Show more  
Show more  




Change Warning 1002.30076 : File System Race Condition

Priority:
State:
Finding:
Owner:
Note: