summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-04-15 16:36:59 -0700
committerGuy Harris <guy@alum.mit.edu>2016-04-15 16:36:59 -0700
commit4418d041840c295df2ad6ac97459a3e460a8f3d4 (patch)
tree130a802a1e48c007649835162f32bdb121494c1c
parentdca2f470ba8ff755361129c9956899bec46357e2 (diff)
downloadlibpcap-4418d041840c295df2ad6ac97459a3e460a8f3d4.tar.gz
Don't check for NULL in cleanup routines, and don't pass NULL to them.
pcap_close() won't pass a null pointer - it'll crash long before that when handed a null pointer, as the platforms on which we run map out page 0. Remove the null pointer checks, and, in cases where the cleanup routines are called internally, make sure we don't pass them a null pointer.
-rw-r--r--pcap-dag.c32
-rw-r--r--pcap-dos.c4
-rw-r--r--pcap-snf.c3
3 files changed, 17 insertions, 22 deletions
diff --git a/pcap-dag.c b/pcap-dag.c
index 6a53ed86..77c03b36 100644
--- a/pcap-dag.c
+++ b/pcap-dag.c
@@ -144,28 +144,25 @@ delete_pcap_dag(pcap_t *p)
static void
dag_platform_cleanup(pcap_t *p)
{
- struct pcap_dag *pd;
+ struct pcap_dag *pd = p->pr;
- if (p != NULL) {
- pd = p->priv;
#ifdef HAVE_DAG_STREAMS_API
- if(dag_stop_stream(p->fd, pd->dag_stream) < 0)
- fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));
+ if(dag_stop_stream(p->fd, pd->dag_stream) < 0)
+ fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));
- if(dag_detach_stream(p->fd, pd->dag_stream) < 0)
- fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
+ if(dag_detach_stream(p->fd, pd->dag_stream) < 0)
+ fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
#else
- if(dag_stop(p->fd) < 0)
- fprintf(stderr,"dag_stop: %s\n", strerror(errno));
+ if(dag_stop(p->fd) < 0)
+ fprintf(stderr,"dag_stop: %s\n", strerror(errno));
#endif /* HAVE_DAG_STREAMS_API */
- if(p->fd != -1) {
- if(dag_close(p->fd) < 0)
- fprintf(stderr,"dag_close: %s\n", strerror(errno));
- p->fd = -1;
- }
- delete_pcap_dag(p);
- pcap_cleanup_live_common(p);
+ if(p->fd != -1) {
+ if(dag_close(p->fd) < 0)
+ fprintf(stderr,"dag_close: %s\n", strerror(errno));
+ p->fd = -1;
}
+ delete_pcap_dag(p);
+ pcap_cleanup_live_common(p);
/* Note: don't need to call close(p->fd) here as dag_close(p->fd) does this. */
}
@@ -174,7 +171,8 @@ atexit_handler(void)
{
while (pcap_dags != NULL) {
if (pcap_dags->pid == getpid()) {
- dag_platform_cleanup(pcap_dags->p);
+ if (pcap_dags->p != NULL)
+ dag_platform_cleanup(pcap_dags->p);
} else {
delete_pcap_dag(pcap_dags->p);
}
diff --git a/pcap-dos.c b/pcap-dos.c
index bf4777da..c9a6a7c7 100644
--- a/pcap-dos.c
+++ b/pcap-dos.c
@@ -451,7 +451,7 @@ static void pcap_cleanup_dos (pcap_t *p)
{
struct pcap_dos *pd;
- if (p && !exc_occured)
+ if (!exc_occured)
{
pd = p->priv;
if (pcap_stats(p,NULL) < 0)
@@ -783,7 +783,7 @@ static void exc_handler (int sig)
fprintf (stderr, "Catching signal %d.\n", sig);
}
exc_occured = 1;
- pcap_cleanup_dos (NULL);
+ close_driver();
}
#endif /* __DJGPP__ */
diff --git a/pcap-snf.c b/pcap-snf.c
index 2271fd66..a453b11c 100644
--- a/pcap-snf.c
+++ b/pcap-snf.c
@@ -66,9 +66,6 @@ snf_platform_cleanup(pcap_t *p)
{
struct pcap_snf *ps = p->priv;
- if (p == NULL)
- return;
-
#ifdef SNF_HAVE_INJECT_API
if (ps->snf_inj)
snf_inject_close(ps->snf_inj);