summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2023-01-31 10:37:31 +0100
committerOleksandr Byelkin <sanja@mariadb.com>2023-01-31 10:37:31 +0100
commitde2d08994255739d53ba28ea34288ca8352029b1 (patch)
treecc557fe9fa3655a03cae9b6895c6e8a0348b2f86 /client
parent4d9fe4032b768e04e33482d83199882c7bb0d9d8 (diff)
parent638625278e7cadf42633e6f9d1b663ca1e3e1bb1 (diff)
downloadmariadb-git-de2d08994255739d53ba28ea34288ca8352029b1.tar.gz
Merge branch '10.8' into 10.9
Diffstat (limited to 'client')
-rw-r--r--client/mysql.cc3
-rw-r--r--client/mysql_plugin.c86
-rw-r--r--client/mysqldump.c2
-rw-r--r--client/mysqltest.cc15
4 files changed, 54 insertions, 52 deletions
diff --git a/client/mysql.cc b/client/mysql.cc
index e63dcf5dbe9..c709095dc8e 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -3798,7 +3798,10 @@ print_table_data(MYSQL_RES *result)
{
print_field_types(result);
if (!mysql_num_rows(result))
+ {
+ my_afree((uchar*) num_flag);
return;
+ }
mysql_field_seek(result,0);
}
separator.copy("+",1,charset_info);
diff --git a/client/mysql_plugin.c b/client/mysql_plugin.c
index d9084ec7c35..dab98b10043 100644
--- a/client/mysql_plugin.c
+++ b/client/mysql_plugin.c
@@ -569,14 +569,14 @@ static int file_exists(char * filename)
@retval int error = 1, success = 0
*/
-static int search_dir(const char * base_path, const char *tool_name,
+static int search_dir(const char *base_path, const char *tool_name,
const char *subdir, char *tool_path)
{
char new_path[FN_REFLEN];
char source_path[FN_REFLEN];
- strcpy(source_path, base_path);
- strcat(source_path, subdir);
+ safe_strcpy(source_path, sizeof(source_path), base_path);
+ safe_strcat(source_path, sizeof(source_path), subdir);
fn_format(new_path, tool_name, source_path, "", MY_UNPACK_FILENAME);
if (file_exists(new_path))
{
@@ -632,7 +632,7 @@ static int load_plugin_data(char *plugin_name, char *config_file)
FILE *file_ptr;
char path[FN_REFLEN];
char line[1024];
- char *reason= 0;
+ const char *reason= 0;
char *res;
int i= -1;
@@ -643,14 +643,14 @@ static int load_plugin_data(char *plugin_name, char *config_file)
}
if (!file_exists(opt_plugin_ini))
{
- reason= (char *)"File does not exist.";
+ reason= "File does not exist.";
goto error;
}
file_ptr= fopen(opt_plugin_ini, "r");
if (file_ptr == NULL)
{
- reason= (char *)"Cannot open file.";
+ reason= "Cannot open file.";
goto error;
}
@@ -660,17 +660,20 @@ static int load_plugin_data(char *plugin_name, char *config_file)
/* Read plugin components */
while (i < 16)
{
+ size_t line_len;
+
res= fgets(line, sizeof(line), file_ptr);
+ line_len= strlen(line);
+
/* strip /n */
- if (line[strlen(line)-1] == '\n')
- {
- line[strlen(line)-1]= '\0';
- }
+ if (line[line_len - 1] == '\n')
+ line[line_len - 1]= '\0';
+
if (res == NULL)
{
if (i < 1)
{
- reason= (char *)"Bad format in plugin configuration file.";
+ reason= "Bad format in plugin configuration file.";
fclose(file_ptr);
goto error;
}
@@ -683,14 +686,19 @@ static int load_plugin_data(char *plugin_name, char *config_file)
if (i == -1) /* if first pass, read this line as so_name */
{
/* Add proper file extension for soname */
- strcat(line, FN_SOEXT);
+ if (safe_strcpy(line + line_len - 1, sizeof(line), FN_SOEXT))
+ {
+ reason= "Plugin name too long.";
+ fclose(file_ptr);
+ goto error;
+ }
/* save so_name */
plugin_data.so_name= my_strdup(PSI_NOT_INSTRUMENTED, line, MYF(MY_WME|MY_ZEROFILL));
i++;
}
else
{
- if (strlen(line) > 0)
+ if (line_len > 0)
{
plugin_data.components[i]= my_strdup(PSI_NOT_INSTRUMENTED, line, MYF(MY_WME));
i++;
@@ -779,14 +787,13 @@ static int check_options(int argc, char **argv, char *operation)
/* read the plugin config file and check for match against argument */
else
{
- if (strlen(argv[i]) + 4 + 1 > FN_REFLEN)
+ if (safe_strcpy(plugin_name, sizeof(plugin_name), argv[i]) ||
+ safe_strcpy(config_file, sizeof(config_file), argv[i]) ||
+ safe_strcat(config_file, sizeof(config_file), ".ini"))
{
fprintf(stderr, "ERROR: argument is too long.\n");
return 1;
}
- strcpy(plugin_name, argv[i]);
- strcpy(config_file, argv[i]);
- strcat(config_file, ".ini");
}
}
@@ -855,35 +862,30 @@ static int check_options(int argc, char **argv, char *operation)
static int process_options(int argc, char *argv[], char *operation)
{
int error= 0;
- int i= 0;
/* Parse and execute command-line options */
if ((error= handle_options(&argc, &argv, my_long_options, get_one_option)))
- goto exit;
+ return error;
/* If the print defaults option used, exit. */
if (opt_print_defaults)
- {
- error= -1;
- goto exit;
- }
+ return -1;
/* Add a trailing directory separator if not present */
if (opt_basedir)
{
- i= (int)strlength(opt_basedir);
- if (opt_basedir[i-1] != FN_LIBCHAR || opt_basedir[i-1] != FN_LIBCHAR2)
+ size_t basedir_len= strlength(opt_basedir);
+ if (opt_basedir[basedir_len - 1] != FN_LIBCHAR ||
+ opt_basedir[basedir_len - 1] != FN_LIBCHAR2)
{
char buff[FN_REFLEN];
- memset(buff, 0, sizeof(buff));
-
- strncpy(buff, opt_basedir, sizeof(buff) - 1);
-#ifdef _WIN32
- strncat(buff, "/", sizeof(buff) - strlen(buff) - 1);
-#else
- strncat(buff, FN_DIRSEP, sizeof(buff) - strlen(buff) - 1);
-#endif
- buff[sizeof(buff) - 1]= 0;
+ if (basedir_len + 2 > FN_REFLEN)
+ return -1;
+
+ memcpy(buff, opt_basedir, basedir_len);
+ buff[basedir_len]= '/';
+ buff[basedir_len + 1]= '\0';
+
my_free(opt_basedir);
opt_basedir= my_strdup(PSI_NOT_INSTRUMENTED, buff, MYF(MY_FAE));
}
@@ -895,10 +897,7 @@ static int process_options(int argc, char *argv[], char *operation)
generated when the defaults were read from the file, exit.
*/
if (!opt_no_defaults && ((error= get_default_values())))
- {
- error= -1;
- goto exit;
- }
+ return -1;
/*
Check to ensure required options are present and validate the operation.
@@ -906,11 +905,9 @@ static int process_options(int argc, char *argv[], char *operation)
read a configuration file named <plugin_name>.ini from the --plugin-dir
or --plugin-ini location if the --plugin-ini option presented.
*/
- strcpy(operation, "");
- if ((error = check_options(argc, argv, operation)))
- {
- goto exit;
- }
+ operation[0]= '\0';
+ if ((error= check_options(argc, argv, operation)))
+ return error;
if (opt_verbose)
{
@@ -922,8 +919,7 @@ static int process_options(int argc, char *argv[], char *operation)
printf("# lc_messages_dir = %s\n", opt_lc_messages_dir);
}
-exit:
- return error;
+ return 0;
}
diff --git a/client/mysqldump.c b/client/mysqldump.c
index 455bf85b70d..f8812bef974 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -2604,7 +2604,7 @@ static uint dump_events_for_db(char *db)
if (mysql_query_with_error_report(mysql, &event_list_res, "show events"))
DBUG_RETURN(0);
- strcpy(delimiter, ";");
+ safe_strcpy(delimiter, sizeof(delimiter), ";");
if (mysql_num_rows(event_list_res) > 0)
{
if (opt_xml)
diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index ba67fd9b166..cb5a20c4c0f 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -6232,7 +6232,9 @@ int do_done(struct st_command *command)
if (*cur_block->delim)
{
/* Restore "old" delimiter after false if block */
- strcpy (delimiter, cur_block->delim);
+ if (safe_strcpy(delimiter, sizeof(delimiter), cur_block->delim))
+ die("Delimiter too long, truncated");
+
delimiter_length= strlen(delimiter);
}
/* Pop block from stack, goto next line */
@@ -6487,10 +6489,12 @@ void do_block(enum block_cmd cmd, struct st_command* command)
if (cur_block->ok)
{
cur_block->delim[0]= '\0';
- } else
+ }
+ else
{
/* Remember "old" delimiter if entering a false if block */
- strcpy (cur_block->delim, delimiter);
+ if (safe_strcpy(cur_block->delim, sizeof(cur_block->delim), delimiter))
+ die("Delimiter too long, truncated");
}
DBUG_PRINT("info", ("OK: %d", cur_block->ok));
@@ -11896,9 +11900,8 @@ static int setenv(const char *name, const char *value, int overwrite)
char *envvar= (char *)malloc(buflen);
if(!envvar)
return ENOMEM;
- strcpy(envvar, name);
- strcat(envvar, "=");
- strcat(envvar, value);
+
+ snprintf(envvar, buflen, "%s=%s", name, value);
putenv(envvar);
return 0;
}