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 <gaojiawei@xiaomi.com>
This commit is contained in:
parent
817919ebb6
commit
335fc3dde2
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user