You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-07 02:42:49 +03:00
followup for e2df6d2
: default directories, files, and groups
* do not read ini_exts array beyond the end * do not use local variable (val) address outside of the variable's scope * do not read $HOME/my.cnf * do not create files in the user's $HOME, use $MYSQL_TMP_DIR * test reading of the executable name group * fail the test if .my.cnf cannot be opened
This commit is contained in:
@@ -118,11 +118,6 @@ char **get_default_configuration_dirs()
|
|||||||
if ((env= getenv("MYSQL_HOME")) &&
|
if ((env= getenv("MYSQL_HOME")) &&
|
||||||
add_cfg_dir(configuration_dirs, env))
|
add_cfg_dir(configuration_dirs, env))
|
||||||
goto error;
|
goto error;
|
||||||
#ifndef _WIN32
|
|
||||||
if ((env= getenv("HOME")) &&
|
|
||||||
add_cfg_dir(configuration_dirs, env))
|
|
||||||
goto error;
|
|
||||||
#endif
|
|
||||||
end:
|
end:
|
||||||
return configuration_dirs;
|
return configuration_dirs;
|
||||||
error:
|
error:
|
||||||
@@ -304,7 +299,7 @@ my_bool _mariadb_read_options(MYSQL *mysql,
|
|||||||
|
|
||||||
for (i=0; i < MAX_CONFIG_DIRS && configuration_dirs[i]; i++)
|
for (i=0; i < MAX_CONFIG_DIRS && configuration_dirs[i]; i++)
|
||||||
{
|
{
|
||||||
for (exts= 0; exts < 2; exts++)
|
for (exts= 0; ini_exts[exts]; exts++)
|
||||||
{
|
{
|
||||||
snprintf(filename, FN_REFLEN,
|
snprintf(filename, FN_REFLEN,
|
||||||
"%s%cmy.%s", configuration_dirs[i], FN_LIBCHAR, ini_exts[exts]);
|
"%s%cmy.%s", configuration_dirs[i], FN_LIBCHAR, ini_exts[exts]);
|
||||||
@@ -316,7 +311,7 @@ my_bool _mariadb_read_options(MYSQL *mysql,
|
|||||||
/* special case: .my.cnf in Home directory */
|
/* special case: .my.cnf in Home directory */
|
||||||
if ((env= getenv("HOME")))
|
if ((env= getenv("HOME")))
|
||||||
{
|
{
|
||||||
for (exts= 0; exts < 2; exts++)
|
for (exts= 0; ini_exts[exts]; exts++)
|
||||||
{
|
{
|
||||||
snprintf(filename, FN_REFLEN,
|
snprintf(filename, FN_REFLEN,
|
||||||
"%s%c.my.%s", env, FN_LIBCHAR, ini_exts[exts]);
|
"%s%c.my.%s", env, FN_LIBCHAR, ini_exts[exts]);
|
||||||
|
@@ -701,35 +701,35 @@ my_bool _mariadb_set_conf_option(MYSQL *mysql, const char *config_option, const
|
|||||||
{
|
{
|
||||||
if (!strcmp(mariadb_defaults[i].conf_key, config_option))
|
if (!strcmp(mariadb_defaults[i].conf_key, config_option))
|
||||||
{
|
{
|
||||||
|
my_bool val_bool;
|
||||||
|
int val_int;
|
||||||
|
size_t val_sizet;
|
||||||
int rc;
|
int rc;
|
||||||
void *option_val= NULL;
|
void *option_val= NULL;
|
||||||
switch (mariadb_defaults[i].type) {
|
switch (mariadb_defaults[i].type) {
|
||||||
case MARIADB_OPTION_BOOL:
|
case MARIADB_OPTION_BOOL:
|
||||||
{
|
val_bool= 0;
|
||||||
my_bool val= 0;
|
|
||||||
if (config_value)
|
if (config_value)
|
||||||
val= atoi(config_value);
|
val_bool= atoi(config_value);
|
||||||
option_val= &val;
|
option_val= &val_bool;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case MARIADB_OPTION_INT:
|
case MARIADB_OPTION_INT:
|
||||||
{
|
val_int= 0;
|
||||||
int val= 0;
|
|
||||||
if (config_value)
|
if (config_value)
|
||||||
val= atoi(config_value);
|
val_int= atoi(config_value);
|
||||||
option_val= &val;
|
option_val= &val_int;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case MARIADB_OPTION_SIZET:
|
case MARIADB_OPTION_SIZET:
|
||||||
{
|
val_sizet= 0;
|
||||||
size_t val= 0;
|
|
||||||
if (config_value)
|
if (config_value)
|
||||||
val= strtol(config_value, NULL, 10);
|
val_sizet= strtol(config_value, NULL, 10);
|
||||||
option_val= &val;
|
option_val= &val_sizet;
|
||||||
break;
|
break;
|
||||||
}
|
case MARIADB_OPTION_STR:
|
||||||
default:
|
|
||||||
option_val= (void*)config_value;
|
option_val= (void*)config_value;
|
||||||
|
break;
|
||||||
|
case MARIADB_OPTION_NONE:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
rc= mysql_optionsv(mysql, mariadb_defaults[i].option, option_val);
|
rc= mysql_optionsv(mysql, mariadb_defaults[i].option, option_val);
|
||||||
return(test(rc));
|
return(test(rc));
|
||||||
|
@@ -1060,34 +1060,32 @@ static int test_mdev12965(MYSQL *unused __attribute__((unused)))
|
|||||||
MYSQL *mysql;
|
MYSQL *mysql;
|
||||||
my_bool reconnect = 0;
|
my_bool reconnect = 0;
|
||||||
FILE *fp= NULL;
|
FILE *fp= NULL;
|
||||||
char *env= getenv("HOME");
|
const char *env= getenv("MYSQL_TMP_DIR");
|
||||||
char cnf_file1[FN_REFLEN + 1],
|
char cnf_file1[FN_REFLEN + 1];
|
||||||
cnf_file2[FN_REFLEN + 1];
|
|
||||||
|
if (!env)
|
||||||
|
env= "/tmp";
|
||||||
|
|
||||||
|
setenv("HOME", env, 1);
|
||||||
|
|
||||||
snprintf(cnf_file1, FN_REFLEN, "%s%c.my.cnf", env, FN_LIBCHAR);
|
snprintf(cnf_file1, FN_REFLEN, "%s%c.my.cnf", env, FN_LIBCHAR);
|
||||||
snprintf(cnf_file2, FN_REFLEN, "%s%cmy.cnf", env, FN_LIBCHAR);
|
|
||||||
|
|
||||||
if (!access(cnf_file1, R_OK) || !access(cnf_file2, R_OK))
|
diag("Config file: %s", cnf_file1);
|
||||||
{
|
|
||||||
diag("Skip this test, it would overwrite configuration files in your home directory");
|
FAIL_IF(!access(cnf_file1, R_OK), "access");
|
||||||
return SKIP;
|
|
||||||
}
|
|
||||||
|
|
||||||
mysql= mysql_init(NULL);
|
mysql= mysql_init(NULL);
|
||||||
fp= fopen(cnf_file1, "w");
|
fp= fopen(cnf_file1, "w");
|
||||||
fprintf(fp, "[test]\ndefault-character-set=latin2");
|
FAIL_IF(!fp, "fopen");
|
||||||
|
|
||||||
|
fprintf(fp, "[misc]\ndefault-character-set=latin2\n[client]\nreconnect=1\n");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
fp= fopen(cnf_file2, "w");
|
mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, NULL);
|
||||||
fprintf(fp, "[test]\nreconnect=1");
|
my_test_connect(mysql, hostname, username, password,
|
||||||
fclose(fp);
|
schema, 0, socketname, 0);
|
||||||
|
|
||||||
mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "test");
|
|
||||||
my_test_connect(mysql, hostname, username, password, schema,
|
|
||||||
0, socketname, 0), mysql_error(mysql);
|
|
||||||
|
|
||||||
remove(cnf_file1);
|
remove(cnf_file1);
|
||||||
remove(cnf_file2);
|
|
||||||
|
|
||||||
FAIL_IF(strcmp(mysql_character_set_name(mysql), "latin2"), "expected charset latin2");
|
FAIL_IF(strcmp(mysql_character_set_name(mysql), "latin2"), "expected charset latin2");
|
||||||
mysql_get_optionv(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
mysql_get_optionv(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||||
|
Reference in New Issue
Block a user