You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/01/09 13:58:17 UTC

(nuttx) 01/02: net/route: Fix null pointer access when ramroute is full

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 54f3452293e22bf138828ff4540af880a60ed635
Author: Zhe Weng <we...@xiaomi.com>
AuthorDate: Wed Jan 3 14:56:54 2024 +0800

    net/route: Fix null pointer access when ramroute is full
    
    Signed-off-by: Zhe Weng <we...@xiaomi.com>
---
 net/route/net_alloc_ramroute.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/net/route/net_alloc_ramroute.c b/net/route/net_alloc_ramroute.c
index 85d8127574..17d60f7f03 100644
--- a/net/route/net_alloc_ramroute.c
+++ b/net/route/net_alloc_ramroute.c
@@ -159,6 +159,11 @@ FAR struct net_route_ipv4_s *net_allocroute_ipv4(void)
   route = ramroute_ipv4_remfirst(&g_free_ipv4routes);
 
   net_unlock();
+  if (!route)
+    {
+      return NULL;
+    }
+
   return &route->entry;
 }
 #endif
@@ -177,6 +182,11 @@ FAR struct net_route_ipv6_s *net_allocroute_ipv6(void)
   route = ramroute_ipv6_remfirst(&g_free_ipv6routes);
 
   net_unlock();
+  if (!route)
+    {
+      return NULL;
+    }
+
   return &route->entry;
 }
 #endif