From f46acd4a3a74c57a31226b11186746bce6c98813 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 29 Jun 2018 14:00:00 +0300 Subject: Adopt Debian's fix-FTBFS-on-GNU-Hurd.patch. - Took the original patch by Ondrej Sury; - Applied a fix for a known problem in the patch: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=882062 - Fixed a few other issues --- sql/wsrep_binlog.cc | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'sql/wsrep_binlog.cc') diff --git a/sql/wsrep_binlog.cc b/sql/wsrep_binlog.cc index 998f4e72157..52934ff10cd 100644 --- a/sql/wsrep_binlog.cc +++ b/sql/wsrep_binlog.cc @@ -318,13 +318,23 @@ int wsrep_write_cache(wsrep_t* const wsrep, void wsrep_dump_rbr_buf(THD *thd, const void* rbr_buf, size_t buf_len) { - char filename[PATH_MAX]= {0}; - int len= snprintf(filename, PATH_MAX, "%s/GRA_%ld_%lld.log", + int len= snprintf(NULL, 0, "%s/GRA_%ld_%lld.log", wsrep_data_home_dir, thd->thread_id, (long long)wsrep_thd_trx_seqno(thd)); - if (len >= PATH_MAX) + if (len < 0) { - WSREP_ERROR("RBR dump path too long: %d, skipping dump.", len); + WSREP_ERROR("snprintf error: %d, skipping dump.", len); + DBUG_VOID_RETURN; + } + + char *filename= (char *)malloc(len++); + int len1= snprintf(filename, len, "%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); + free(filename); return; } @@ -343,6 +353,7 @@ void wsrep_dump_rbr_buf(THD *thd, const void* rbr_buf, size_t buf_len) WSREP_ERROR("Failed to open file '%s': %d (%s)", filename, errno, strerror(errno)); } + free(filename); } /* @@ -448,19 +459,32 @@ void wsrep_dump_rbr_buf_with_header(THD *thd, const void *rbr_buf, { DBUG_ENTER("wsrep_dump_rbr_buf_with_header"); - char filename[PATH_MAX]= {0}; File file; IO_CACHE cache; Log_event_writer writer(&cache); Format_description_log_event *ev=NULL; - int len= my_snprintf(filename, PATH_MAX, "%s/GRA_%ld_%lld_v2.log", + longlong thd_trx_seqno= (long long)wsrep_thd_trx_seqno(thd); + + int len= my_snprintf(NULL, 0, "%s/GRA_%ld_%lld_v2.log", wsrep_data_home_dir, thd->thread_id, - (long long) wsrep_thd_trx_seqno(thd)); + thd_trx_seqno); - if (len >= PATH_MAX) + char *filename; + if (len < 0 || !(filename= (char*)malloc(len++))) { - WSREP_ERROR("RBR dump path too long: %d, skipping dump.", len); + WSREP_ERROR("snprintf error: %d, skipping dump.", len); + DBUG_VOID_RETURN; + } + + int len1= my_snprintf(filename, len, "%s/GRA_%ld_%lld_v2.log", + wsrep_data_home_dir, thd->thread_id, + thd_trx_seqno); + + if (len >= len1) + { + WSREP_ERROR("RBR dump path truncated: %d, skipping dump.", len); + free(filename); DBUG_VOID_RETURN; } @@ -501,6 +525,7 @@ cleanup2: end_io_cache(&cache); cleanup1: + free(filename); mysql_file_close(file, MYF(MY_WME)); if (!thd->wsrep_applier) delete ev; -- cgit v1.2.1 From 36ea82617c1506532e863cb241296acc8b657243 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 29 Jun 2018 18:16:56 +0300 Subject: Fix a typo a in the commit before the last one in the "Adopt Debian's fix-FTBFS-on-GNU-Hurd.patch", DBUG_VOID_RETURN has been used instead of "return" --- sql/wsrep_binlog.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/wsrep_binlog.cc') diff --git a/sql/wsrep_binlog.cc b/sql/wsrep_binlog.cc index 52934ff10cd..f8553d015aa 100644 --- a/sql/wsrep_binlog.cc +++ b/sql/wsrep_binlog.cc @@ -324,7 +324,7 @@ void wsrep_dump_rbr_buf(THD *thd, const void* rbr_buf, size_t buf_len) if (len < 0) { WSREP_ERROR("snprintf error: %d, skipping dump.", len); - DBUG_VOID_RETURN; + return; } char *filename= (char *)malloc(len++); -- cgit v1.2.1 From 1d10c9afe0f2f4fba73892e6c12ea6efe90d5931 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Mon, 2 Jul 2018 15:29:22 +0300 Subject: Post-fix to "Adopt Debian's fix-FTBFS-on-GNU-Hurd.patch", part #2. "my_snprintf(NULL, 0, ...)" does not follow what snprintf does. Change the call in wsrep_dump_rbr_buf_with_header to use snprintf (note that wsrep_dump_rbr_buf was using snprintf all the way). Fix an off-by-one error in comparison so it actually prints the output --- sql/wsrep_binlog.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'sql/wsrep_binlog.cc') diff --git a/sql/wsrep_binlog.cc b/sql/wsrep_binlog.cc index f8553d015aa..902190d4772 100644 --- a/sql/wsrep_binlog.cc +++ b/sql/wsrep_binlog.cc @@ -327,11 +327,11 @@ void wsrep_dump_rbr_buf(THD *thd, const void* rbr_buf, size_t buf_len) return; } - char *filename= (char *)malloc(len++); + char *filename= (char *)malloc(len+1); int len1= snprintf(filename, len, "%s/GRA_%ld_%lld.log", wsrep_data_home_dir, thd->thread_id, (long long)wsrep_thd_trx_seqno(thd)); - if (len >= len1) + if (len > len1) { WSREP_ERROR("RBR dump path truncated: %d, skipping dump.", len); free(filename); @@ -466,22 +466,22 @@ void wsrep_dump_rbr_buf_with_header(THD *thd, const void *rbr_buf, longlong thd_trx_seqno= (long long)wsrep_thd_trx_seqno(thd); - int len= my_snprintf(NULL, 0, "%s/GRA_%ld_%lld_v2.log", - wsrep_data_home_dir, thd->thread_id, - thd_trx_seqno); + int len= snprintf(NULL, 0, "%s/GRA_%ld_%lld_v2.log", + wsrep_data_home_dir, thd->thread_id, + thd_trx_seqno); char *filename; - if (len < 0 || !(filename= (char*)malloc(len++))) + if (len < 0 || !(filename= (char*)malloc(len+1))) { WSREP_ERROR("snprintf error: %d, skipping dump.", len); DBUG_VOID_RETURN; } - int len1= my_snprintf(filename, len, "%s/GRA_%ld_%lld_v2.log", - wsrep_data_home_dir, thd->thread_id, - thd_trx_seqno); + int len1= snprintf(filename, len, "%s/GRA_%ld_%lld_v2.log", + wsrep_data_home_dir, thd->thread_id, + thd_trx_seqno); - if (len >= len1) + if (len > len1) { WSREP_ERROR("RBR dump path truncated: %d, skipping dump.", len); free(filename); -- cgit v1.2.1 From 09f147659f36a30d7075885d88392c9a41244505 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Thu, 19 Jul 2018 12:07:07 +0300 Subject: 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(-) (limited to 'sql/wsrep_binlog.cc') diff --git a/sql/wsrep_binlog.cc b/sql/wsrep_binlog.cc index 902190d4772..c7674cd0169 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); -- cgit v1.2.1