From e57944ef44a335db8219b2e398403db11660dc91 Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Tue, 11 Feb 2014 14:55:16 +0200 Subject: [PATCH] Bug #399, http://bugs.skysql.com/show_bug.cgi?id=399 Corrected the length variable including length of timestampt string which doesn't include terminating null. --- log_manager/log_manager.cc | 17 +++++++++-------- utils/skygw_utils.cc | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index d369d5e53..54a9e5968 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -663,7 +663,8 @@ static int logmanager_write_log( flush); /** * Write timestamp with at most characters - * to wp + * to wp. + * Returned timestamp_len doesn't include terminating null. */ timestamp_len = snprint_timestamp(wp, timestamp_len); /** @@ -671,9 +672,9 @@ static int logmanager_write_log( * of the timestamp string. */ if (use_valist) { - vsnprintf(wp+timestamp_len-1, safe_str_len, str, valist); + vsnprintf(wp+timestamp_len, safe_str_len, str, valist); } else { - snprintf(wp+timestamp_len-1, safe_str_len, str); + snprintf(wp+timestamp_len, safe_str_len, str); } /** write to syslog */ @@ -681,11 +682,11 @@ static int logmanager_write_log( { switch(id) { case LOGFILE_ERROR: - syslog(LOG_ERR, wp+timestamp_len-1); + syslog(LOG_ERR, wp+timestamp_len); break; case LOGFILE_MESSAGE: - syslog(LOG_NOTICE, wp+timestamp_len-1); + syslog(LOG_NOTICE, wp+timestamp_len); break; default: @@ -694,10 +695,10 @@ static int logmanager_write_log( } /** remove double line feed */ - if (wp[timestamp_len-1+str_len-2] == '\n') { - wp[timestamp_len-1+str_len-2]=' '; + if (wp[timestamp_len+str_len-2] == '\n') { + wp[timestamp_len+str_len-2]=' '; } - wp[timestamp_len-1+str_len-1]='\n'; + wp[timestamp_len+str_len-1]='\n'; blockbuf_unregister(bb); /** diff --git a/utils/skygw_utils.cc b/utils/skygw_utils.cc index 64c96362d..1ed569962 100644 --- a/utils/skygw_utils.cc +++ b/utils/skygw_utils.cc @@ -1672,7 +1672,7 @@ static bool file_write_footer( if (header_buf3 == NULL) { goto return_succp; } - tslen = snprint_timestamp(header_buf3, tslen-1); + tslen = snprint_timestamp(header_buf3, tslen); header_buf4 = "\n--------------------------------------------" "---------------------------\n";