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 ee9e41f2dd43020a9614944e08448a01b79c929d
Author: Ville Juven <ville.ju...@unikie.com>
AuthorDate: Mon Oct 16 13:18:03 2023 +0300

    mpfs_ethernet.c: Fix possible NULL de-reference
    
    Fix case where NULL is de-referenced via tx/rx buffer or descriptor. Only
    1 queue is currently set up for each, so the indices 1,2,3 are not valid
    and should not be handled.
---
 arch/risc-v/src/mpfs/mpfs_ethernet.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/arch/risc-v/src/mpfs/mpfs_ethernet.c 
b/arch/risc-v/src/mpfs/mpfs_ethernet.c
index 1587803bee..fe764c27e7 100644
--- a/arch/risc-v/src/mpfs/mpfs_ethernet.c
+++ b/arch/risc-v/src/mpfs/mpfs_ethernet.c
@@ -1180,6 +1180,13 @@ static void mpfs_txreset(struct mpfs_ethmac_s *priv)
       priv->queue[qi].txhead = 0;
       priv->queue[qi].txtail = 0;
 
+      if (!txdesc || !txbuffer)
+        {
+          /* The queue index is not set up */
+
+          continue;
+        }
+
       for (ndx = 0; ndx < CONFIG_MPFS_ETHMAC_NTXBUFFERS; ndx++)
         {
           bufaddr = (uintptr_t)&txbuffer[ndx * GMAC_TX_UNITSIZE];
@@ -1255,6 +1262,13 @@ static void mpfs_rxreset(struct mpfs_ethmac_s *priv)
       rxdesc   = priv->queue[qi].rx_desc_tab;
       priv->queue[qi].rxndx = 0;
 
+      if (!rxdesc || !rxbuffer)
+        {
+          /* The queue index is not set up */
+
+          continue;
+        }
+
       for (ndx = 0; ndx < CONFIG_MPFS_ETHMAC_NRXBUFFERS; ndx++)
         {
           bufaddr = (uintptr_t)&rxbuffer[ndx * GMAC_RX_UNITSIZE];

Reply via email to