Skip to content

Commit

Permalink
Fix for CONC-297:
Browse files Browse the repository at this point in the history
MariaDB Connector/C was not compatible to libmysql when passing value for MYSQL_OPT_LOCAL_INFILE.
According to the documentatin local infile will be enabled if a NULL pointer was passed or a pointer to an unsigned integer which value is > 0. Connector/C expected a bool pointer, which ends up in wrong results on big endian systems.
  • Loading branch information
9EOR9 committed Dec 4, 2017
1 parent 87b863e commit 434b67e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
4 changes: 2 additions & 2 deletions libmariadb/mariadb_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ struct st_default_options mariadb_defaults[] =
{MYSQL_SET_CHARSET_NAME, MARIADB_OPTION_STR, "default-character-set"},
{MARIADB_OPT_INTERACTIVE, MARIADB_OPTION_NONE, "interactive-timeout"},
{MYSQL_OPT_CONNECT_TIMEOUT, MARIADB_OPTION_INT, "connect-timeout"},
{MYSQL_OPT_LOCAL_INFILE, MARIADB_OPTION_BOOL, "local-infile"},
{MYSQL_OPT_LOCAL_INFILE, MARIADB_OPTION_INT, "local-infile"},
{0, 0 ,"disable-local-infile",},
{MYSQL_OPT_SSL_CIPHER, MARIADB_OPTION_STR, "ssl-cipher"},
{MYSQL_OPT_MAX_ALLOWED_PACKET, MARIADB_OPTION_SIZET, "max-allowed-packet"},
Expand Down Expand Up @@ -2702,7 +2702,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...)
mysql->options.named_pipe=1; /* Force named pipe */
break;
case MYSQL_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/
if (!arg1 || test(*(my_bool*) arg1))
if (!arg1 || test(*(unsigned int*) arg1))
mysql->options.client_flag|= CLIENT_LOCAL_FILES;
else
mysql->options.client_flag&= ~CLIENT_LOCAL_FILES;
Expand Down
53 changes: 50 additions & 3 deletions unittest/libmariadb/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ static int test_get_options(MYSQL *unused __attribute__((unused)))
MYSQL_OPT_PROTOCOL, MYSQL_OPT_READ_TIMEOUT, MYSQL_OPT_WRITE_TIMEOUT, 0};
my_bool options_bool[]= {MYSQL_OPT_RECONNECT, MYSQL_REPORT_DATA_TRUNCATION,
MYSQL_OPT_COMPRESS, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_SECURE_AUTH,
#ifdef _WIN32
#ifdef _WIN32
MYSQL_OPT_NAMED_PIPE,
#endif
0};
Expand Down Expand Up @@ -877,7 +877,7 @@ static int test_get_options(MYSQL *unused __attribute__((unused)))
mysql_options(mysql, options_char[i], char1);
char2= NULL;
mysql_get_optionv(mysql, options_char[i], (void *)&char2);
if (options_char[i] != MYSQL_SET_CHARSET_NAME)
if (options_char[i] != MYSQL_SET_CHARSET_NAME)
FAIL_IF(strcmp(char1, char2), "mysql_get_optionv (char) failed");
}

Expand Down Expand Up @@ -1345,14 +1345,61 @@ static int test_conc277(MYSQL *my __attribute__((unused)))
port, socketname,
CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS);

diag("error: %s", mysql_error(mysql));
FAIL_IF(mysql_errno(mysql), "No error expected");

mysql_close(mysql);
return OK;
}

/* CONC-297: libmysql incompatibility: According to the documentation
load data local infile will be enabled by passing NULL pointer
or a pointer to an unsigned int value */
static int test_conc297(MYSQL *my __attribute__((unused)))
{
MYSQL *mysql;
int local_infile= 0;

mysql= mysql_init(NULL);
mysql_optionsv(mysql, MYSQL_OPT_LOCAL_INFILE, NULL);
my_test_connect(mysql, hostname, username, password, schema,
port, socketname,
CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS);
FAIL_IF(mysql_errno(mysql), "No error expected");

mysql_get_option(mysql, MYSQL_OPT_LOCAL_INFILE, &local_infile);

FAIL_IF(!local_infile, "local infile was not enabled");
mysql_close(mysql);

mysql= mysql_init(NULL);
local_infile= 0;
mysql_optionsv(mysql, MYSQL_OPT_LOCAL_INFILE, &local_infile);
my_test_connect(mysql, hostname, username, password, schema,
port, socketname,
CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS);
FAIL_IF(mysql_errno(mysql), "No error expected");
mysql_get_option(mysql, MYSQL_OPT_LOCAL_INFILE, &local_infile);

FAIL_IF(local_infile, "local infile was not disabled");
mysql_close(mysql);

mysql= mysql_init(NULL);
local_infile= 1;
mysql_optionsv(mysql, MYSQL_OPT_LOCAL_INFILE, &local_infile);
my_test_connect(mysql, hostname, username, password, schema,
port, socketname,
CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS);
FAIL_IF(mysql_errno(mysql), "No error expected");
mysql_get_option(mysql, MYSQL_OPT_LOCAL_INFILE, &local_infile);

FAIL_IF(!local_infile, "local infile was not enabled");
mysql_close(mysql);

return OK;
}

struct my_tests_st my_tests[] = {
{"test_conc297", test_conc297, TEST_CONNECTION_NONE, 0, NULL, NULL},
{"test_conc277", test_conc277, TEST_CONNECTION_NONE, 0, NULL, NULL},
{"test_mdev9059_1", test_mdev9059_1, TEST_CONNECTION_NONE, 0, NULL, NULL},
{"test_mdev9059_2", test_mdev9059_2, TEST_CONNECTION_NONE, 0, NULL, NULL},
Expand Down

0 comments on commit 434b67e

Please sign in to comment.