aboutsummaryrefslogtreecommitdiffstats
path: root/capture_loop.c
diff options
context:
space:
mode:
authorJörg Mayer <jmayer@loplof.de>2006-11-02 09:45:12 +0000
committerJörg Mayer <jmayer@loplof.de>2006-11-02 09:45:12 +0000
commit23ce819952282ef05d3fe29cf82d3ea2495065f0 (patch)
tree1544dff0eb3db3e58d4f8f254472fb9f47ec3ed3 /capture_loop.c
parent003db517095c19dab06a1871485d5e0c607b43c6 (diff)
Frederic Heem:
Fix some memleaks and overflows. I haven't committed the changes that are not bug fixes. svn path=/trunk/; revision=19777
Diffstat (limited to 'capture_loop.c')
-rw-r--r--capture_loop.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/capture_loop.c b/capture_loop.c
index 18c45beb09..24e8651e99 100644
--- a/capture_loop.c
+++ b/capture_loop.c
@@ -244,6 +244,13 @@ cap_pipe_open_live(char *pipename, struct pcap_hdr *hdr, loop_data *ld,
unsigned int bytes_read;
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "cap_pipe_open_live: %s", pipename);
+
+ if(pipename == NULL){
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING, "cap_pipe_open_live: pipe name is NULL");
+ g_snprintf(errmsg, errmsgl,
+ "The capture session could not be initiated because the pipe is not valid, maybe lack of privileges?");
+ return -1;
+ }
/*
* XXX (T)Wireshark blocks until we return
@@ -799,14 +806,19 @@ static void capture_loop_close_input(loop_data *ld) {
if (ld->cap_pipe_fd >= 0) {
g_assert(ld->from_cap_pipe);
eth_close(ld->cap_pipe_fd);
+ ld->cap_pipe_fd = 0;
}
/* if open, close the pcap "input file" */
if(ld->pcap_h != NULL) {
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_close_input: closing %p", ld->pcap_h);
g_assert(!ld->from_cap_pipe);
pcap_close(ld->pcap_h);
+ ld->pcap_h = NULL;
}
+ ld->go = FALSE;
+
#ifdef _WIN32
/* Shut down windows sockets */
WSACleanup();
@@ -1020,6 +1032,8 @@ capture_loop_dispatch(capture_options *capture_opts _U_, loop_data *ld,
#ifdef LOG_CAPTURE_VERBOSE
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_dispatch: from pcap_dispatch");
#endif
+ if(ld->pcap_h){
+ /* libpcap crashed when the pcap handle is NULL!!*/
#ifdef _WIN32
/*
* On Windows, we don't support asynchronously telling a process to
@@ -1031,6 +1045,9 @@ capture_loop_dispatch(capture_options *capture_opts _U_, loop_data *ld,
#else
inpkts = pcap_dispatch(ld->pcap_h, -1, ld->packet_cb, (u_char *) ld);
#endif
+ } else {
+ inpkts = -1;
+ }
if (inpkts < 0) {
if (inpkts == -1) {
/* Error, rather than pcap_breakloop(). */
@@ -1206,10 +1223,14 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
gboolean write_ok;
gboolean close_ok;
gboolean cfilter_error = FALSE;
- char errmsg[4096+1];
- char secondary_errmsg[4096+1];
+#define MSG_MAX_LENGTH 4096+1
+ char errmsg[MSG_MAX_LENGTH] = "";
+ char secondary_errmsg[MSG_MAX_LENGTH] = "";
int save_file_fd = -1;
+ if(capture_opts == NULL){
+ return FALSE;
+ }
/* init the loop data */
ld.go = TRUE;
@@ -1561,6 +1582,7 @@ error:
if(capture_opts->save_file != NULL) {
eth_unlink(capture_opts->save_file);
g_free(capture_opts->save_file);
+ capture_opts->save_file = NULL;
}
}
capture_opts->save_file = NULL;