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 402d5db9a096310aee8972dbbb426d85289e3bf7 Author: Bowen Wang <[email protected]> AuthorDate: Fri Jul 10 16:14:53 2026 +0800 drivers/syslog/syslog_rpmsg: reset a buffer with a corrupted header The buffer may be kept across a reboot, or shared with another firmware, and come back with head or tail out of range while the magic is still valid. syslog_rpmsg_transfer() would then copy from an address outside the buffer. Reset the buffer when head or tail is not below size. Signed-off-by: Bowen Wang <[email protected]> --- drivers/syslog/syslog_rpmsg.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/syslog/syslog_rpmsg.c b/drivers/syslog/syslog_rpmsg.c index 3f780c268b2..a7543d5a019 100644 --- a/drivers/syslog/syslog_rpmsg.c +++ b/drivers/syslog/syslog_rpmsg.c @@ -129,7 +129,15 @@ static void syslog_rpmsg_init_buffer(FAR struct syslog_rpmsg_s *priv) header->size = CONFIG_SYSLOG_RPMSG_BUFSIZE - sizeof(struct syslog_rpmsg_buffer_header_s); #endif - if (header->magic != SYSLOG_RPMSG_MAGIC_NUMBER) + /* Reset the buffer when it is uninitialized (bad magic), or when the + * head/tail indices are out of range. The shared buffer may have been + * left corrupted by another firmware; a bad head/tail would make + * syslog_rpmsg_transfer() memcpy from a wild source address, so discard + * the content and start clean rather than replaying a corrupted buffer. + */ + + if (header->magic != SYSLOG_RPMSG_MAGIC_NUMBER || + header->head >= header->size || header->tail >= header->size) { header->head = 0; header->tail = 0;
