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 45b070462c6a1d7670588c2a312f906a0f33b3fb
Author: wangshaoxin <[email protected]>
AuthorDate: Thu Aug 6 10:47:55 2026 +0800

    drivers/mtd/rpmsgmtd: keep a copy of the remote cpu and path
    
    rpmsgmtd_register() only saved the remotecpu and remotepath pointers of
    the caller. They are used much later, in the device_created and
    device_destroy callbacks, so a caller that passes a stack buffer or
    frees the strings after registration leaves the driver reading freed
    memory. Copy them into the device.
    
    Signed-off-by: wangshaoxin <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/mtd/rpmsgmtd.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/rpmsgmtd.c b/drivers/mtd/rpmsgmtd.c
index a78169fd57f..89968f7c49b 100644
--- a/drivers/mtd/rpmsgmtd.c
+++ b/drivers/mtd/rpmsgmtd.c
@@ -49,8 +49,13 @@ struct rpmsgmtd_s
 {
   struct mtd_dev_s      mtd;         /* MTD device */
   struct rpmsg_endpoint ept;         /* Rpmsg endpoint */
-  FAR const char       *remotecpu;   /* The server cpu name */
-  FAR const char       *remotepath;  /* The device path in the server cpu */
+
+  /* The server cpu name and the device path in the server cpu */
+
+  char                  remotecpu[RPMSG_NAME_SIZE];
+  char                  remotepath[RPMSG_NAME_SIZE -
+                                   RPMSGMTD_NAME_PREFIX_LEN];
+
   sem_t                 wait;        /* Wait sem, used for preventing any
                                       * operation until the connection
                                       * between two cpu established.
@@ -1156,8 +1161,8 @@ int rpmsgmtd_register(FAR const char *remotecpu, FAR 
const char *remotepath,
 
   /* Initialize the rpmsg device */
 
-  dev->remotecpu  = remotecpu;
-  dev->remotepath = remotepath;
+  strlcpy(dev->remotecpu, remotecpu, sizeof(dev->remotecpu));
+  strlcpy(dev->remotepath, remotepath, sizeof(dev->remotepath));
 
   nxsem_init(&dev->wait, 0, 0);
   nxmutex_init(&dev->geolock);

Reply via email to