Skip to content

Commit d374707

Browse files
authored
Merge pull request #3600 from sysown/v2.2.1-3599
Closes #3599: Backport bugfixes to v2.2.1 - 3
2 parents 478ef63 + 92d2f49 commit d374707

File tree

18 files changed

+524
-28
lines changed

18 files changed

+524
-28
lines changed

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ $(error GIT_VERSION is not set)
55
endif
66
endif
77

8+
### NOTES:
9+
### to compile without jemalloc, set environment variable NOJEMALLOC=1
10+
### to compile with ASAN, set environment variables NOJEMALLOC=1, WITHASAN=1:
11+
### * To perform a full ProxySQL build with ASAN then execute:
12+
###
13+
### ```
14+
### make build_deps_debug -j$(nproc) && make debug -j$(nproc) && make build_tap_test_debug -j$(nproc)
15+
### ```
16+
817
O0=-O0
918
O2=-O2
1019
O1=-O1
@@ -129,6 +138,10 @@ build_lib_testall: build_deps_debug
129138
build_tap_test: build_src
130139
cd test/tap && OPTZ="${O0} -ggdb -DDEBUG" CC=${CC} CXX=${CXX} ${MAKE}
131140

141+
.PHONY: build_tap_test_debug
142+
build_tap_test_debug: build_src
143+
cd test/tap && OPTZ="${O0} -ggdb -DDEBUG" CC=${CC} CXX=${CXX} ${MAKE} debug
144+
132145
.PHONY: build_src_debug
133146
build_src_debug: build_deps build_lib_debug
134147
cd src && OPTZ="${O0} -ggdb -DDEBUG" CC=${CC} CXX=${CXX} ${MAKE}

deps/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ jemalloc/jemalloc/lib/libjemalloc.a:
164164

165165
jemalloc: jemalloc/jemalloc/lib/libjemalloc.a
166166

167+
WITHASAN := $(shell echo $(WITHASAN))
167168

168169
mariadb-client-library/mariadb_client/libmariadb/libmariadbclient.a: libssl/openssl/libssl.a
169170
cd mariadb-client-library && rm -rf mariadb-connector-c-3.1.9-src
@@ -188,6 +189,9 @@ mariadb-client-library/mariadb_client/libmariadb/libmariadbclient.a: libssl/open
188189
cd mariadb-client-library/mariadb_client && patch -p0 < ../client_deprecate_eof.patch
189190
cd mariadb-client-library/mariadb_client && patch -p0 < ../cr_new_stmt_metadata_removal.patch
190191
cd mariadb-client-library/mariadb_client && patch -p0 < ../ps_buffer_stmt_read_all_rows.patch
192+
ifeq ($(WITHASAN),1)
193+
cd mariadb-client-library/mariadb_client && patch -p0 < ../mariadb_asan.patch
194+
endif
191195
cd mariadb-client-library/mariadb_client && CC=${CC} CXX=${CXX} ${MAKE} mariadbclient
192196
# cd mariadb-client-library/mariadb_client/include && make my_config.h
193197

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git CMakeLists.txt CMakeLists.txt
2+
index 568e4f5..cfac85b 100644
3+
--- CMakeLists.txt
4+
+++ CMakeLists.txt
5+
@@ -136,6 +136,10 @@ SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DDBUG_OFF")
6+
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DDBUG_OFF")
7+
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DDBUG_OFF")
8+
9+
+SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
10+
+SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
11+
+SET(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
12+
+
13+
IF(CMAKE_COMPILER_IS_GNUCC)
14+
INCLUDE(CheckCCompilerFlag)
15+
SET(GCC_FLAGS -Wunused -Wlogical-op -Wno-uninitialized -Wall -Wextra -Wformat-security -Wno-init-self -Wwrite-strings -Wshift-count-overflow -Wdeclaration-after-statement -Wno-undef -Wno-unknown-pragmas)

docker/images/proxysql/deb-compliant/entrypoint/entrypoint.bash

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ ARCH=$PROXYSQL_BUILD_ARCH
77

88
echo "==> $ARCH architecture detected for package"
99

10-
# Dirty patch to ensure OS deps are installed:
11-
apt-get update
12-
apt-get -y install gnutls-dev || true
13-
apt-get -y install libgnutls28-dev || true
14-
apt-get -y install libtool || true
15-
1610
# Delete package if exists
1711
rm -f "/opt/proxysql/binaries/proxysql_${CURVER}-${PKG_RELEASE}_$ARCH.deb" || true
1812
# Cleanup relic directories from a previously failed build

docker/images/proxysql/rhel-compliant/entrypoint/entrypoint.bash

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@ env
77
ARCH=$PROXYSQL_BUILD_ARCH
88
echo "==> $ARCH architecture detected for package"
99

10-
echo "==> Dirty patching to ensure OS deps are installed"
11-
12-
if [[ -f "/usr/bin/python" ]] || [[ -h "/usr/bin/python" ]];
13-
then
14-
echo "==> Installing dependancies for RHEL compliant version 7"
15-
yum -y install gnutls-devel libtool || true
16-
else
17-
echo "==> Installing dependancies for RHEL compliant version 8"
18-
yum -y install python2 gnutls-devel libtool || true
19-
ln -s /usr/bin/python2.7 /usr/bin/python || true
20-
fi
21-
2210
echo "==> Cleaning"
2311
# Delete package if exists
2412
rm -f /opt/proxysql/binaries/proxysql-${CURVER}-1-${PKG_RELEASE}.$ARCH.rpm || true

lib/Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ ODIR= obj
6767
#CXX=g++
6868
#CC=clang
6969

70+
WITHASANVAR := $(shell echo $(WITHASAN))
71+
ifeq ($(WITHASANVAR),1)
72+
WASAN=-fsanitize=address
73+
# Force the disable of JEMALLOC, since ASAN isn't compatible.
74+
export NOJEMALLOC = 1
75+
else
76+
WASAN=
77+
endif
78+
7079
#CFLAGS=$(IDIRS) $(OPTZ) $(DEBUG) -Wall #-lcrypto
7180
#CXXFLAGS=-std=c++11 $(CFLAGS) $(LDIRS) $(LIBS)
7281
NOJEMALLOC := $(shell echo $(NOJEMALLOC))
@@ -93,7 +102,7 @@ ifeq ($(UNAME_S),Darwin)
93102
endif
94103

95104

96-
MYCFLAGS=$(IDIRS) $(OPTZ) $(DEBUG) -Wall -DGITVERSION=\"$(GIT_VERSION)\" $(NOJEM)
105+
MYCFLAGS=$(IDIRS) $(OPTZ) $(DEBUG) -Wall -DGITVERSION=\"$(GIT_VERSION)\" $(NOJEM) $(WASAN)
97106
MYCXXFLAGS=-std=c++11 $(MYCFLAGS) $(PSQLCH)
98107

99108
default: libproxysql.a

lib/MySQL_Protocol.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,15 @@ bool MySQL_Protocol::process_pkt_handshake_response(unsigned char *pkt, unsigned
17701770
//Copy4B(&hdr,pkt);
17711771
pkt += sizeof(mysql_hdr);
17721772

1773+
// NOTE: 'mysqlsh' sends a 'COM_INIT_DB' as soon as the connection is openned
1774+
// before ProxySQL has sent 'Server Greeting' messsage. Because this packet is
1775+
// unexpected, we simple return 'false' and exit.
1776+
if (hdr.pkt_id == 0 && *pkt == 2) {
1777+
ret = false;
1778+
proxy_debug(PROXY_DEBUG_MYSQL_AUTH, 5, "Session=%p , DS=%p , user='%s' . Client is disconnecting\n", (*myds), (*myds)->sess, user);
1779+
goto __exit_process_pkt_handshake_response;
1780+
}
1781+
17731782
if ((*myds)->myconn->userinfo->username) {
17741783
(*myds)->switching_auth_stage=2;
17751784
if (len==5) {

lib/MySQL_Session.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4503,6 +4503,14 @@ int MySQL_Session::handler() {
45034503

45044504
handler_rc0_Process_GTID(myconn);
45054505

4506+
// if we are locked on hostgroup, the value of autocommit is copied from the backend connection
4507+
// see bug #3549
4508+
if (locked_on_hostgroup >= 0) {
4509+
assert(myconn != NULL);
4510+
assert(myconn->mysql != NULL);
4511+
autocommit = myconn->mysql->server_status & SERVER_STATUS_AUTOCOMMIT;
4512+
}
4513+
45064514
if (mirror == false) {
45074515
// Support for LAST_INSERT_ID()
45084516
if (myconn->mysql->insert_id) {

lib/ProxySQL_Admin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3292,7 +3292,7 @@ bool ProxySQL_Admin::GenericRefreshStatistics(const char *query_no_space, unsign
32923292
SQLite3_result * ProxySQL_Admin::generate_show_fields_from(const char *tablename, char **err) {
32933293
char *tn=NULL; // tablename
32943294
// note that tablename is passed with a trailing '
3295-
tn=(char *)malloc(strlen(tablename));
3295+
tn=(char *)malloc(strlen(tablename) + 1);
32963296
unsigned int i=0, j=0;
32973297
while (i<strlen(tablename)) {
32983298
if (tablename[i]!='\\' && tablename[i]!='`' && tablename[i]!='\'') {

lib/mysql_connection.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,23 @@ void MySQL_Connection::connect_start() {
730730
mysql->options.client_flag |= CLIENT_DEPRECATE_EOF;
731731
}
732732

733+
if (myds != NULL) {
734+
if (myds->sess != NULL) {
735+
if (myds->sess->session_fast_forward == true) { // this is a fast_forward connection
736+
assert(myds->sess->client_myds != NULL);
737+
MySQL_Connection * c = myds->sess->client_myds->myconn;
738+
assert(c != NULL);
739+
mysql->options.client_flag &= ~(CLIENT_DEPRECATE_EOF); // we disable it by default
740+
// if both client_flag and server_capabilities (used for client) , set CLIENT_DEPRECATE_EOF
741+
if (c->options.client_flag & CLIENT_DEPRECATE_EOF) {
742+
if (c->options.server_capabilities & CLIENT_DEPRECATE_EOF) {
743+
mysql->options.client_flag |= CLIENT_DEPRECATE_EOF;
744+
}
745+
}
746+
}
747+
}
748+
}
749+
733750
char *auth_password=NULL;
734751
if (userinfo->password) {
735752
if (userinfo->password[0]=='*') { // we don't have the real password, let's pass sha1
@@ -2251,7 +2268,11 @@ bool MySQL_Connection::IsKeepMultiplexEnabledVariables(char *query_digest_text)
22512268
}
22522269
while (query_digest_text_filter_select && (match = strcasestr(query_digest_text_filter_select,"@@"))) {
22532270
*match = '\0';
2254-
strcat(query_digest_text_filter_select, match+strlen("@@"));
2271+
if (strlen(query_digest_text_filter_select) == 0) {
2272+
memcpy(query_digest_text_filter_select, match, strlen("@@"));
2273+
} else {
2274+
strcat(query_digest_text_filter_select, match+strlen("@@"));
2275+
}
22552276
}
22562277

22572278
std::vector<char*>query_digest_text_filter_select_v;

0 commit comments

Comments
 (0)