mirror of
https://github.com/espressif/openthread.git
synced 2026-09-12 04:00:10 +00:00
[posix] fix the snprintf buffer overflow issue (#9251)
This commit is contained in:
@@ -74,15 +74,22 @@ void GetFilename(Filename &aFilename, const char *aPattern)
|
||||
|
||||
int Daemon::OutputFormatV(const char *aFormat, va_list aArguments)
|
||||
{
|
||||
char buf[OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH + 1];
|
||||
int rval;
|
||||
static constexpr char truncatedMsg[] = "(truncated ...)";
|
||||
char buf[OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH];
|
||||
int rval;
|
||||
|
||||
buf[OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH] = '\0';
|
||||
|
||||
rval = vsnprintf(buf, sizeof(buf) - 1, aFormat, aArguments);
|
||||
static_assert(sizeof(truncatedMsg) < OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH,
|
||||
"OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH is too short!");
|
||||
|
||||
rval = vsnprintf(buf, sizeof(buf), aFormat, aArguments);
|
||||
VerifyOrExit(rval >= 0, otLogWarnPlat("Failed to format CLI output: %s", strerror(errno)));
|
||||
|
||||
if (rval >= static_cast<int>(sizeof(buf)))
|
||||
{
|
||||
rval = static_cast<int>(sizeof(buf) - 1);
|
||||
memcpy(buf + sizeof(buf) - sizeof(truncatedMsg), truncatedMsg, sizeof(truncatedMsg));
|
||||
}
|
||||
|
||||
VerifyOrExit(mSessionSocket != -1);
|
||||
|
||||
#if defined(__linux__)
|
||||
|
||||
Reference in New Issue
Block a user