revision-id: 09f147659f36a30d7075885d88392c9a41244505 parent(s): 4d06b7e1bd3b825da32c9200e6f5ca609add0e13 committer: Sergei Petrunia branch nick: 10.1-r2 timestamp: 2018-07-19 12:07:07 +0300 message: MDEV-16777: galera.galera_gra_log fails with File ...GRA_*.log not found error snprintf returns the number of bytes it wrote (or would have written) NOT counting the \0 terminal character. The buffer size it accepts as argument DOES COUNT the \0 character. Pass the right parameter value. --- sql/wsrep_binlog.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sql/wsrep_binlog.cc b/sql/wsrep_binlog.cc index 902190d..c7674cd 100644 --- a/sql/wsrep_binlog.cc +++ b/sql/wsrep_binlog.cc @@ -326,11 +326,16 @@ void wsrep_dump_rbr_buf(THD *thd, const void* rbr_buf, size_t buf_len) WSREP_ERROR("snprintf error: %d, skipping dump.", len); return; } + /* + len doesn't count the \0 end-of-string. Use len+1 below + to alloc and pass as an argument to snprintf. + */ char *filename= (char *)malloc(len+1); - int len1= snprintf(filename, len, "%s/GRA_%ld_%lld.log", + int len1= snprintf(filename, len+1, "%s/GRA_%ld_%lld.log", wsrep_data_home_dir, thd->thread_id, (long long)wsrep_thd_trx_seqno(thd)); + if (len > len1) { WSREP_ERROR("RBR dump path truncated: %d, skipping dump.", len); @@ -469,7 +474,10 @@ void wsrep_dump_rbr_buf_with_header(THD *thd, const void *rbr_buf, int len= snprintf(NULL, 0, "%s/GRA_%ld_%lld_v2.log", wsrep_data_home_dir, thd->thread_id, thd_trx_seqno); - + /* + len doesn't count the \0 end-of-string. Use len+1 below + to alloc and pass as an argument to snprintf. + */ char *filename; if (len < 0 || !(filename= (char*)malloc(len+1))) { @@ -477,7 +485,7 @@ void wsrep_dump_rbr_buf_with_header(THD *thd, const void *rbr_buf, DBUG_VOID_RETURN; } - int len1= snprintf(filename, len, "%s/GRA_%ld_%lld_v2.log", + int len1= snprintf(filename, len+1, "%s/GRA_%ld_%lld_v2.log", wsrep_data_home_dir, thd->thread_id, thd_trx_seqno);