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 cc6fb0255fb167108db4a683849da602977ca3fb
Author: guoshengyuan3 <[email protected]>
AuthorDate: Thu Oct 15 21:04:45 2026 +0800

    drivers/sensors/sensor_rpmsg: Validate commands before dispatch.
    
    sensor_rpmsg_ept_cb() uses the command of the received message as an
    index into g_sensor_rpmsg_handler[] without any check. A corrupted
    message, for example on an rpmsg UART port, loads a function pointer
    outside the table:
    
      sensor_rpmsg.c:1613:29: runtime error: load of address 0x26c0a4e8
      with insufficient space for an object of type '<unknown> *'
    
    Reject messages shorter than the command field or with an unknown
    command with -EINVAL.
    
    Signed-off-by: guoshengyuan3 <[email protected]>
---
 drivers/sensors/sensor_rpmsg.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/sensors/sensor_rpmsg.c b/drivers/sensors/sensor_rpmsg.c
index ed13ecda6dd..97951935e64 100644
--- a/drivers/sensors/sensor_rpmsg.c
+++ b/drivers/sensors/sensor_rpmsg.c
@@ -1596,7 +1596,18 @@ static int sensor_rpmsg_ept_cb(FAR struct rpmsg_endpoint 
*ept,
                                FAR void *priv)
 {
   FAR struct sensor_rpmsg_advsub_s *msg = data;
-  uint32_t command = msg->command;
+  uint32_t command;
+
+  if (len < sizeof(msg->command))
+    {
+      return -EINVAL;
+    }
+
+  command = msg->command;
+  if (command > SENSOR_RPMSG_IOCTL_ACK)
+    {
+      return -EINVAL;
+    }
 
   /* For publish handler, use the original rx buffer directly to avoid
    * extra copy. For all other handlers, copy data to a temporary stack

Reply via email to