You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/05/17 17:36:22 UTC

[incubator-nuttx] branch master updated: syslog: Fixed a potential buffer overflow issue

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 335fc3dde2 syslog: Fixed a potential buffer overflow issue
335fc3dde2 is described below

commit 335fc3dde2d7851817e2d42d79133a1e5e009c0a
Author: gaojiawei <ga...@xiaomi.com>
AuthorDate: Tue May 17 15:46:49 2022 +0800

    syslog: Fixed a potential buffer overflow issue
    
    The `CONFIG_SYSLOG_MAX_CHANNELS` is user-specified, however, if the user
    defines more channels than what `CONFIG_SYSLOG_MAX_CHANNELS` was defined as,
    a potential buffer overflow occurred. Although the compiler does warn us about
    that, we should explicitly tell the user this is an error.
    
    Signed-off-by: gaojiawei <ga...@xiaomi.com>
---
 drivers/syslog/syslog_channel.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/syslog/syslog_channel.c b/drivers/syslog/syslog_channel.c
index 1b26eef7f6..d5f938a926 100644
--- a/drivers/syslog/syslog_channel.c
+++ b/drivers/syslog/syslog_channel.c
@@ -129,6 +129,43 @@ static struct syslog_channel_s g_default_channel =
 };
 #endif
 
+/* This is a simply sanity check to avoid we have more elements than the
+ * `g_syslog_channel` array can hold
+ */
+
+#ifdef CONFIG_SYSLOG_DEFAULT
+#  define SYSLOG_DEFAULT_AVAILABLE 1
+#else
+#  define SYSLOG_DEFAULT_AVAILABLE 0
+#endif
+
+#ifdef CONFIG_RAMLOG_SYSLOG
+#  define RAMLOG_SYSLOG_AVAILABLE 1
+#else
+#  define RAMLOG_SYSLOG_AVAILABLE 0
+#endif
+
+#ifdef CONFIG_SYSLOG_RPMSG
+#  define SYSLOG_RPMSG_AVAILABLE 1
+#else
+#  define SYSLOG_RPMSG_AVAILABLE 0
+#endif
+
+#ifdef CONFIG_SYSLOG_RTT
+#  define SYSLOG_RTT_AVAILABLE 1
+#else
+#  define SYSLOG_RTT_AVAILABLE 0
+#endif
+
+#define SYSLOG_NCHANNELS (SYSLOG_DEFAULT_AVAILABLE + \
+                          RAMLOG_SYSLOG_AVAILABLE + \
+                          SYSLOG_RPMSG_AVAILABLE + \
+                          SYSLOG_RTT_AVAILABLE)
+
+#if SYSLOG_NCHANNELS > CONFIG_SYSLOG_MAX_CHANNELS
+#  error "Maximum channel number exceeds."
+#endif
+
 /* This is the current syslog channel in use */
 
 FAR struct syslog_channel_s