Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: no newline when debug msg over DEBUG_BUF_SIZE - backport 2.28 #7608

Merged
merged 8 commits into from
May 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
send debug msg if contains '\n'
Signed-off-by: valord577 <valord577@gmail.com>
  • Loading branch information
valord577 authored and daverodgman committed May 16, 2023
commit e3623920cf0649fd0b26952ddd27446b5966a138
27 changes: 19 additions & 8 deletions library/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level,
va_list argp;
char str[DEBUG_BUF_SIZE];
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
int newline = -1;

if (NULL == ssl ||
NULL == ssl->conf ||
Expand All @@ -80,16 +81,26 @@ void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level,
ret = mbedtls_vsnprintf(str, DEBUG_BUF_SIZE, format, argp);
va_end(argp);

if (ret >= 0 && ret < DEBUG_BUF_SIZE - 1) {
str[ret] = '\n';
str[ret + 1] = '\0';
}
else
{
str[DEBUG_BUF_SIZE - 2] = '\n';
if (DEBUG_BUF_SIZE >= 2) {
if (ret < 0) {
newline = 0;
} else {
newline = ret;
if (ret >= DEBUG_BUF_SIZE - 1) {
newline = DEBUG_BUF_SIZE - 2;
}
}
}

debug_send_line(ssl, level, file, line, str);
/*
* Send if str contains '\n'.
*/
if (newline >= 0) {
str[newline] = '\n';
str[newline + 1] = '\0';

debug_send_line(ssl, level, file, line, str);
}
}

void mbedtls_debug_print_ret(const mbedtls_ssl_context *ssl, int level,
Expand Down