Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDEV-16478: mysql_real_connect() from libmariadbd.so always crash
Returned accidentally removed undefinition of MYSQL_SERVER in net_serv.cc inside embedded server (embedded server uses real_net_read/write only as a client) Prevented attempt to clean up embedded server if it was not initialized
- Loading branch information
1 parent
88aaf59
commit 46fc864
Showing
5 changed files
with
118 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include | ||
${CMAKE_SOURCE_DIR}/libmysqld/include | ||
${PCRE_INCLUDES} | ||
${CMAKE_SOURCE_DIR}/sql | ||
${MY_READLINE_INCLUDE_DIR} | ||
) | ||
|
||
|
||
ADD_DEFINITIONS(-DEMBEDDED_LIBRARY -UMYSQL_CLIENT) | ||
|
||
|
||
MYSQL_ADD_EXECUTABLE(test-connect-t test-connect.cc | ||
COMPONENT Test) | ||
TARGET_LINK_LIBRARIES(test-connect-t mysqlserver ) | ||
MY_ADD_TEST(test-connect) | ||
|
||
IF(UNIX) | ||
SET_TARGET_PROPERTIES(test-connect-t PROPERTIES ENABLE_EXPORTS TRUE) | ||
ENDIF() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include <mysql.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
int get_evar(char **hostname, char **port, char** username, char ** password) | ||
{ | ||
|
||
if (!((*hostname)= getenv("MYSQL_TEST_HOST"))) | ||
(*hostname)= (char *)"127.0.0.1"; | ||
|
||
if (!((*port)= getenv("MASTER_MYPORT"))) | ||
{ | ||
if (!((*port)= getenv("MYSQL_TEST_PORT"))) | ||
return 1; | ||
} | ||
|
||
if (!((*username)= getenv("MYSQL_TEST_USER"))) | ||
(*username)= (char *)"root"; | ||
|
||
if (!((*password)= getenv("MYSQL_TEST_PASSWD"))) | ||
(*password)= (char *)""; | ||
|
||
return 0; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
MYSQL *mysql; | ||
char *host; | ||
char *user; | ||
char *passwd; | ||
char *porta; | ||
unsigned int port; | ||
|
||
if (get_evar(&host, &porta, &user, &passwd)) | ||
{ | ||
printf("set environment variable MASTER_MYPORT\n"); | ||
return 1; | ||
} | ||
|
||
port = atoi(porta); | ||
|
||
mysql_thread_init(); | ||
|
||
if (mysql_server_init(-1, NULL, NULL) != 0) { | ||
printf("mysql_library_init failed"); | ||
return 1; | ||
} | ||
|
||
|
||
mysql = mysql_init(NULL); | ||
|
||
if (!mysql) { | ||
printf("mysql_init failed"); | ||
return 1; | ||
} | ||
|
||
if (mysql_options(mysql, MYSQL_OPT_USE_REMOTE_CONNECTION, NULL) != 0) { | ||
printf("mysql_options MYSQL_OPT_USE_REMOTE_CONNECTION failed: %s\n", mysql_error(mysql)); | ||
return 1; | ||
} | ||
|
||
if (mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "utf8mb4") != 0) { | ||
printf("mysql_options MYSQL_SET_CHARSET_NAME utf8mb4 failed: %s\n", mysql_error(mysql)); | ||
return 1; | ||
} | ||
|
||
if (!mysql_real_connect(mysql, host, user, passwd, NULL, port, NULL, CLIENT_FOUND_ROWS | CLIENT_MULTI_RESULTS | CLIENT_REMEMBER_OPTIONS)) { | ||
printf("mysql_real_connect failed: %s\n", mysql_error(mysql)); | ||
return 1; | ||
} | ||
mysql_close(mysql); | ||
mysql_thread_end(); | ||
mysql_library_end(); | ||
|
||
return 0; | ||
|
||
} |