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 c7b56cfae7cbbb571ce5ef7cf7a90170a5134904
Author: wangshaoxin <[email protected]>
AuthorDate: Thu Nov 26 10:08:20 2026 +0800

    drivers/misc/rpmsgblk: keep a copy of the remote cpu and path
    
    rpmsgblk_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/misc/rpmsgblk.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/rpmsgblk.c b/drivers/misc/rpmsgblk.c
index 0c0355bb277..ea4410770f9 100644
--- a/drivers/misc/rpmsgblk.c
+++ b/drivers/misc/rpmsgblk.c
@@ -54,8 +54,13 @@ struct rpmsgblk_s
 {
   struct block_operations blk;         /* Rpmsg-Block device operation */
   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 -
+                                     RPMSGBLK_NAME_PREFIX_LEN];
+
   sem_t                   wait;        /* Wait sem, used for preventing any
                                         * operation until the connection
                                         * between two cpu established.
@@ -1288,8 +1293,8 @@ int rpmsgblk_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->lock);

Reply via email to