773311
From ccaeae4261bc7d35d48a511f71cfc25728786b24 Mon Sep 17 00:00:00 2001
773311
From: Ilya Maximets <i.maximets@ovn.org>
773311
Date: Tue, 5 May 2020 13:08:50 +0200
773311
Subject: [PATCH 2/4] ovn-northd: Fix memory leak and incorrect limiting of
773311
 ECMP routes.
773311
773311
If route count reaches UINT16_MAX, ecmp_groups_add_route() will leak the
773311
allocated route structure.  Also, since group->route_count incremented
773311
unconditionally, next attempt to add new route will succeed, because the
773311
value of 'route_count' is zero now and out of sync with the real number
773311
of routes.
773311
773311
Fixes: 4e53974bdc4e ("ovn-northd: Support ECMP routes.")
773311
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
773311
Acked-by: Mark Michelson <mmichels@redhat.com>
773311
Signed-off-by: Han Zhou <hzhou@ovn.org>
773311
---
773311
 northd/ovn-northd.c | 8 ++++----
773311
 1 file changed, 4 insertions(+), 4 deletions(-)
773311
773311
diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
773311
index ec77ae1a8..dc647d7c5 100644
773311
--- a/northd/ovn-northd.c
773311
+++ b/northd/ovn-northd.c
773311
@@ -7188,15 +7188,15 @@ static void
773311
 ecmp_groups_add_route(struct ecmp_groups_node *group,
773311
                       const struct parsed_route *route)
773311
 {
773311
-    struct ecmp_route_list_node *er = xmalloc(sizeof *er);
773311
-    er->route = route;
773311
-    er->id = ++group->route_count;
773311
-    if (er->id == 0) {
773311
+   if (group->route_count == UINT16_MAX) {
773311
         static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1);
773311
         VLOG_WARN_RL(&rl, "too many routes in a single ecmp group.");
773311
         return;
773311
     }
773311
 
773311
+    struct ecmp_route_list_node *er = xmalloc(sizeof *er);
773311
+    er->route = route;
773311
+    er->id = ++group->route_count;
773311
     ovs_list_insert(&group->route_list, &er->list_node);
773311
 }
773311
 
773311
-- 
773311
2.26.2
773311