From f47d7fde827bd15124e94d8e285347eef12ee6d4 Mon Sep 17 00:00:00 2001 From: arfa k Date: Fri, 6 Nov 2026 19:46:03 +0530 Subject: [PATCH] Check incl_len against the file size in eaud_pcap_dissect() eaud_pcap_dissect() derives the payload length and the offset of the next record from the record's incl_len without checking it against the bytes left in the file. load_pcap() then hands l5_data/l5_len to rtp_packet_parse_raw(), and with SRTP to eaud_crypto_decrypt(), which decrypts in place, so a record that claims more than the file holds is read (or written) past the end of the mapping. A 264-byte recording with incl_len 0x10000000 and the RTP P bit set makes extractaudio segfault reading the padding length in rtp_packet_parse_raw(). pcap_hdr_len is an int, so an incl_len close to UINT32_MAX on a non-IPv4 record also wraps the record length to 0 or a few bytes and the scan loop stalls or resyncs in the middle of a record. Return PCP_DSCT_TRNK for such records, the same way eaud_adhoc_dissect() already handles truncated adhoc files. Add a badargs sub-test that builds such a file from call1_g722_srtp and expects extractaudio to fail with exit status 1 rather than crash. --- extractaudio/eaud_pcap.c | 6 ++++++ tests/extractaudio/badargs | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/extractaudio/eaud_pcap.c b/extractaudio/eaud_pcap.c index 19a31555a..a8c4055e3 100644 --- a/extractaudio/eaud_pcap.c +++ b/extractaudio/eaud_pcap.c @@ -67,6 +67,9 @@ eaud_pcap_dissect(unsigned char *bp, size_t blen, int network, } memcpy(&family, &pcp->null.family, sizeof(family)); memcpy(&incl_len, &pcp->null.pcaprec_hdr.incl_len, sizeof(incl_len)); + if (incl_len > blen - sizeof(pcaprec_hdr_t)) { + return (PCP_DSCT_TRNK); + } if (family != AF_INET) { dp->pcap_hdr_len = sizeof(pcaprec_hdr_t) + incl_len; return (PCP_DSCT_UNKN); @@ -82,6 +85,9 @@ eaud_pcap_dissect(unsigned char *bp, size_t blen, int network, } memcpy(ðer_type, &pcp->en10t.ether.type, sizeof(ether_type)); memcpy(&incl_len, &pcp->en10t.pcaprec_hdr.incl_len, sizeof(incl_len)); + if (incl_len > blen - sizeof(pcaprec_hdr_t)) { + return (PCP_DSCT_TRNK); + } if (ether_type != ETHERTYPE_INET) { dp->pcap_hdr_len = sizeof(pcaprec_hdr_t) + incl_len; return (PCP_DSCT_UNKN); diff --git a/tests/extractaudio/badargs b/tests/extractaudio/badargs index c3942e051..8ce7af69e 100755 --- a/tests/extractaudio/badargs +++ b/tests/extractaudio/badargs @@ -37,3 +37,18 @@ ${EXTRACTAUDIO} -D pcm_16 -C 0.5 extractaudio/call1_alaw ${wfile} reportifnotfail "extractaudio start with bad argumens: -D pcm_16 -C 0.5" test ! -e ${wfile} report "${wfile} is removed" + +# A PCAP record whose incl_len runs past the end of the file has to be +# rejected, not read. +rbase="badargs.trunc" +dd if=extractaudio/call1_g722_srtp.a.rtp of=${rbase}.a.rtp bs=264 count=1 \ + 2>/dev/null +# incl_len = 0x10000000, RTP P bit set so that the parser reads the last byte +printf '\000\000\000\020' | dd of=${rbase}.a.rtp bs=1 seek=32 conv=notrunc \ + 2>/dev/null +printf '\240' | dd of=${rbase}.a.rtp bs=1 seek=82 conv=notrunc 2>/dev/null +cp ${rbase}.a.rtp ${rbase}.o.rtp +${EXTRACTAUDIO} ${rbase} ${rbase}.wav >/dev/null 2>&1 +test ${?} -eq 1 +report "extractaudio rejects a truncated PCAP record" +rm -f ${rbase}.a.rtp ${rbase}.o.rtp ${rbase}.wav