From 63dfa6f1c7fbc236c3b3cebb50273201dd56bc35 Mon Sep 17 00:00:00 2001
From: James M Snell <jasnell@gmail.com>
Date: Thu, 20 Aug 2020 09:51:33 -0700
Subject: [PATCH] Assert when window is zero

Fixes: https://github.com/ngtcp2/ngtcp2/issues/257
---
 lib/ngtcp2_conn.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/ngtcp2_conn.c b/lib/ngtcp2_conn.c
index 9ba2984b..ff8c608b 100644
--- a/lib/ngtcp2_conn.c
+++ b/lib/ngtcp2_conn.c
@@ -595,6 +595,12 @@ static void conn_update_recv_rate(ngtcp2_conn *conn, size_t datalen,
   window = conn->cstat.min_rtt == UINT64_MAX ? conn->cstat.initial_rtt
                                              : conn->cstat.min_rtt * 2;
 
+  /* If settings.initial_rtt is zero for whatever reason then window
+     can be zero and we can end up with a division by zero error when
+     bps is set below. If this assert fails, check that
+     settings.initial_rtt is not zero. */
+  assert(window);
+
   if (window > ts - conn->rx.rate.start_ts) {
     return;
   }
-- 
GitLab