From e002edf87c8e6765be59158e86fc8e651ae31a51 Mon Sep 17 00:00:00 2001 From: chao an Date: Mon, 5 Dec 2022 13:12:14 +0800 Subject: [PATCH] net/devif: reprepare iob buffer before polling connections Loopback device will consume the d_iob packet in upper layer protocol, in order to avoid null pointer access, reprepare iob buffer before polling connections Signed-off-by: chao an --- net/devif/devif_poll.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index fed11e7ba2..d8561f2124 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -645,7 +645,7 @@ static inline int devif_poll_tcp_connections(FAR struct net_driver_s *dev, static int devif_poll_connections(FAR struct net_driver_s *dev, devif_poll_callback_t callback) { - int bstop; + int bstop = false; /* Traverse all of the active packet connections and perform the poll * action. @@ -903,8 +903,8 @@ static int devif_poll_callback(FAR struct net_driver_s *dev) int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback) { uint16_t llhdrlen; - int bstop = false; FAR uint8_t *buf; + int bstop; if (dev->d_buf == NULL) { @@ -913,17 +913,18 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback) buf = dev->d_buf; - /* Device polling, prepare iob buffer */ - - if (netdev_iob_prepare(dev, false, 0) != OK) - { - return true; - } - llhdrlen = NET_LL_HDRLEN(dev); do { + /* Device polling, prepare iob buffer */ + + if (netdev_iob_prepare(dev, false, 0) != OK) + { + bstop = true; + break; + } + /* Perform all connections poll */ bstop = devif_poll_connections(dev, devif_poll_callback); @@ -951,18 +952,13 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback) if (dev->d_buf != buf) { - if (dev->d_buf == NULL) + buf = dev->d_buf; + + if (buf == NULL) { break; } - - buf = dev->d_buf; } - - /* Finish copy, reset iob */ - - netdev_iob_prepare(dev, false, 0); - iob_update_pktlen(dev->d_iob, 0); } } while (bstop);