(/home/sate/Testcases/c/cve/wireshark-1.2.0/dumpcap.c) |
| |
| 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; |
| 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 | | | |
| 1974 | | | global_ld.go = TRUE; |
Event 1:
!0 evaluates to true.
hide
|
|
| 1975 | | | global_ld.packet_count = 0; |
| 1976 | | | if (capture_opts->has_autostop_packets) |
Event 2:
Taking true branch. capture_opts->has_autostop_packets evaluates to true.
hide
|
|
| 1977 | | | global_ld.packet_max = capture_opts->autostop_packets; |
| 1978 | | | else |
| 1979 | | | global_ld.packet_max = 0; |
| 1980 | | | global_ld.err = 0; |
| 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 | | | |
| 1991 | | | *stats_known = FALSE; |
| 1992 | | | |
| 1993 | | | #ifndef _WIN32 |
| 1994 | | | |
| 1995 | | | |
| 1996 | | | |
| 1997 | | | |
| 1998 | | | act.sa_handler = capture_loop_stop_signal_handler;
x /usr/include/bits/sigaction.h |
| |
37 | # define sa_handler __sigaction_handler.sa_handler |
| |
|
| 1999 | | | |
| 2000 | | | |
| 2001 | | | |
| 2002 | | | |
| 2003 | | | |
| 2004 | | | act.sa_flags = 0; |
| 2005 | | | sigemptyset(&act.sa_mask); |
| 2006 | | | sigaction(SIGUSR1, &act, NULL);
x /usr/include/bits/signum.h |
| |
43 | #define SIGUSR1 10 /* User-defined signal 1 (POSIX). */ |
| |
|
| 2007 | | | #endif |
| 2008 | | | |
| 2009 | | | g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture loop starting ...");
x /home/sate/Testcases/c/cve/wireshark-1.2.0/log.h |
| |
32 | #define LOG_DOMAIN_CAPTURE_CHILD "CaptureChild" |
| |
|
| 2010 | | | capture_opts_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, capture_opts);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/log.h |
| |
32 | #define LOG_DOMAIN_CAPTURE_CHILD "CaptureChild" |
| |
|
| 2011 | | | |
| 2012 | | | |
| 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 | | | |
| 2019 | | | switch (capture_loop_init_filter(global_ld.pcap_h, global_ld.from_cap_pipe, |
| 2020 | | | capture_opts->iface, |
| 2021 | | | capture_opts->cfilter)) { |
Event 13:
capture_loop_init_filter(...) evaluates to 0.
hide
|
|
| 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 | | | |
| 2039 | | | |
| 2040 | | | if (capture_opts->saving_to_file) { |
Event 14:
Skipping " if". capture_opts->saving_to_file evaluates to false.
hide
|
|
| 2041 | | | if (!capture_loop_open_output(capture_opts, &save_file_fd, errmsg, sizeof(errmsg))) { |
| 2042 | | | goto error; |
| 2043 | | | } |
| 2044 | | | |
| 2045 | | | |
| 2046 | | | if (!capture_loop_init_output(capture_opts, save_file_fd, &global_ld, |
| 2047 | | | errmsg, sizeof(errmsg))) { |
| 2048 | | | goto error; |
| 2049 | | | } |
| 2050 | | | |
| 2051 | | | |
| 2052 | | | |
| 2053 | | | |
| 2054 | | | |
| 2055 | | | |
| 2056 | | | |
| 2057 | | | |
| 2058 | | | |
| 2059 | | | |
| 2060 | | | |
| 2061 | | | |
| 2062 | | | |
| 2063 | | | |
| 2064 | | | libpcap_dump_flush(global_ld.pdh, NULL); |
| 2065 | | | report_new_capture_file(capture_opts->save_file); |
| 2066 | | | } |
| 2067 | | | |
| 2068 | | | |
| 2069 | | | init_capture_stop_conditions(); |
| 2070 | | | |
| 2071 | | | if (capture_opts->has_autostop_filesize) |
Event 15:
Taking true branch. capture_opts->has_autostop_filesize evaluates to true.
hide
|
|
| 2072 | | | cnd_autostop_size = |
| 2073 | | | cnd_new(CND_CLASS_CAPTURESIZE,(long)capture_opts->autostop_filesize * 1024); |
| 2074 | | | if (capture_opts->has_autostop_duration) |
Event 16:
Taking true branch. capture_opts->has_autostop_duration evaluates to true.
hide
|
|
| 2075 | | | cnd_autostop_duration = |
| 2076 | [+] | | cnd_new(CND_CLASS_TIMEOUT,(gint32)capture_opts->autostop_duration); |
 |
| 2077 | | | |
| 2078 | | | if (capture_opts->multi_files_on) { |
Event 20:
Taking true branch. capture_opts->multi_files_on evaluates to true.
hide
|
|
| 2079 | | | if (capture_opts->has_file_duration) |
Event 21:
Taking true branch. capture_opts->has_file_duration evaluates to true.
hide
|
|
| 2080 | | | cnd_file_duration = |
| 2081 | | | cnd_new(CND_CLASS_TIMEOUT, capture_opts->file_duration); |
| 2082 | | | |
| 2083 | | | if (capture_opts->has_autostop_files) |
Event 22:
Taking true branch. capture_opts->has_autostop_files evaluates to true.
hide
|
|
| 2084 | | | cnd_autostop_files = |
| 2085 | | | cnd_new(CND_CLASS_CAPTURESIZE, capture_opts->autostop_files); |
| 2086 | | | } |
| 2087 | | | |
| 2088 | | | |
| 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!");
x /home/sate/Testcases/c/cve/wireshark-1.2.0/log.h |
| |
32 | #define LOG_DOMAIN_CAPTURE_CHILD "CaptureChild" |
| |
|
| 2093 | | | |
| 2094 | | | |
| 2095 | | | |
| 2096 | | | while (global_ld.go) { |
Event 25:
Continuing from loop body. Entering loop body. global_ld.go evaluates to true.
hide
|
|
| 2097 | | | |
| 2098 | | | inpkts = capture_loop_dispatch(capture_opts, &global_ld, errmsg, |
| 2099 | | | sizeof(errmsg)); |
| 2100 | | | |
| 2101 | | | #ifdef _WIN32 |
| 2102 | | | |
| 2103 | | | if (!signal_pipe_check_running()) { |
| 2104 | | | global_ld.go = FALSE; |
| 2105 | | | } |
| 2106 | | | #endif |
| 2107 | | | |
| 2108 | | | if (inpkts > 0) { |
Event 26:
Taking true branch. inpkts > 0 evaluates to true.
hide
|
|
| 2109 | | | inpkts_to_sync_pipe += inpkts; |
| 2110 | | | |
| 2111 | | | |
| 2112 | | | if (cnd_autostop_size != NULL && |
Event 27:
Skipping " if". cnd_autostop_size != (void *)0 evaluates to false.
hide
|
|
| 2113 | | | cnd_eval(cnd_autostop_size, (guint32)global_ld.bytes_written)){ |
| 2114 | | | |
| 2115 | | | if (capture_opts->multi_files_on) { |
| 2116 | | | if (cnd_autostop_files != NULL && |
| 2117 | | | cnd_eval(cnd_autostop_files, ++autostop_files)) { |
| 2118 | | | |
| 2119 | | | global_ld.go = FALSE; |
| 2120 | | | continue; |
| 2121 | | | } |
| 2122 | | | |
| 2123 | | | |
| 2124 | | | if (ringbuf_switch_file(&global_ld.pdh, &capture_opts->save_file, |
| 2125 | | | &save_file_fd, &global_ld.err)) { |
| 2126 | | | gboolean successful; |
| 2127 | | | |
| 2128 | | | |
| 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 = (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 = (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 | | | |
| 2156 | | | global_ld.go = FALSE; |
| 2157 | | | continue; |
| 2158 | | | } |
| 2159 | | | } else { |
| 2160 | | | |
| 2161 | | | global_ld.go = FALSE; |
| 2162 | | | continue; |
| 2163 | | | } |
| 2164 | | | } |
| 2165 | | | if (capture_opts->output_to_pipe) { |
Event 28:
Skipping " if". capture_opts->output_to_pipe evaluates to false.
hide
|
|
| 2166 | | | libpcap_dump_flush(global_ld.pdh, NULL); |
| 2167 | | | } |
| 2168 | | | } |
| 2169 | | | |
| 2170 | | | |
| 2171 | | | |
| 2172 | | | |
| 2173 | | | cur_time = TIME_GET(); |
| 2174 | | | #ifdef _WIN32 |
| 2175 | | | if ( (cur_time - upd_time) > 500) { |
| 2176 | | | #else |
| 2177 | | | if (cur_time - upd_time > 0) { |
Event 29:
Taking true branch. cur_time - upd_time > 0 evaluates to true.
hide
|
|
| 2178 | | | #endif |
| 2179 | | | upd_time = cur_time; |
| 2180 | | | |
| 2181 | | | |
| 2182 | | | |
| 2183 | | | |
| 2184 | | | |
| 2185 | | | |
| 2186 | | | if (inpkts_to_sync_pipe) { |
Event 30:
Taking true branch. inpkts_to_sync_pipe evaluates to true.
hide
|
|
| 2187 | | | |
| 2188 | | | libpcap_dump_flush(global_ld.pdh, NULL); |
| 2189 | | | |
| 2190 | | | |
| 2191 | | | |
| 2192 | | | report_packet_count(inpkts_to_sync_pipe); |
| 2193 | | | |
| 2194 | | | inpkts_to_sync_pipe = 0; |
| 2195 | | | } |
| 2196 | | | |
| 2197 | | | |
| 2198 | | | if (cnd_autostop_duration != NULL && cnd_eval(cnd_autostop_duration)) { |
Event 31:
Skipping " if". cnd_autostop_duration != (void *)0 evaluates to false.
hide
|
|
| 2199 | | | |
| 2200 | | | global_ld.go = FALSE; |
| 2201 | | | continue; |
| 2202 | | | } |
| 2203 | | | |
| 2204 | | | |
| 2205 | | | if (cnd_file_duration != NULL && cnd_eval(cnd_file_duration)) { |
| 2206 | | | |
| 2207 | | | if (capture_opts->multi_files_on) { |
Event 33:
Taking true branch. capture_opts->multi_files_on evaluates to true.
hide
|
|
| 2208 | | | if (cnd_autostop_files != NULL && |
Event 34:
Skipping " if". cnd_autostop_files != (void *)0 evaluates to true.
hide
|
|
| 2209 | [+] | | cnd_eval(cnd_autostop_files, ++autostop_files)) { |
 |
| 2210 | | | |
| 2211 | | | global_ld.go = FALSE; |
| 2212 | | | continue; |
| 2213 | | | } |
| 2214 | | | |
| 2215 | | | |
| 2216 | | | if (ringbuf_switch_file(&global_ld.pdh, &capture_opts->save_file, |
Event 37:
&global_ld.pdh is passed to ringbuf_switch_file() as the first argument.
hide
|
|
| 2217 | [+] | | &save_file_fd, &global_ld.err)) { |
 |
| 2218 | | | gboolean successful; |
| 2219 | | | |
| 2220 | | | |
| 2221 | | | global_ld.bytes_written = 0; |
| 2222 | | | if (capture_opts->use_pcapng) { |
Event 50:
Taking true branch. capture_opts->use_pcapng evaluates to true.
hide
|
|
| 2223 | | | char appname[100]; |
| 2224 | | | |
| 2225 | | | g_snprintf(appname, sizeof(appname), "Dumpcap " VERSION "%s", wireshark_svnversion); |
| 2226 | [+] | | successful = (global_ld.pdh, appname, &global_ld.bytes_written, &global_ld.err) && |
Event 52:
global_ld.pdh, which evaluates to fdopen(fd, "wb") from pcapio.c:198, is passed to () as the first argument. See related event 47.
hide
|
|
 |
| 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 = (global_ld.pdh, global_ld.linktype, global_ld.file_snaplen, |
| 2230 | | | &global_ld.bytes_written, &global_ld.err); |
| 2231 | | | } |
| 2232 | | | if (!successful) { |
Event 60:
Taking true branch. successful evaluates to false.
hide
|
|
| 2233 | | | fclose(global_ld.pdh); |
Event 61:
global_ld.pdh, which evaluates to fdopen(fd, "wb") from pcapio.c:198, is passed to fclose(). See related event 47.
hide
Double Close
global_ld.pdh was closed at pcapio.c:294 and is closed again here by fclose(). The issue can occur if the highlighted code executes. See related events 58 and 61. Show: All events | Only primary events |
|
| 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 | | | |
| 2247 | | | global_ld.go = FALSE; |
| 2248 | | | continue; |
| 2249 | | | } |
| 2250 | | | } else { |
| 2251 | | | |
| 2252 | | | global_ld.go = FALSE; |
| 2253 | | | continue; |
| |