2022-02-16 08:27:44

by Joseph Hwang

[permalink] [raw]
Subject: [BlueZ PATCH v1] 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 <[email protected]>
Reviewed-by: Yun-Hao Chung <[email protected]>
Reviewed-by: Shuo-Peng Liao <[email protected]>
Signed-off-by: Joseph Hwang <[email protected]>
---

monitor/analyze.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/monitor/analyze.c b/monitor/analyze.c
index 0c74e8f2e..ac23e13bb 100644
--- a/monitor/analyze.c
+++ b/monitor/analyze.c
@@ -161,7 +161,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.35.1.265.g69c8d7142f-goog