aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-04-23 21:47:54 +0200
committerGitHub <noreply@github.com>2021-04-23 21:47:54 +0200
commita7a4d35816b7e2a0e62a681304da27df1deb4e13 (patch)
tree5f28d47be26d0d9b49147686c0ab8fbbd65e06d9
parentae168e009b237d994bc5f406bdc2f0608330c3a9 (diff)
parent71f6e3a21f9a7e21308f4f26471c24746607c8b9 (diff)
downloadPROJ-a7a4d35816b7e2a0e62a681304da27df1deb4e13.tar.gz
PROJ-a7a4d35816b7e2a0e62a681304da27df1deb4e13.zip
Merge pull request #2693 from OSGeo/backport-2687-to-8.0
[Backport 8.0] pj_vlog(): fix buffer overflow in case of super lengthy error message
-rw-r--r--src/log.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/log.cpp b/src/log.cpp
index c50b0ebc..6bad34d4 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -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 )
{
@@ -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 );