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

[Backport 8.0] pj_vlog(): fix buffer overflow in case of super lengthy error message #2693

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Changes from all commits
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
9 changes: 5 additions & 4 deletions src/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void pj_stderr_logger( void *app_data, int level, const char *msg )
/* pj_vlog() */
/************************************************************************/
void pj_vlog( PJ_CONTEXT *ctx, int level, const char *fmt, va_list args );
/* Workhorse for the log functions - relates to pj_log as vsprintf relates to sprintf */

void pj_vlog( PJ_CONTEXT *ctx, int level, const char *fmt, va_list args )

{
Expand All @@ -67,12 +67,13 @@ void pj_vlog( PJ_CONTEXT *ctx, int level, const char *fmt, va_list args )
if( level > debug_level )
return;

msg_buf = (char *) malloc(100000);
constexpr size_t BUF_SIZE = 100000;
msg_buf = (char *) malloc(BUF_SIZE);
if( msg_buf == nullptr )
return;

/* we should use vsnprintf where available once we add configure detect.*/
vsprintf( msg_buf, fmt, args );
vsnprintf( msg_buf, BUF_SIZE, fmt, args );
msg_buf[BUF_SIZE-1] = '\0';

ctx->logger( ctx->logger_app_data, level, msg_buf );

Expand Down