Skip to content

Commit 09a4d31

Browse files
fennerguyharris
authored andcommitted
Avoid race condition when receiving signal during shutdown
If we receive a TERM signal while we're shutting down, we can access a free'd pcap_t while trying to call pcap_breakloop(). We avoid this by setting the "pd" to NULL after freeing it, and don't try to use it if it's NULL.
1 parent 774dcbe commit 09a4d31

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tcpdump.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2783,6 +2783,7 @@ DIAG_ON_ASSIGN_ENUM
27832783
info(1);
27842784
}
27852785
pcap_close(pd);
2786+
pd = NULL;
27862787
if (VFileName != NULL) {
27872788
ret = get_next_file(VFile, VFileLine);
27882789
if (ret) {
@@ -3062,7 +3063,8 @@ cleanup(int signo _U_)
30623063
* to do anything with standard I/O streams in a signal handler -
30633064
* the ANSI C standard doesn't say it is).
30643065
*/
3065-
pcap_breakloop(pd);
3066+
if (pd)
3067+
pcap_breakloop(pd);
30663068
}
30673069

30683070
/*

0 commit comments

Comments
 (0)