From dc42b3c4d9546153e2f0049393e3771e21551679 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Fri, 11 Jan 2019 01:44:07 +0100 Subject: [PATCH 01/15] Backport MDEV-17504 to 5.5 mysql_install_db.exe should not remove datadir, if it was not created by it. --- sql/CMakeLists.txt | 2 +- sql/mysql_install_db.cc | 72 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 67 insertions(+), 7 deletions(-) diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 02196a7e366..6648b7a2612 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -351,7 +351,7 @@ IF(WIN32) ${CMAKE_CURRENT_BINARY_DIR}/mysql_bootstrap_sql.c COMPONENT Server ) - TARGET_LINK_LIBRARIES(mysql_install_db mysys) + TARGET_LINK_LIBRARIES(mysql_install_db mysys shlwapi) ADD_LIBRARY(winservice STATIC winservice.c) TARGET_LINK_LIBRARIES(winservice shell32) diff --git a/sql/mysql_install_db.cc b/sql/mysql_install_db.cc index 9c1a234241f..9d2b261b46c 100644 --- a/sql/mysql_install_db.cc +++ b/sql/mysql_install_db.cc @@ -28,6 +28,8 @@ #include #include #include +struct IUnknown; +#include #define USAGETEXT \ "mysql_install_db.exe Ver 1.00 for Windows\n" \ @@ -532,20 +534,78 @@ static int create_db_instance() DWORD cwd_len= MAX_PATH; char cmdline[3*MAX_PATH]; FILE *in; + bool cleanup_datadir= true; + DWORD last_error; verbose("Running bootstrap"); GetCurrentDirectory(cwd_len, cwd); - CreateDirectory(opt_datadir, NULL); /*ignore error, it might already exist */ + + /* Create datadir and datadir/mysql, if they do not already exist. */ + + if (!CreateDirectory(opt_datadir, NULL) && (GetLastError() != ERROR_ALREADY_EXISTS)) + { + last_error = GetLastError(); + switch(last_error) + { + case ERROR_ACCESS_DENIED: + die("Can't create data directory '%s' (access denied)\n", + opt_datadir); + break; + case ERROR_PATH_NOT_FOUND: + die("Can't create data directory '%s' " + "(one or more intermediate directories do not exist)\n", + opt_datadir); + break; + default: + die("Can't create data directory '%s', last error %u\n", + opt_datadir, last_error); + break; + } + } if (!SetCurrentDirectory(opt_datadir)) { - die("Cannot set current directory to '%s'\n",opt_datadir); - return -1; + last_error = GetLastError(); + switch (last_error) + { + case ERROR_DIRECTORY: + die("Can't set current directory to '%s', the path is not a valid directory \n", + opt_datadir); + break; + default: + die("Can' set current directory to '%s', last error %u\n", + opt_datadir, last_error); + break; + } } - CreateDirectory("mysql",NULL); - CreateDirectory("test", NULL); + if (PathIsDirectoryEmpty(opt_datadir)) + { + cleanup_datadir= false; + } + + if (!CreateDirectory("mysql",NULL)) + { + last_error = GetLastError(); + DWORD attributes; + switch(last_error) + { + case ERROR_ACCESS_DENIED: + die("Can't create subdirectory 'mysql' in '%s' (access denied)\n",opt_datadir); + break; + case ERROR_ALREADY_EXISTS: + attributes = GetFileAttributes("mysql"); + + if (attributes == INVALID_FILE_ATTRIBUTES) + die("GetFileAttributes() failed for existing file '%s\\mysql', last error %u", + opt_datadir, GetLastError()); + else if (!(attributes & FILE_ATTRIBUTE_DIRECTORY)) + die("File '%s\\mysql' exists, but it is not a directory", opt_datadir); + + break; + } + } /* Set data directory permissions for both current user and @@ -642,7 +702,7 @@ static int create_db_instance() } end: - if (ret) + if (ret && cleanup_datadir) { SetCurrentDirectory(cwd); clean_directory(opt_datadir); From 235374aee3c4b08d34026c2bcd7d88db515966cb Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 15 Jan 2019 18:44:03 +0100 Subject: [PATCH 02/15] MDEV-18254 upgrade HeidiSQL to 9.5 --- win/packaging/heidisql.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win/packaging/heidisql.cmake b/win/packaging/heidisql.cmake index 772834e7c7d..29ecdd8eb4f 100644 --- a/win/packaging/heidisql.cmake +++ b/win/packaging/heidisql.cmake @@ -1,4 +1,4 @@ -SET(HEIDISQL_BASE_NAME "HeidiSQL_9.4_Portable") +SET(HEIDISQL_BASE_NAME "HeidiSQL_9.5_Portable") SET(HEIDISQL_ZIP "${HEIDISQL_BASE_NAME}.zip") SET(HEIDISQL_URL "http://www.heidisql.com/downloads/releases/${HEIDISQL_ZIP}") SET(HEIDISQL_DOWNLOAD_DIR ${THIRD_PARTY_DOWNLOAD_LOCATION}/${HEIDISQL_BASE_NAME}) From 1ecccb509c9dfa57976a2e2c3af07753a5356188 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Wed, 16 Jan 2019 13:16:41 +0100 Subject: [PATCH 03/15] MDEV-17085: CHECKSUM TABLE EXTENDED does not work correctly The problem was in calculating of the mask to clear unused null bits in case of using full byte. --- mysql-test/r/row-checksum-old.result | 16 ++++++++++++++++ mysql-test/r/row-checksum.result | 16 ++++++++++++++++ mysql-test/t/row-checksum.test | 17 +++++++++++++++++ sql/sql_table.cc | 5 ++++- 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/row-checksum-old.result b/mysql-test/r/row-checksum-old.result index ef523463860..920c5dbe838 100644 --- a/mysql-test/r/row-checksum-old.result +++ b/mysql-test/r/row-checksum-old.result @@ -85,3 +85,19 @@ checksum table t1 extended; Table Checksum test.t1 4108368782 drop table t1; +# +# MDEV-17085: CHECKSUM TABLE EXTENDED does not work correctly +# +CREATE TABLE t1 ( c1 int NOT NULL, c2 int NOT NULL, c4 varchar(20), c5 varchar(20), c6 varchar(20), c7 varchar(20), c8 varchar(20), c9 varchar(20), c10 varchar(20), c11 varchar(20), c12 varchar(20), c13 varchar(20), c14 varchar(20), c15 varchar(20), c16 varchar(20), c19 int NOT NULL, c20 int NOT NULL, c21 varchar(20), c22 VARCHAR(20), c23 varchar(20)); +insert into t1 values (5,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,0,"dog",NULL,NULL); +# Important is that checksum is different from following +CHECKSUM TABLE t1 EXTENDED; +Table Checksum +test.t1 2514025256 +UPDATE t1 SET c21='cat' WHERE c1=5; +# Important is that checksum is different from above +CHECKSUM TABLE t1 EXTENDED; +Table Checksum +test.t1 2326430205 +drop table t1; +# End of 5.5 tests diff --git a/mysql-test/r/row-checksum.result b/mysql-test/r/row-checksum.result index fb8a1260a1d..0f8311b703a 100644 --- a/mysql-test/r/row-checksum.result +++ b/mysql-test/r/row-checksum.result @@ -85,3 +85,19 @@ checksum table t1 extended; Table Checksum test.t1 3885665021 drop table t1; +# +# MDEV-17085: CHECKSUM TABLE EXTENDED does not work correctly +# +CREATE TABLE t1 ( c1 int NOT NULL, c2 int NOT NULL, c4 varchar(20), c5 varchar(20), c6 varchar(20), c7 varchar(20), c8 varchar(20), c9 varchar(20), c10 varchar(20), c11 varchar(20), c12 varchar(20), c13 varchar(20), c14 varchar(20), c15 varchar(20), c16 varchar(20), c19 int NOT NULL, c20 int NOT NULL, c21 varchar(20), c22 VARCHAR(20), c23 varchar(20)); +insert into t1 values (5,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,0,"dog",NULL,NULL); +# Important is that checksum is different from following +CHECKSUM TABLE t1 EXTENDED; +Table Checksum +test.t1 2514025256 +UPDATE t1 SET c21='cat' WHERE c1=5; +# Important is that checksum is different from above +CHECKSUM TABLE t1 EXTENDED; +Table Checksum +test.t1 2326430205 +drop table t1; +# End of 5.5 tests diff --git a/mysql-test/t/row-checksum.test b/mysql-test/t/row-checksum.test index 920a2384aa8..6b79827d066 100644 --- a/mysql-test/t/row-checksum.test +++ b/mysql-test/t/row-checksum.test @@ -60,3 +60,20 @@ checksum table t1; checksum table t1 quick; checksum table t1 extended; drop table t1; + +--echo # +--echo # MDEV-17085: CHECKSUM TABLE EXTENDED does not work correctly +--echo # + +CREATE TABLE t1 ( c1 int NOT NULL, c2 int NOT NULL, c4 varchar(20), c5 varchar(20), c6 varchar(20), c7 varchar(20), c8 varchar(20), c9 varchar(20), c10 varchar(20), c11 varchar(20), c12 varchar(20), c13 varchar(20), c14 varchar(20), c15 varchar(20), c16 varchar(20), c19 int NOT NULL, c20 int NOT NULL, c21 varchar(20), c22 VARCHAR(20), c23 varchar(20)); + +insert into t1 values (5,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,0,"dog",NULL,NULL); +--echo # Important is that checksum is different from following +CHECKSUM TABLE t1 EXTENDED; +UPDATE t1 SET c21='cat' WHERE c1=5; +--echo # Important is that checksum is different from above +CHECKSUM TABLE t1 EXTENDED; + +drop table t1; + +--echo # End of 5.5 tests diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 1b83b513c2d..d3448c167c4 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -7844,7 +7844,10 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, { /* calculating table's checksum */ ha_checksum crc= 0; - uchar null_mask=256 - (1 << t->s->last_null_bit_pos); + DBUG_ASSERT(t->s->last_null_bit_pos < 8); + uchar null_mask= (t->s->last_null_bit_pos ? + (256 - (1 << t->s->last_null_bit_pos)): + 0); t->use_all_columns(); From 459d6da86955c89e96f6e9a8d3bc2a9b1756629b Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 16 Jan 2019 14:28:37 +0000 Subject: [PATCH 04/15] MDEV-18269 - fix off-by-one bug in unittest Fix the off-by-one overflow which was introduced with commit b0fd06a6f2721 (MDEV-15670 - unit.my_atomic failed in buildbot with Signal 11 thrown) Closes #1098. --- unittest/mysys/thr_template.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittest/mysys/thr_template.c b/unittest/mysys/thr_template.c index d1bc0868ca0..0e06bf6e731 100644 --- a/unittest/mysys/thr_template.c +++ b/unittest/mysys/thr_template.c @@ -34,7 +34,7 @@ void test_concurrently(const char *test, pthread_handler handler, int n, int m) bad= 0; diag("Testing %s with %d threads, %d iterations... ", test, n, m); - for (i= n; i; i--) + for (i= 0; i < n; i++) { if (pthread_create(&threads[i], 0, handler, &m) != 0) { @@ -43,7 +43,7 @@ void test_concurrently(const char *test, pthread_handler handler, int n, int m) } } - for (i= n; i; i--) + for (i= 0; i < n; i++) pthread_join(threads[i], 0); now= my_interval_timer() - now; From 78f62e9079b6ad3705bb2abb7b48b31143297e86 Mon Sep 17 00:00:00 2001 From: Alexander Kuleshov Date: Fri, 4 Jan 2019 13:32:51 +0600 Subject: [PATCH 05/15] remove duplicated paragraph from mysql_install_db.sh Signed-off-by: Alexander Kuleshov --- scripts/mysql_install_db.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/mysql_install_db.sh b/scripts/mysql_install_db.sh index 0272a19931f..f56de12d931 100644 --- a/scripts/mysql_install_db.sh +++ b/scripts/mysql_install_db.sh @@ -207,9 +207,6 @@ cannot_find_file() done fi - echo - echo "If you compiled from source, you need to run 'make install' to" - echo "copy the software into the correct location ready for operation." echo echo "If you compiled from source, you need to either run 'make install' to" echo "copy the software into the correct location ready for operation." From e292d1a800312f4e0330a519e0d980e27a7172f3 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Sat, 19 Jan 2019 14:01:09 +0100 Subject: [PATCH 06/15] Avoid noisy Clang 7 warning about unused variable. Patch by Eugene Kosov. --- include/my_valgrind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/my_valgrind.h b/include/my_valgrind.h index 5d08a271d4a..a85e610f049 100644 --- a/include/my_valgrind.h +++ b/include/my_valgrind.h @@ -42,7 +42,7 @@ https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning */ # define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0) # define MEM_CHECK_DEFINED(a,len) ((void) 0) #else -# define MEM_UNDEFINED(a,len) ((void) 0) +# define MEM_UNDEFINED(a,len) ((void) (a), (void) (len)) # define MEM_NOACCESS(a,len) ((void) 0) # define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0) # define MEM_CHECK_DEFINED(a,len) ((void) 0) @@ -51,7 +51,7 @@ https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning */ #ifndef DBUG_OFF #define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); MEM_UNDEFINED(A, trash_tmp); memset(A, C, trash_tmp); } while (0) #else -#define TRASH_FILL(A,B,C) do { const size_t trash_tmp __attribute__((unused))= (B); MEM_UNDEFINED(A,trash_tmp); } while (0) +#define TRASH_FILL(A,B,C) do { MEM_UNDEFINED((A), (B)); } while (0) #endif #define TRASH_ALLOC(A,B) do { TRASH_FILL(A,B,0xA5); MEM_UNDEFINED(A,B); } while(0) #define TRASH_FREE(A,B) do { TRASH_FILL(A,B,0x8F); MEM_NOACCESS(A,B); } while(0) From 0d3c49ef5de3fa7356851dd7a05052f5360d0ae6 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 14 Jan 2019 12:33:52 +0100 Subject: [PATCH 07/15] MDEV-17615 cmake ssl error on musl/libressl don't shortcut trying to test for openssl version, test what is actually needed for a code to compile --- cmake/ssl.cmake | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmake/ssl.cmake b/cmake/ssl.cmake index 0c6cde31299..60d2cb48387 100644 --- a/cmake/ssl.cmake +++ b/cmake/ssl.cmake @@ -71,15 +71,23 @@ MACRO (MYSQL_CHECK_SSL) FIND_LIBRARY(CRYPTO_LIBRARY crypto) MARK_AS_ADVANCED(CRYPTO_LIBRARY) INCLUDE(CheckSymbolExists) + INCLUDE(CheckCSourceCompiles) SET(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) SET(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES}) CHECK_SYMBOL_EXISTS(SHA512_DIGEST_LENGTH "openssl/sha.h" HAVE_SHA512_DIGEST_LENGTH) CHECK_SYMBOL_EXISTS(ERR_remove_thread_state "openssl/err.h" HAVE_ERR_remove_thread_state) + CHECK_C_SOURCE_COMPILES(" + #include + int main() + { + DH dh; + return sizeof(dh.version); + }" OLD_OPENSSL_API) SET(CMAKE_REQUIRED_INCLUDES) SET(CMAKE_REQUIRED_LIBRARIES) - IF(OPENSSL_FOUND AND OPENSSL_VERSION VERSION_LESS "1.1.0" AND + IF(OPENSSL_FOUND AND OLD_OPENSSL_API AND CRYPTO_LIBRARY AND HAVE_SHA512_DIGEST_LENGTH) SET(SSL_SOURCES "") SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES} ${CRYPTO_LIBRARY}) From 50e593386fcbaa1ca7bd2ed9fdfc51fd5102cdab Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 11 Jan 2019 19:35:46 +1100 Subject: [PATCH 08/15] MDEV-14580: mysql_install_db elements based on dirname of mysql_install_db Closes #1086 --- scripts/mysql_install_db.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/mysql_install_db.sh b/scripts/mysql_install_db.sh index f56de12d931..f1249e1d06b 100644 --- a/scripts/mysql_install_db.sh +++ b/scripts/mysql_install_db.sh @@ -253,6 +253,9 @@ then cannot_find_file my_print_defaults $basedir/bin $basedir/extra exit 1 fi +elif test -x "$(dirname $0)/../@bindir@/my_print_defaults" +then + print_defaults="$(dirname $0)/../@bindir@/my_print_defaults" else print_defaults="@bindir@/my_print_defaults" fi @@ -304,6 +307,14 @@ then cannot_find_file fill_help_tables.sql @pkgdata_locations@ exit 1 fi +# relative from where the script was run for a relocatable install +elif test -x "$(dirname $0)/../@INSTALL_SBINDIR@/mysqld" +then + basedir="$(dirname $0)/../" + bindir="$basedir/@INSTALL_SBINDIR@" + resolveip="$bindir/resolveip" + mysqld="$basedir/@INSTALL_SBINDIR@/mysqld" + pkgdatadir="$basedir/@INSTALL_MYSQLSHAREDIR@" else basedir="@prefix@" bindir="@bindir@" From 9c5be7d131f7eb7f27df722463faa2cd8135fd1b Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 14 Jan 2019 15:55:21 +0100 Subject: [PATCH 09/15] MDEV-14580: mysql_install_db elements based on dirname of mysql_install_db Avoid introducing new dependencies or new syntax. That is, don't use $(...) and don't assume dirname is present. And remove unsighty /foo/bar/../xyz from the path. Use dirname instead of ../ --- scripts/mysql_install_db.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/mysql_install_db.sh b/scripts/mysql_install_db.sh index f1249e1d06b..9f00562f4bd 100644 --- a/scripts/mysql_install_db.sh +++ b/scripts/mysql_install_db.sh @@ -36,6 +36,9 @@ in_rpm=0 ip_only=0 cross_bootstrap=0 +dirname0=`dirname $0 2>/dev/null` +dirname0=`dirname $dirname0 2>/dev/null` + usage() { cat < Date: Wed, 23 Jan 2019 09:51:06 +0200 Subject: [PATCH 10/15] MDEV-18349 InnoDB file size changes are not safe when file system crashes fil_extend_space_to_desired_size(): Invoke fsync() after posix_fallocate() in order to durably extend the file in a crash-safe file system. --- storage/innobase/fil/fil0fil.c | 4 +++- storage/xtradb/fil/fil0fil.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/storage/innobase/fil/fil0fil.c b/storage/innobase/fil/fil0fil.c index 4006ce4acce..32bf0b8ccd8 100644 --- a/storage/innobase/fil/fil0fil.c +++ b/storage/innobase/fil/fil0fil.c @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2014, 2017, MariaDB Corporation. All Rights Reserved. +Copyright (c) 2014, 2019, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -4155,6 +4155,8 @@ fil_extend_space_to_desired_size( " failed with error %d\n", node->name, start_offset, len + start_offset, err); + } else { + os_file_flush(node->handle); } mutex_enter(&fil_system->mutex); diff --git a/storage/xtradb/fil/fil0fil.c b/storage/xtradb/fil/fil0fil.c index 004a80e9b13..fc305c7e01f 100644 --- a/storage/xtradb/fil/fil0fil.c +++ b/storage/xtradb/fil/fil0fil.c @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2014, 2017, MariaDB Corporation. All Rights Reserved. +Copyright (c) 2014, 2019, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -4990,6 +4990,8 @@ fil_extend_space_to_desired_size( " failed with error %d\n", node->name, start_offset, len + start_offset, err); + } else { + os_file_flush(node->handle, TRUE); } mutex_enter(&fil_system->mutex); From 6de2928d5bf912ace5fb5a1e2254025efe202b67 Mon Sep 17 00:00:00 2001 From: Aditya A Date: Mon, 10 Sep 2018 16:00:29 +0530 Subject: [PATCH 11/15] Bug #28178776 COMPARISON OF UNINITAILIZED MEMORY IN LOG_IN_USE PROBLEM ------- Memory sanitizer reports uninitialized comparisons in log_in_use(), because strings are compared with memcmp() instead of strncmp. FIX --- Use strncmp() to compare strings --- sql/log.cc | 6 +++--- sql/sql_repl.cc | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sql/log.cc b/sql/log.cc index 2504b5e2d06..7db4985ad48 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1,5 +1,5 @@ -/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. - Copyright (c) 2009, 2016, MariaDB +/* Copyright (c) 2000, 2018, Oracle and/or its affiliates. + Copyright (c) 2009, 2019, MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -3413,7 +3413,7 @@ int MYSQL_BIN_LOG::find_log_pos(LOG_INFO *linfo, const char *log_name, // if the log entry matches, null string matching anything if (!log_name || (log_name_len == fname_len-1 && full_fname[log_name_len] == '\n' && - !memcmp(full_fname, full_log_name, log_name_len))) + !strncmp(full_fname, full_log_name, log_name_len))) { DBUG_PRINT("info", ("Found log file entry")); full_fname[fname_len-1]= 0; // remove last \n diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index ca6e8d15e7a..cb4904bb5a6 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1,5 +1,5 @@ -/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. - Copyright (c) 2008, 2017, MariaDB Corporation +/* Copyright (c) 2000, 2018, Oracle and/or its affiliates. + Copyright (c) 2008, 2019, MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -365,7 +365,7 @@ bool log_in_use(const char* log_name) if ((linfo = tmp->current_linfo)) { mysql_mutex_lock(&linfo->lock); - result = !memcmp(log_name, linfo->log_file_name, log_name_len); + result = !strncmp(log_name, linfo->log_file_name, log_name_len); mysql_mutex_unlock(&linfo->lock); if (result) break; From b20d94da356fa274a49ac38497e0cb20ce760d93 Mon Sep 17 00:00:00 2001 From: Sreeharsha Ramanavarapu Date: Tue, 9 Oct 2018 12:03:35 +0530 Subject: [PATCH 12/15] Bug #28499924: INCORRECT BEHAVIOR WITH UNION IN SUBQUERY Issue: ------ When a subquery contains UNION the count of the number of subquery columns is calculated incorrectly. Only the first query block in the subquery's UNION is considered and an array indexing goes out-of-bounds, and this is caught by an assert. Solution: --------- Sum up the columns from all query blocks of the query expression. Change specific to 5.6/5.5: --------------------------- The "child" points to the last query block of the UNION (as opposed to 5.7+ where it points to the first member of UNION). So "child->master_unit()->first_select()" is used to reach the first query block of UNION. --- sql/sql_yacc.yy | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 34f7c6e3481..ba0041cf477 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -14627,19 +14627,21 @@ subselect_end: lex->current_select = lex->current_select->return_after_parsing(); lex->nest_level--; lex->current_select->n_child_sum_items += child->n_sum_items; - /* - A subselect can add fields to an outer select. Reserve space for - them. - */ - lex->current_select->select_n_where_fields+= - child->select_n_where_fields; /* - Aggregate functions in having clause may add fields to an outer - select. Count them also. + A subquery (and all the subsequent query blocks in a UNION) can + add columns to an outer query block. Reserve space for them. + Aggregate functions in having clause can also add fields to an + outer select. */ - lex->current_select->select_n_having_items+= - child->select_n_having_items; + for (SELECT_LEX *temp= child->master_unit()->first_select(); + temp != NULL; temp= temp->next_select()) + { + lex->current_select->select_n_where_fields+= + temp->select_n_where_fields; + lex->current_select->select_n_having_items+= + temp->select_n_having_items; + } } ; From a8da66f8c56211417289b0e40a10faf49e225a54 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 22 Jan 2019 00:15:57 +0100 Subject: [PATCH 13/15] Bug #28499924: INCORRECT BEHAVIOR WITH UNION IN SUBQUERY test case --- mysql-test/r/subselect2.result | 22 ++++++++++++++++++++++ mysql-test/t/subselect2.test | 20 ++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/mysql-test/r/subselect2.result b/mysql-test/r/subselect2.result index 64bd86707cc..8d555aa798b 100644 --- a/mysql-test/r/subselect2.result +++ b/mysql-test/r/subselect2.result @@ -394,3 +394,25 @@ select null in (select a from t1 where a < out3.a union select a from t2 where (select a from t3) +1 < out3.a+1) from t3 out3; ERROR 21000: Subquery returns more than 1 row drop table t1, t2, t3; +CREATE TABLE t1( +q11 int, q12 int, q13 int, q14 int, q15 int, q16 int, q17 int, q18 int, q19 int, +q21 int, q22 int, q23 int, q24 int, q25 int, q26 int, q27 int, q28 int, q29 int, +f1 int +); +CREATE TABLE t2(f2 int, f21 int, f3 timestamp, f4 int, f5 int, f6 int); +INSERT INTO t1 (f1) VALUES (1),(1),(2),(2); +INSERT INTO t2 VALUES (1,1,"2004-02-29 11:11:11",0,0,0), (2,2,"2004-02-29 11:11:11",0,0,0); +SELECT f1, +(SELECT t.f21 from t2 t where max( +q11+q12+q13+q14+q15+q16+q17+q18+q19+ +q21+q22+q23+q24+q25+q26+q27+q28+q29) = t.f2 UNION +SELECT t.f3 FROM t2 AS t WHERE t1.f1=t.f2 AND t.f3=MAX(t1.f1) UNION +SELECT 1 LIMIT 1) AS test +FROM t1 GROUP BY f1; +f1 test +1 1 +2 1 +Warnings: +Warning 1292 Incorrect datetime value: '1' +Warning 1292 Incorrect datetime value: '2' +DROP TABLE t1,t2; diff --git a/mysql-test/t/subselect2.test b/mysql-test/t/subselect2.test index ae210b865a2..73b0e77ade6 100644 --- a/mysql-test/t/subselect2.test +++ b/mysql-test/t/subselect2.test @@ -411,3 +411,23 @@ insert into t3 select a from t1; select null in (select a from t1 where a < out3.a union select a from t2 where (select a from t3) +1 < out3.a+1) from t3 out3; drop table t1, t2, t3; + +# +# Bug #28499924: INCORRECT BEHAVIOR WITH UNION IN SUBQUERY +# +CREATE TABLE t1( + q11 int, q12 int, q13 int, q14 int, q15 int, q16 int, q17 int, q18 int, q19 int, + q21 int, q22 int, q23 int, q24 int, q25 int, q26 int, q27 int, q28 int, q29 int, + f1 int +); +CREATE TABLE t2(f2 int, f21 int, f3 timestamp, f4 int, f5 int, f6 int); +INSERT INTO t1 (f1) VALUES (1),(1),(2),(2); +INSERT INTO t2 VALUES (1,1,"2004-02-29 11:11:11",0,0,0), (2,2,"2004-02-29 11:11:11",0,0,0); +SELECT f1, + (SELECT t.f21 from t2 t where max( + q11+q12+q13+q14+q15+q16+q17+q18+q19+ + q21+q22+q23+q24+q25+q26+q27+q28+q29) = t.f2 UNION + SELECT t.f3 FROM t2 AS t WHERE t1.f1=t.f2 AND t.f3=MAX(t1.f1) UNION + SELECT 1 LIMIT 1) AS test + FROM t1 GROUP BY f1; +DROP TABLE t1,t2; From 949559285efff44ba49b478ee766e0fe0a5a9b79 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 23 Jan 2019 10:09:49 +0100 Subject: [PATCH 14/15] MDEV-18059 `support-files/mysql.server.sh stop` must run as root don't run `su - mysql` is $USER is already mysql --- support-files/mysql.server.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/support-files/mysql.server.sh b/support-files/mysql.server.sh index c1d85ba2664..f3990967b87 100644 --- a/support-files/mysql.server.sh +++ b/support-files/mysql.server.sh @@ -187,7 +187,11 @@ fi user='@MYSQLD_USER@' su_kill() { - su - $user -s /bin/sh -c "kill $*" >/dev/null 2>&1 + if test "$USER" = "$user"; then + kill $* >/dev/null 2>&1 + else + su - $user -s /bin/sh -c "kill $*" >/dev/null 2>&1 + fi } # From ad220b96fb01dbb6acf7e51bdd8d4d6362d96ea7 Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Mon, 2 Jul 2018 12:26:22 +0300 Subject: [PATCH 15/15] MDEV-16658 Memory leak in mysqltest on connect failure Close connection handler on connection failure. This fixes 14 failing tests in main suite under clang+ASAN build. ASAN report for main.connect looks like this: ================================================================= ==25495==ERROR: LeakSanitizer: detected memory leaks Direct leak of 146280 byte(s) in 115 object(s) allocated from: #0 0x4fba47 in calloc /fun/cpp_projects/llvm_toolchain/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:138 #1 0x5a7a02 in mysql_init /work/mariadb/libmariadb/libmariadb/mariadb_lib.c:977:26 #2 0x570a7a in do_connect(st_command*) /work/mariadb/client/mysqltest.cc:6096:26 #3 0x584c39 in main /work/mariadb/client/mysqltest.cc:9321:9 #4 0x7fd15514db96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310 Indirect leak of 7065600 byte(s) in 115 object(s) allocated from: #0 0x4fb80f in __interceptor_malloc /fun/cpp_projects/llvm_toolchain/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:129 #1 0x637a83 in my_context_init /work/mariadb/libmariadb/libmariadb/ma_context.c:367:23 #2 0x59fd16 in mysql_optionsv /work/mariadb/libmariadb/libmariadb/mariadb_lib.c:2738:9 #3 0x5bc1d4 in mysql_options /work/mariadb/libmariadb/libmariadb/mariadb_lib.c:3242:10 #4 0x570b94 in do_connect(st_command*) /work/mariadb/client/mysqltest.cc:6103:7 #5 0x584c39 in main /work/mariadb/client/mysqltest.cc:9321:9 #6 0x7fd15514db96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310 Indirect leak of 940240 byte(s) in 115 object(s) allocated from: #0 0x4fb80f in __interceptor_malloc /fun/cpp_projects/llvm_toolchain/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:129 #1 0x64386e in ma_init_dynamic_array /work/mariadb/libmariadb/libmariadb/ma_array.c:49:31 #2 0x649ead in _hash_init /work/mariadb/libmariadb/libmariadb/ma_hash.c:52:7 #3 0x5a3080 in mysql_optionsv /work/mariadb/libmariadb/libmariadb/mariadb_lib.c:2938:13 #4 0x5bc20c in mysql_options4 /work/mariadb/libmariadb/libmariadb/mariadb_lib.c:3248:10 #5 0x56f63b in connect_n_handle_errors(st_command*, st_mysql*, char const*, char const*, char const*, char const*, int, char const*) /work/mariadb/client/mysqltest.cc:5874:3 #6 0x57146b in do_connect(st_command*) /work/mariadb/client/mysqltest.cc:6193:7 #7 0x584c39 in main /work/mariadb/client/mysqltest.cc:9321:9 #8 0x7fd15514db96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310 ... Closes #809 --- client/mysqltest.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 088afed41b2..2b7401878ef 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -6129,6 +6129,11 @@ void do_connect(struct st_command *command) if (con_slot == next_con) next_con++; /* if we used the next_con slot, advance the pointer */ } + else // Failed to connect. Free the memory. + { + mysql_close(con_slot->mysql); + con_slot->mysql= NULL; + } dynstr_free(&ds_connection_name); dynstr_free(&ds_host);