Skip to content

Commit

Permalink
Merge pull request #2687 from rouault/pj_vlog_buffer_overflow
Browse files Browse the repository at this point in the history
pj_vlog(): fix buffer overflow in case of super lengthy error message
  • Loading branch information
rouault authored Apr 23, 2021
2 parents 2733271 + c221134 commit 57102f4
Showing 1 changed file with 5 additions and 4 deletions.
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

0 comments on commit 57102f4

Please sign in to comment.