From 8ae0399886cdcb131c292b2b316888ce3c964fd9 Mon Sep 17 00:00:00 2001 From: Joseph Hwang Date: Wed, 16 Feb 2022 16:15:18 +0800 Subject: [PATCH] monitor: fix division by zero about conn->tx_pkt_med In a connection without outgoing traffic, conn->tx_num will remain 0. In this case, conn->tx_pkt_med should be simply 0 without calculating "conn->tx_bytes / conn->tx_num". This was likely to happen, for example, when "btmon -w btsnoop.log" was launched in the middle of a LE mouse connection, and a number of incoming ACL Data RX were received as the mouse movements. When running "btmon -a btsnoop.log", it would encounter this error. Reviewed-by: Alain Michaud Reviewed-by: Yun-Hao Chung Reviewed-by: Shuo-Peng Liao Signed-off-by: Manika Shrivastava Signed-off-by: Ayush Garg --- monitor/analyze.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monitor/analyze.c b/monitor/analyze.c index 1610e4f..135dc91 100755 --- a/monitor/analyze.c +++ b/monitor/analyze.c @@ -163,7 +163,8 @@ static void conn_destroy(void *data) break; } - conn->tx_pkt_med = conn->tx_bytes / conn->tx_num; + if (conn->tx_num > 0) + conn->tx_pkt_med = conn->tx_bytes / conn->tx_num; printf(" Found %s connection with handle %u\n", str, conn->handle); /* TODO: Store address type */ -- 2.7.4