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")) &&
|
||||
add_cfg_dir(configuration_dirs, env))
|
||||
goto error;
|
||||
#ifndef _WIN32
|
||||
if ((env= getenv("HOME")) &&
|
||||
add_cfg_dir(configuration_dirs, env))
|
||||
goto error;
|
||||
#endif
|
||||
end:
|
||||
return configuration_dirs;
|
||||
error:
|
||||
@@ -304,7 +299,7 @@ my_bool _mariadb_read_options(MYSQL *mysql,
|
||||
|
||||
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,
|
||||
"%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 */
|
||||
if ((env= getenv("HOME")))
|
||||
{
|
||||
for (exts= 0; exts < 2; exts++)
|
||||
for (exts= 0; ini_exts[exts]; exts++)
|
||||
{
|
||||
snprintf(filename, FN_REFLEN,
|
||||
"%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))
|
||||
{
|
||||
my_bool val_bool;
|
||||
int val_int;
|
||||
size_t val_sizet;
|
||||
int rc;
|
||||
void *option_val= NULL;
|
||||
switch (mariadb_defaults[i].type) {
|
||||
case MARIADB_OPTION_BOOL:
|
||||
{
|
||||
my_bool val= 0;
|
||||
val_bool= 0;
|
||||
if (config_value)
|
||||
val= atoi(config_value);
|
||||
option_val= &val;
|
||||
val_bool= atoi(config_value);
|
||||
option_val= &val_bool;
|
||||
break;
|
||||
}
|
||||
case MARIADB_OPTION_INT:
|
||||
{
|
||||
int val= 0;
|
||||
val_int= 0;
|
||||
if (config_value)
|
||||
val= atoi(config_value);
|
||||
option_val= &val;
|
||||
val_int= atoi(config_value);
|
||||
option_val= &val_int;
|
||||
break;
|
||||
}
|
||||
case MARIADB_OPTION_SIZET:
|
||||
{
|
||||
size_t val= 0;
|
||||
val_sizet= 0;
|
||||
if (config_value)
|
||||
val= strtol(config_value, NULL, 10);
|
||||
option_val= &val;
|
||||
val_sizet= strtol(config_value, NULL, 10);
|
||||
option_val= &val_sizet;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case MARIADB_OPTION_STR:
|
||||
option_val= (void*)config_value;
|
||||
break;
|
||||
case MARIADB_OPTION_NONE:
|
||||
break;
|
||||
}
|
||||
rc= mysql_optionsv(mysql, mariadb_defaults[i].option, option_val);
|
||||
return(test(rc));
|
||||
|
@@ -1060,34 +1060,32 @@ static int test_mdev12965(MYSQL *unused __attribute__((unused)))
|
||||
MYSQL *mysql;
|
||||
my_bool reconnect = 0;
|
||||
FILE *fp= NULL;
|
||||
char *env= getenv("HOME");
|
||||
char cnf_file1[FN_REFLEN + 1],
|
||||
cnf_file2[FN_REFLEN + 1];
|
||||
const char *env= getenv("MYSQL_TMP_DIR");
|
||||
char cnf_file1[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_file2, FN_REFLEN, "%s%cmy.cnf", env, FN_LIBCHAR);
|
||||
|
||||
if (!access(cnf_file1, R_OK) || !access(cnf_file2, R_OK))
|
||||
{
|
||||
diag("Skip this test, it would overwrite configuration files in your home directory");
|
||||
return SKIP;
|
||||
}
|
||||
diag("Config file: %s", cnf_file1);
|
||||
|
||||
FAIL_IF(!access(cnf_file1, R_OK), "access");
|
||||
|
||||
mysql= mysql_init(NULL);
|
||||
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);
|
||||
|
||||
fp= fopen(cnf_file2, "w");
|
||||
fprintf(fp, "[test]\nreconnect=1");
|
||||
fclose(fp);
|
||||
|
||||
mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "test");
|
||||
my_test_connect(mysql, hostname, username, password, schema,
|
||||
0, socketname, 0), mysql_error(mysql);
|
||||
mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, NULL);
|
||||
my_test_connect(mysql, hostname, username, password,
|
||||
schema, 0, socketname, 0);
|
||||
|
||||
remove(cnf_file1);
|
||||
remove(cnf_file2);
|
||||
|
||||
FAIL_IF(strcmp(mysql_character_set_name(mysql), "latin2"), "expected charset latin2");
|
||||
mysql_get_optionv(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
|
Reference in New Issue
Block a user