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

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

commit caf9b0b60d29aec152ac2cf88058e749c8f50c12
Author: guoshengyuan3 <[email protected]>
AuthorDate: Fri Oct 16 12:35:23 2026 +0800

    drivers/mtd/rpmsgmtd: do not copy the ioctl argument from a NULL pointer
    
    rpmsgmtd_ioctl() copied arglen bytes from arg, and gave arg to the
    reply copy, whenever the command has an argument size, also when the
    caller passed arg 0. UBSan reports this as "null pointer passed as
    argument 2". Copy the argument and the reply only when arg is not 0.
    
    Signed-off-by: guoshengyuan3 <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/mtd/rpmsgmtd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/rpmsgmtd.c b/drivers/mtd/rpmsgmtd.c
index 5959e3bae06..bd6e2b3d6c1 100644
--- a/drivers/mtd/rpmsgmtd.c
+++ b/drivers/mtd/rpmsgmtd.c
@@ -654,13 +654,14 @@ static int rpmsgmtd_ioctl(FAR struct mtd_dev_s *dev, int 
cmd,
   msg->arg     = arg;
   msg->arglen  = arglen;
 
-  if (arglen > 0)
+  if (arg != 0 && arglen > 0)
     {
       memcpy(msg->buf, (FAR void *)(uintptr_t)arg, arglen);
     }
 
   return rpmsgmtd_send_recv(priv, RPMSGMTD_IOCTL, false, &msg->header,
-                            msglen, arglen > 0 ? (FAR void *)arg : NULL);
+                            msglen, arglen > 0 && arg != 0 ?
+                            (FAR void *)arg : NULL);
 }
 
 /****************************************************************************

Reply via email to