Skip to content
Permalink
Browse files
MDEV-16777: galera.galera_gra_log fails with File ...GRA_*.log not fo…
…und 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.
  • Loading branch information
spetrunia committed Jul 19, 2018
1 parent 4d06b7e commit 09f1476
Showing 1 changed file with 11 additions and 3 deletions.
@@ -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,15 +474,18 @@ 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)))
{
WSREP_ERROR("snprintf error: %d, skipping dump.", len);
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);

0 comments on commit 09f1476

Please sign in to comment.