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 17bfb62ac3a177502e5a07ea7035ba2e2bd3262a
Author: guanyi <[email protected]>
AuthorDate: Fri Jan 24 11:14:53 2025 +0800

    driver/note: fix overflowed integer argument
    
    sched_note_event_ip() caps the note at sizeof(data) - 1 bytes and then
    passes length - SIZEOF_NOTE_EVENT(0) to memcpy().  Static analysis
    reports that argument as a possible integer overflow, because nothing
    ties the size of the stack buffer to the size of the note header.
    
    Name the buffer size BUFFER_SIZE, use it for the buffers of
    sched_note_event_ip() and sched_note_vprintf_ip(), and check at build
    time that it is at least sizeof(struct note_event_s).
    
    Assisted-by: Kiro:claude-opus-5-5
    Signed-off-by: guanyi <[email protected]>
---
 drivers/note/note_driver.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/note/note_driver.c b/drivers/note/note_driver.c
index c978e9387c0..3f21d4c757f 100644
--- a/drivers/note/note_driver.c
+++ b/drivers/note/note_driver.c
@@ -107,6 +107,10 @@
 #define note_vprintf(drv, ip, fmt, va)                                       \
   ((drv)->ops->vprintf && ((drv)->ops->vprintf(drv, ip, fmt, va), true))
 
+#define BUFFER_SIZE 256
+static_assert(BUFFER_SIZE >= sizeof(struct note_event_s),
+              "Buffer size too small");
+
 /****************************************************************************
  * Private Types
  ****************************************************************************/
@@ -1498,7 +1502,7 @@ void sched_note_event_ip(uint32_t tag, uintptr_t ip, 
uint8_t event,
   FAR struct note_event_s *note;
   FAR struct note_driver_s **driver;
   bool formatted = false;
-  char data[256];
+  char data[BUFFER_SIZE];
   unsigned int length;
   FAR struct tcb_s *tcb = running_task();
 
@@ -1552,7 +1556,7 @@ void sched_note_vprintf_ip(uint32_t tag, uintptr_t ip, 
FAR const char *fmt,
   FAR struct note_printf_s *note;
   FAR struct note_driver_s **driver;
   bool formatted = false;
-  uint8_t data[256];
+  uint8_t data[BUFFER_SIZE];
   size_t length = 0;
   FAR struct tcb_s *tcb = running_task();
 

Reply via email to