From 42c3865d71a3d3ad3fc61ee382ad3b5113d40552 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 1 Jun 2017 17:58:28 -0700 Subject: Make the checks and adjustment of the snapshot length module-dependent. Also, initialize the snapshot length to 0, meaning "not specified", so that the default snapshot length, if not specified, is also module-dependent. That way, D-Bus has a maximum and default of 128MB, as that's the maximum message size, but other capture devices have the current MAXIMUM_SNAPLEN, so we can handle full-size D-Bus messages without advertising an overly-large snapshot length for other devices, potentially causing libpcap and programs using it or reading libpcap files to allocate overly-large buffers for other capture devices. --- pcap-dbus.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'pcap-dbus.c') diff --git a/pcap-dbus.c b/pcap-dbus.c index ea3a390f..2fedaeff 100644 --- a/pcap-dbus.c +++ b/pcap-dbus.c @@ -223,6 +223,14 @@ dbus_activate(pcap_t *handle) return PCAP_ERROR_RFMON_NOTSUP; } + /* + * Turn a negative snapshot value (invalid), a snapshot value of + * 0 (unspecified), or a value bigger than the normal maximum + * value, into the maximum message length for D-Bus (128MB). + */ + if (handle->snapshot <= 0 || handle->snapshot > 134217728) + handle->snapshot = 134217728; + /* dbus_connection_set_max_message_size(handlep->conn, handle->snapshot); */ if (handle->opt.buffer_size != 0) dbus_connection_set_max_received_size(handlep->conn, handle->opt.buffer_size); -- cgit v1.2.3