Skip to content

Commit 4dd5b86

Browse files
committed
Fix segfault when converting header-less formats to pcapng
* apply demotion logic to pcapng format to try and wrangle packets into a suitable DLT for writing to pcapng
1 parent 990133d commit 4dd5b86

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

lib/format_pcapng.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ static inline uint32_t pcapng_get_record_type(const libtrace_packet_t *packet)
7373
{
7474
uint32_t *btype = (uint32_t *)packet->header;
7575

76+
if (btype == NULL) {
77+
return 0;
78+
}
79+
7680
/* only check for byteswapped if input format is pcapng */
7781
if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
7882
if (DATA(packet->trace)->byteswapped)
@@ -891,6 +895,17 @@ static int pcapng_write_packet(libtrace_out_t *libtrace,
891895

892896
libtrace_linktype_t linktype = trace_get_link_type(packet);
893897

898+
if (packet->trace->format->type != TRACE_FORMAT_PCAPNG) {
899+
while (libtrace_to_pcap_linktype(linktype) == TRACE_DLT_ERROR) {
900+
if (!demote_packet(packet)) {
901+
trace_set_err_out(libtrace, TRACE_ERR_NO_CONVERSION,
902+
"cannot convert this type of packet to pcapng");
903+
return -1;
904+
}
905+
linktype = trace_get_link_type(packet);
906+
}
907+
}
908+
894909
/* If the file is not open, open it */
895910
if (!DATAOUT(libtrace)->file) {
896911
DATAOUT(libtrace)->file = trace_open_file_out(

0 commit comments

Comments
 (0)