Text   |  XML   |  ReML   |   Visible Warnings:

Unreachable Control Flow  at file.c:545

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

cf_read

(/home/sate/Testcases/c/cve/wireshark-1.2.0/file.c)expand/collapse
Show more  
 400  cf_read(capture_file *cf)
 401  {
 402    int         err;
 403    gchar       *err_info;
 404    const gchar *name_ptr;
 405    const char  *errmsg;
 406    char         errmsg_errno[1024+1];
 407    gint64       data_offset;
 408    progdlg_t *volatile progbar = NULL;
 409    gboolean     stop_flag;
 410    volatile gint64 size;
 411    gint64       file_pos;
 412    volatile float progbar_val;
 413    GTimeVal     start_time;
 414    gchar        status_str[100];
 415    volatile gint64 progbar_nextstep;
 416    volatile gint64 progbar_quantum;
 417    dfilter_t   *dfcode;
 418  #ifdef HAVE_LIBPCAP 
 419    volatile int displayed_once = 0;
 420  #endif
 421   
 422    /* Compile the current display filter.
 423     * We assume this will not fail since cf->dfilter is only set in
 424     * cf_filter IFF the filter was valid.
 425     */
 426    dfcode=NULL;
 427    if(cf->dfilter){
 428      dfilter_compile(cf->dfilter, &dfcode);
 429    }
 430   
 431    cum_bytes=0;
 432   
 433    reset_tap_listeners();
 434   
 435    cf_callback_invoke(cf_cb_file_read_start, cf);
 436   
 437    name_ptr = get_basename(cf->filename);
 438   
 439    /* Find the size of the file. */
 440    size = wtap_file_size(cf->wth, NULL);
 441   
 442    /* Update the progress bar when it gets to this value. */
 443    progbar_nextstep = 0;
 444    /* When we reach the value that triggers a progress bar update,
 445       bump that value by this amount. */
 446    if (size >= 0)
 447      progbar_quantum = size/N_PROGBAR_UPDATES;
 448    else 
 449      progbar_quantum = 0;
 450    /* Progress so far. */
 451    progbar_val = 0.0f;
 452   
 453    packet_list_freeze();
 454   
 455    stop_flag = FALSE;
 456    g_get_current_time(&start_time);
 457   
 458    while ((wtap_read(cf->wth, &err, &err_info, &data_offset))) {
 459      if (size >= 0) {
 460        /* Create the progress bar if necessary.
 461           We check on every iteration of the loop, so that it takes no 
 462           longer than the standard time to create it (otherwise, for a
 463           large file, we might take considerably longer than that standard
 464           time in order to get to the next progress bar step). */
 465        if (progbar == NULL) {
 466          progbar = delayed_create_progress_dlg("Loading", name_ptr,
 467            TRUE, &stop_flag, &start_time, progbar_val);
 468        }
 469   
 470        /* Update the progress bar, but do it only N_PROGBAR_UPDATES times;
 471           when we update it, we have to run the GTK+ main loop to get it 
 472           to repaint what's pending, and doing so may involve an "ioctl()"
 473           to see if there's any pending input from an X server, and doing
 474           that for every packet can be costly, especially on a big file. */
 475        if (data_offset >= progbar_nextstep) {
 476            file_pos = wtap_read_so_far(cf->wth, NULL);
 477            progbar_val = (gfloat) file_pos / (gfloat) size;
 478            if (progbar_val > 1.0) {
 479              /* The file probably grew while we were reading it.
 480                 Update file size, and try again. */
 481              size = wtap_file_size(cf->wth, NULL);
 482              if (size >= 0)
 483                progbar_val = (gfloat) file_pos / (gfloat) size;
 484              /* If it's still > 1, either "wtap_file_size()" failed (in which 
 485                 case there's not much we can do about it), or the file 
 486                 *shrank* (in which case there's not much we can do about
 487                 it); just clip the progress value at 1.0. */
 488              if (progbar_val > 1.0f)
 489                progbar_val = 1.0f;
 490            }
 491            if (progbar != NULL) {
 492                /* update the packet lists content on the first run or frequently on very large files */
 493                /* (on smaller files the display update takes longer than reading the file) */
 494  #ifdef HAVE_LIBPCAP 
 495                if (progbar_quantum > 500000 || displayed_once == 0) {
 496                    if ((auto_scroll_live || displayed_once == 0 || cf->displayed_count < 1000) && cf->plist_end != NULL) {
 497                        displayed_once = 1;
 498                        packet_list_thaw();
 499                        if (auto_scroll_live)
 500                            packet_list_moveto_end();
 501                        packet_list_freeze();
 502                    }
 503                }
 504  #endif
 505   
 506              g_snprintf(status_str, sizeof(status_str),
 507                         "%" G_GINT64_MODIFIER "dKB of %" G_GINT64_MODIFIER "dKB",
 508                         file_pos / 1024, size / 1024);
 509              update_progress_dlg(progbar, progbar_val, status_str);
 510            }
 511           progbar_nextstep += progbar_quantum;
 512        }
 513      }
 514   
 515      if (stop_flag) {
 516        /* Well, the user decided to abort the read. He/She will be warned and
 517           it might be enough for him/her to work with the already loaded
 518           packets.
 519           This is especially true for very large capture files, where you don't
 520           want to wait loading the whole file (which may last minutes or even 
 521           hours even on fast machines) just to see that it was the wrong file. */
 522        break;
 523      }
 524      TRY {
 525          read_packet(cf, dfcode, data_offset);
 526      }
 527      CATCH(OutOfMemoryError) {
 528          gpointer dialog;
 529   
 530          dialog = simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 531                "%sOut Of Memory!%s\n"
 532                "\n"
 533                "Sorry, but Wireshark has to terminate now!\n"
 534                "\n"
 535                "Some infos / workarounds can be found at:\n"
 536                "http://wiki.wireshark.org/KnownBugs/OutOfMemory",
 537                simple_dialog_primary_start(), simple_dialog_primary_end());
 538          /* we have to terminate, as we cannot recover from the memory error */
 539          simple_dialog_set_cb(dialog, outofmemory_cb, NULL);
 540          while(1) {
 541              main_window_update();
 542              /* XXX - how to avoid a busy wait? */
 543              /* Sleep(100); */
 544          };
 545          break;
 546      }
 547      ENDTRY;
 548    }
 549   
 550    /* Cleanup and release all dfilter resources */
 551    if (dfcode != NULL){
 552      dfilter_free(dfcode);
 553    }
 554   
 555    /* We're done reading the file; destroy the progress bar if it was created. */
 556    if (progbar != NULL)
 557      destroy_progress_dlg(progbar);
 558   
 559    /* We're done reading sequentially through the file. */
 560    cf->state = FILE_READ_DONE;
 561   
 562    /* Close the sequential I/O side, to free up memory it requires. */
 563    wtap_sequential_close(cf->wth);
 564   
 565    /* Allow the protocol dissectors to free up memory that they
 566     * don't need after the sequential run-through of the packets. */
 567    postseq_cleanup_all_protocols();
 568   
 569    /* Set the file encapsulation type now; we don't know what it is until 
 570       we've looked at all the packets, as we don't know until then whether
 571       there's more than one type (and thus whether it's
 572       WTAP_ENCAP_PER_PACKET). */
 573    cf->lnk_t = wtap_file_encap(cf->wth);
 574   
 575    cf->current_frame = cf->first_displayed;
 576    cf->current_row = 0;
 577   
 578    packet_list_thaw();
 579   
 580    cf_callback_invoke(cf_cb_file_read_finished, cf);
 581   
 582    /* If we have any displayed packets to select, select the first of those 
 583       packets by making the first row the selected row. */
 584    if (cf->first_displayed != NULL)
 585      packet_list_select_row(0);
 586   
 587    if(stop_flag) {
 588      simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
 589            "%sFile loading was cancelled!%s\n"
 590            "\n"
 591                    "The remaining packets in the file were discarded.\n"
 592            "\n"
 593            "As a lot of packets from the original file will be missing,\n"
 594                    "remember to be careful when saving the current content to a file.\n",
 595            simple_dialog_primary_start(), simple_dialog_primary_end());
 596      return CF_READ_ERROR;
 597    }
 598   
 599    if (err != 0) {
 600      /* Put up a message box noting that the read failed somewhere along
 601         the line.  Don't throw out the stuff we managed to read, though,
 602         if any. */
 603      switch (err) {
 604   
 605      case WTAP_ERR_UNSUPPORTED_ENCAP:
 606        g_snprintf(errmsg_errno, sizeof(errmsg_errno),
 607                 "The capture file has a packet with a network type that Wireshark doesn't support.\n(%s)",
 608                 err_info);
 609        g_free(err_info);
 610        errmsg = errmsg_errno;
 611        break;
 612   
 613      case WTAP_ERR_CANT_READ:
 614        errmsg = "An attempt to read from the capture file failed for"
 615                 " some unknown reason.";
 616        break;
 617   
 618      case WTAP_ERR_SHORT_READ:
 619        errmsg = "The capture file appears to have been cut short"
 620                 " in the middle of a packet.";
 621        break;
 622   
 623      case WTAP_ERR_BAD_RECORD:
 624        g_snprintf(errmsg_errno, sizeof(errmsg_errno),
 625                 "The capture file appears to be damaged or corrupt.\n(%s)",
 626                 err_info);
 627        g_free(err_info);
 628        errmsg = errmsg_errno;
 629        break;
 630   
 631      default:
 632        g_snprintf(errmsg_errno, sizeof(errmsg_errno),
 633                 "An error occurred while reading the"
 634                 " capture file: %s.", wtap_strerror(err));
 635        errmsg = errmsg_errno;
 636        break;
 637      }
 638      simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", errmsg);
 639      return CF_READ_ERROR;
 640    } else 
 641      return CF_READ_OK;
 642  }
Show more  




Change Warning 3969.31683 : Unreachable Control Flow

Priority:
State:
Finding:
Owner:
Note: