Skip to content

Commit fdbdd17

Browse files
author
rootvector2
committed
rpcapd: fix daemon_unpackapplyfilter() leak on failure paths
Free the received BPF instruction buffer through a common cleanup path when receiving instructions, validating the filter, or applying the filter fails.\n\nKeep existing daemon.c indentation style and make only the relevant CHANGES entry for this fix (Coverity CID 1641537).
1 parent 726d504 commit fdbdd17

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
6666
rpcapd: Refine SSL options in printusage().
6767
Fix a possible buffer overflow (Coverity CID 1619148).
6868
Fix parameter name validation in the configuration file.
69+
Fix a memory leak in daemon_unpackapplyfilter() (Coverity CID
70+
1641537).
6971
Documentation:
7072
Add a README.hurd.md file.
7173
Cross-reference some man pages better.

rpcapd/daemon.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,6 +2342,7 @@ daemon_unpackapplyfilter(PCAP_SOCKET sockctrl, SSL *ctrl_ssl, struct session *se
23422342
struct bpf_insn *bf_insn;
23432343
struct bpf_program bf_prog;
23442344
unsigned int i;
2345+
int ret;
23452346

23462347
status = rpcapd_recv(sockctrl, ctrl_ssl, (char *) &filter,
23472348
sizeof(struct rpcap_filter), plenp, errmsgbuf);
@@ -2385,11 +2386,13 @@ daemon_unpackapplyfilter(PCAP_SOCKET sockctrl, SSL *ctrl_ssl, struct session *se
23852386
sizeof(struct rpcap_filterbpf_insn), plenp, errmsgbuf);
23862387
if (status == -1)
23872388
{
2388-
return -1;
2389+
ret = -1;
2390+
goto cleanup;
23892391
}
23902392
if (status == -2)
23912393
{
2392-
return -2;
2394+
ret = -2;
2395+
goto cleanup;
23932396
}
23942397

23952398
bf_insn->code = ntohs(insn.code);
@@ -2406,16 +2409,22 @@ daemon_unpackapplyfilter(PCAP_SOCKET sockctrl, SSL *ctrl_ssl, struct session *se
24062409
if (bpf_validate(bf_prog.bf_insns, bf_prog.bf_len) == 0)
24072410
{
24082411
snprintf(errmsgbuf, PCAP_ERRBUF_SIZE, "The filter contains invalid instructions");
2409-
return -2;
2412+
ret = -2;
2413+
goto cleanup;
24102414
}
24112415

24122416
if (pcap_setfilter(session->fp, &bf_prog))
24132417
{
24142418
snprintf(errmsgbuf, PCAP_ERRBUF_SIZE, "RPCAP error: %s", pcap_geterr(session->fp));
2415-
return -2;
2419+
ret = -2;
2420+
goto cleanup;
24162421
}
24172422

2418-
return 0;
2423+
ret = 0;
2424+
2425+
cleanup:
2426+
free(bf_prog.bf_insns);
2427+
return ret;
24192428
}
24202429

24212430
static int

0 commit comments

Comments
 (0)