Text   |  XML   |  ReML   |   Visible Warnings:

Double Close  at dumpcap.c:2233

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

capture_loop_start

(/home/sate/Testcases/c/cve/wireshark-1.2.0/dumpcap.c)expand/collapse
Show more  
 1947  capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct pcap_stat *stats)
 1948  {
 1949  #ifndef _WIN32 
 1950    struct sigaction act;
 1951  #endif
 1952    time_t      upd_time, cur_time;
 1953    time_t      start_time;
 1954    int         err_close;
 1955    int         inpkts;
 1956    gint        inpkts_to_sync_pipe = 0;     /* packets not already send out to the sync_pipe */
 1957    condition  *cnd_file_duration = NULL;
 1958    condition  *cnd_autostop_files = NULL;
 1959    condition  *cnd_autostop_size = NULL;
 1960    condition  *cnd_autostop_duration = NULL;
 1961    guint32     autostop_files = 0;
 1962    gboolean    write_ok;
 1963    gboolean    close_ok;
 1964    gboolean    cfilter_error = FALSE;
 1965  #define MSG_MAX_LENGTH 4096
 1966    char        errmsg[MSG_MAX_LENGTH+1];
 1967    char        secondary_errmsg[MSG_MAX_LENGTH+1];
 1968    int         save_file_fd = -1;
 1969   
 1970    *errmsg           = '\0';
 1971    *secondary_errmsg = '\0';
 1972   
 1973    /* init the loop data */
 1974    global_ld.go                 = TRUE;
 1975    global_ld.packet_count       = 0;
 1976    if (capture_opts->has_autostop_packets)
 1977      global_ld.packet_max       = capture_opts->autostop_packets;
 1978    else 
 1979      global_ld.packet_max       = 0;     /* no limit */
 1980    global_ld.err                = 0;     /* no error seen yet */
 1981    global_ld.wtap_linktype      = WTAP_ENCAP_UNKNOWN;
 1982    global_ld.pcap_err           = FALSE;
 1983    global_ld.from_cap_pipe      = FALSE;
 1984    global_ld.pdh                = NULL;
 1985    global_ld.cap_pipe_fd        = -1;
 1986  #ifdef MUST_DO_SELECT 
 1987    global_ld.pcap_fd            = 0;
 1988  #endif
 1989   
 1990    /* We haven't yet gotten the capture statistics. */
 1991    *stats_known      = FALSE;
 1992   
 1993  #ifndef _WIN32 
 1994    /*
 1995     * Catch SIGUSR1, so that we exit cleanly if the parent process 
 1996     * kills us with it due to the user selecting "Capture->Stop".
 1997     */
 1998    act.sa_handler = capture_loop_stop_signal_handler;
 1999    /*
 2000     * Arrange that system calls not get restarted, because when
 2001     * our signal handler returns we don't want to restart 
 2002     * a call that was waiting for packets to arrive.
 2003     */
 2004    act.sa_flags = 0;
 2005    sigemptyset(&act.sa_mask);
 2006    sigaction(SIGUSR1, &act, NULL);
 2007  #endif /* _WIN32 */
 2008   
 2009    g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture loop starting ...");
 2010    capture_opts_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, capture_opts);
 2011   
 2012    /* open the "input file" from network interface or capture pipe */
 2013    if (!capture_loop_open_input(capture_opts, &global_ld, errmsg, sizeof(errmsg),
 2014[+]                                secondary_errmsg, sizeof(secondary_errmsg))) {
 2015      goto error;
 2016    }
 2017   
 2018    /* init the input filter from the network interface (capture pipe will do nothing) */
 2019    switch (capture_loop_init_filter(global_ld.pcap_h, global_ld.from_cap_pipe,
 2020                                     capture_opts->iface,
 2021                                     capture_opts->cfilter)) {
 2022   
 2023    case INITFILTER_NO_ERROR:
 2024      break;
 2025   
 2026    case INITFILTER_BAD_FILTER:
 2027      cfilter_error = TRUE;
 2028      g_snprintf(errmsg, sizeof(errmsg), "%s", pcap_geterr(global_ld.pcap_h));
 2029      goto error;
 2030   
 2031    case INITFILTER_OTHER_ERROR:
 2032      g_snprintf(errmsg, sizeof(errmsg), "Can't install filter (%s).",
 2033                 pcap_geterr(global_ld.pcap_h));
 2034      g_snprintf(secondary_errmsg, sizeof(secondary_errmsg), "%s", please_report);
 2035      goto error;
 2036    }
 2037   
 2038    /* If we're supposed to write to a capture file, open it for output
 2039       (temporary/specified name/ringbuffer) */
 2040    if (capture_opts->saving_to_file) {
 2041      if (!capture_loop_open_output(capture_opts, &save_file_fd, errmsg, sizeof(errmsg))) {
 2042        goto error;
 2043      }
 2044   
 2045      /* set up to write to the already-opened capture output file/files */
 2046      if (!capture_loop_init_output(capture_opts, save_file_fd, &global_ld,
 2047                                    errmsg, sizeof(errmsg))) {
 2048        goto error;
 2049      }
 2050   
 2051    /* XXX - capture SIGTERM and close the capture, in case we're on a
 2052       Linux 2.0[.x] system and you have to explicitly close the capture 
 2053       stream in order to turn promiscuous mode off?  We need to do that
 2054       in other places as well - and I don't think that works all the 
 2055       time in any case, due to libpcap bugs. */
 2056   
 2057      /* Well, we should be able to start capturing.
 2058   
 2059         Sync out the capture file, so the header makes it to the file system,
 2060         and send a "capture started successfully and capture file created"
 2061         message to our parent so that they'll open the capture file and 
 2062         update its windows to indicate that we have a live capture in 
 2063         progress. */
 2064      libpcap_dump_flush(global_ld.pdh, NULL);
 2065      report_new_capture_file(capture_opts->save_file);
 2066    }
 2067   
 2068    /* initialize capture stop (and alike) conditions */
 2069    init_capture_stop_conditions();
 2070    /* create stop conditions */
 2071    if (capture_opts->has_autostop_filesize)
 2072      cnd_autostop_size =
 2073          cnd_new(CND_CLASS_CAPTURESIZE,(long)capture_opts->autostop_filesize * 1024);
 2074    if (capture_opts->has_autostop_duration)
 2075      cnd_autostop_duration =
 2076[+]         cnd_new(CND_CLASS_TIMEOUT,(gint32)capture_opts->autostop_duration);
 2077   
 2078    if (capture_opts->multi_files_on) {
 2079        if (capture_opts->has_file_duration)
 2080          cnd_file_duration =
 2081              cnd_new(CND_CLASS_TIMEOUT, capture_opts->file_duration);
 2082   
 2083        if (capture_opts->has_autostop_files)
 2084          cnd_autostop_files =
 2085              cnd_new(CND_CLASS_CAPTURESIZE, capture_opts->autostop_files);
 2086    }
 2087   
 2088    /* init the time values */
 2089    start_time = TIME_GET();
 2090    upd_time = TIME_GET();
 2091   
 2092    g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture loop running!");
 2093   
 2094    /* WOW, everything is prepared! */
 2095    /* please fasten your seat belts, we will enter now the actual capture loop */
 2096    while (global_ld.go) {
 2097      /* dispatch incoming packets */
 2098      inpkts = capture_loop_dispatch(capture_opts, &global_ld, errmsg,
 2099                                     sizeof(errmsg));
 2100   
 2101  #ifdef _WIN32 
 2102      /* any news from our parent (signal pipe)? -> just stop the capture */
 2103      if (!signal_pipe_check_running()) {
 2104        global_ld.go = FALSE;
 2105      }
 2106  #endif
 2107   
 2108      if (inpkts > 0) {
 2109        inpkts_to_sync_pipe += inpkts;
 2110   
 2111        /* check capture size condition */
 2112        if (cnd_autostop_size != NULL &&
 2113            cnd_eval(cnd_autostop_size, (guint32)global_ld.bytes_written)){
 2114          /* Capture size limit reached, do we have another file? */
 2115          if (capture_opts->multi_files_on) {
 2116            if (cnd_autostop_files != NULL &&
 2117                cnd_eval(cnd_autostop_files, ++autostop_files)) {
 2118               /* no files left: stop here */
 2119              global_ld.go = FALSE;
 2120              continue;
 2121            }
 2122   
 2123            /* Switch to the next ringbuffer file */
 2124            if (ringbuf_switch_file(&global_ld.pdh, &capture_opts->save_file,
 2125                                    &save_file_fd, &global_ld.err)) {
 2126              gboolean successful;
 2127               
 2128              /* File switch succeeded: reset the conditions */
 2129              global_ld.bytes_written = 0;
 2130              if (capture_opts->use_pcapng) {
 2131                char appname[100];
 2132   
 2133                g_snprintf(appname, sizeof(appname), "Dumpcap " VERSION "%s", wireshark_svnversion);
 2134                successful = libpcap_write_session_header_block(global_ld.pdh, appname, &global_ld.bytes_written, &global_ld.err) &&
 2135                             libpcap_write_interface_description_block(global_ld.pdh, capture_opts->iface, capture_opts->cfilter, global_ld.linktype, global_ld.file_snaplen, &global_ld.bytes_written, &global_ld.err);
 2136              } else {
 2137                successful = libpcap_write_file_header(global_ld.pdh, global_ld.linktype, global_ld.file_snaplen,
 2138                                                       &global_ld.bytes_written, &global_ld.err);
 2139              }
 2140              if (!successful) {
 2141                fclose(global_ld.pdh);
 2142                global_ld.pdh = NULL;
 2143                global_ld.go = FALSE;
 2144                continue;
 2145              }
 2146              cnd_reset(cnd_autostop_size);
 2147              if (cnd_file_duration) {
 2148                cnd_reset(cnd_file_duration);
 2149              }
 2150              libpcap_dump_flush(global_ld.pdh, NULL);
 2151              report_packet_count(inpkts_to_sync_pipe);
 2152              inpkts_to_sync_pipe = 0;
 2153              report_new_capture_file(capture_opts->save_file);
 2154            } else {
 2155              /* File switch failed: stop here */
 2156              global_ld.go = FALSE;
 2157              continue;
 2158            }
 2159          } else {
 2160            /* single file, stop now */
 2161            global_ld.go = FALSE;
 2162            continue;
 2163          }
 2164        } /* cnd_autostop_size */
 2165        if (capture_opts->output_to_pipe) {
 2166          libpcap_dump_flush(global_ld.pdh, NULL);
 2167        }
 2168      } /* inpkts */
 2169   
 2170      /* Only update once a second (Win32: 500ms) so as not to overload slow
 2171       * displays. This also prevents too much context-switching between the
 2172       * dumpcap and wireshark processes */
 2173      cur_time = TIME_GET();
 2174  #ifdef _WIN32 
 2175      if ( (cur_time - upd_time) > 500) {
 2176  #else
 2177      if (cur_time - upd_time > 0) {
 2178  #endif
 2179          upd_time = cur_time;
 2180   
 2181        /*if (pcap_stats(pch, stats) >= 0) {
 2182          *stats_known = TRUE;
 2183        }*/
 2184   
 2185        /* Let the parent process know. */
 2186        if (inpkts_to_sync_pipe) {
 2187          /* do sync here */
 2188          libpcap_dump_flush(global_ld.pdh, NULL);
 2189   
 2190          /* Send our parent a message saying we've written out "inpkts_to_sync_pipe"
 2191             packets to the capture file. */
 2192          report_packet_count(inpkts_to_sync_pipe);
 2193   
 2194          inpkts_to_sync_pipe = 0;
 2195        }
 2196   
 2197        /* check capture duration condition */
 2198        if (cnd_autostop_duration != NULL && cnd_eval(cnd_autostop_duration)) {
 2199          /* The maximum capture time has elapsed; stop the capture. */
 2200          global_ld.go = FALSE;
 2201          continue;
 2202        }
 2203   
 2204        /* check capture file duration condition */
 2205        if (cnd_file_duration != NULL && cnd_eval(cnd_file_duration)) {
 2206          /* duration limit reached, do we have another file? */
 2207          if (capture_opts->multi_files_on) {
 2208            if (cnd_autostop_files != NULL &&
 2209[+]               cnd_eval(cnd_autostop_files, ++autostop_files)) {
 2210              /* no files left: stop here */
 2211              global_ld.go = FALSE;
 2212              continue;
 2213            }
 2214   
 2215            /* Switch to the next ringbuffer file */
 2216            if (ringbuf_switch_file(&global_ld.pdh, &capture_opts->save_file,
 2217[+]                                   &save_file_fd, &global_ld.err)) {
 2218              gboolean successful;
 2219   
 2220              /* file switch succeeded: reset the conditions */
 2221              global_ld.bytes_written = 0;
 2222              if (capture_opts->use_pcapng) {
 2223                char appname[100];
 2224   
 2225                g_snprintf(appname, sizeof(appname), "Dumpcap " VERSION "%s", wireshark_svnversion);
 2226[+]               successful = libpcap_write_session_header_block(global_ld.pdh, appname, &global_ld.bytes_written, &global_ld.err) &&
 2227                             libpcap_write_interface_description_block(global_ld.pdh, capture_opts->iface, capture_opts->cfilter, global_ld.linktype, global_ld.file_snaplen, &global_ld.bytes_written, &global_ld.err);
 2228              } else {
 2229                successful = libpcap_write_file_header(global_ld.pdh, global_ld.linktype, global_ld.file_snaplen,
 2230                                                       &global_ld.bytes_written, &global_ld.err);
 2231              }
 2232              if (!successful) {
 2233                fclose(global_ld.pdh);
 2234                global_ld.pdh = NULL;
 2235                global_ld.go = FALSE;
 2236                continue;
 2237              }
 2238              cnd_reset(cnd_file_duration);
 2239              if(cnd_autostop_size)
 2240                cnd_reset(cnd_autostop_size);
 2241              libpcap_dump_flush(global_ld.pdh, NULL);
 2242              report_packet_count(inpkts_to_sync_pipe);
 2243              inpkts_to_sync_pipe = 0;
 2244              report_new_capture_file(capture_opts->save_file);
 2245            } else {
 2246              /* File switch failed: stop here */
 2247              global_ld.go = FALSE;
 2248              continue;
 2249            }
 2250          } else {
 2251            /* single file, stop now */
 2252            global_ld.go = FALSE;
 2253            continue;
Show more  




Change Warning 5033.30419 : Double Close

Priority:
State:
Finding:
Owner:
Note: