Text   |  XML   |  ReML   |   Visible Warnings:

File System Race Condition  at file_access.c:302

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 */);
Show more  




Change Warning 1001.30075 : File System Race Condition

Priority:
State:
Finding:
Owner:
Note: