Commit 023bb2fc authored by Anel Husakovic's avatar Anel Husakovic Committed by Andrew Hutchings

MDBF-534: Coverity scan: fix client folder

--------------------------------
    File: `mysqldump`:
    --------------------------------
    -Coverity (`BAD_SHIFT`):
    https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53073433&mergedDefectId=1211186&eventId=53073433-25

    `mysqldump` - Error obtained by coverity is implication of type
    conversion.
    It may happen that function `find_type` returns -1 which
    is assigned to `uint` that gets converted by compiler to max
    (UINT_32/64). In that situation left bit shift may lead to UB.
    Converting from `uint` to `int` will solve the problem.

    - Coverity (`RESOURCE_LEAK`):
      - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53072912&mergedDefectId=1519239
      - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53073706&mergedDefectId=1519368
      - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53073560&mergedDefectId=1519655
      - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53074494&mergedDefectId=1519822&fileStart=4001&fileEnd=4250
      - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53074999&mergedDefectId=1519915&eventId=53074999-53
      - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53075060&mergedDefectId=1519964
      - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53073268&mergedDefectId=1519967
      - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53073015&mergedDefectId=1520164

    `mysqldump` - in case of error memory should be freeed.

    - Coverity (`UNINT`) - FALSE POSITIVES:
      - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53074364&mergedDefectId=1519587&eventId=53074364-10
      - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53072619&mergedDefectId=1519684&eventId=53072619-1
      - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53073256&mergedDefectId=1519722
      - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53074251&mergedDefectId=1519979
      - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53074996&mergedDefectId=1520021
      - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53073425&mergedDefectId=1520166&eventId=53073425-9

    ---------------------------------
    File: `mysqladmin`
    ---------------------------------
    - Coverity (PRECEDANCE_ERROR) a.k.a MDEV-15736:
      https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728425&defectInstanceId=53074187&mergedDefectId=1519944

    - Coverity (BAD_FREE) - FALSE POSITIVE:
      https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728425&defectInstanceId=53074614&mergedDefectId=1520042

    ---------------------------------
    File: `mysqlimport`
    ---------------------------------
    - FALSE POSITIVES
      - Coverity (TAINTED_SCALAR):
        https://scan5.scan.coverity.com/reports.htm#v58936/p10357/  fileInstanceId=231728411&defectInstanceId=53074012&mergedDefectId=1519158&eventId=53074012-6
      - Coverity (UNINT):
        https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728411&defectInstanceId=53072860&mergedDefectId=1520020

    ---------------------------------
    File: `mysqlshow`
    ---------------------------------
    - FALSE POSITIVES
      - Coverity (TAINTED_SCALAR):
        https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728418&defectInstanceId=53074361&mergedDefectId=1519232&eventId=53074361-4
      - Coverity (UNINT):
        https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728411&defectInstanceId=53072860&mergedDefectId=1520020

      - Coverity (BAD_FREE):
        https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728418&defectInstanceId=53073408&mergedDefectId=1519972
parent ff7e0977
......@@ -1589,7 +1589,8 @@ static void print_relative_row_vert(MYSQL_RES *result __attribute__((unused)),
llstr((tmp - last_values[row]), buff));
/* Find the minimum row length needed to output the relative value */
if ((length=(uint) strlen(buff) > ex_val_max_len[row]) && ex_status_printed)
length=(uint) strlen(buff);
if (length > ex_val_max_len[row] && ex_status_printed)
ex_val_max_len[row] = length;
last_values[row] = tmp;
}
......
......@@ -2480,8 +2480,11 @@ static uint dump_events_for_db(char *db)
/* Get database collation. */
if (fetch_db_collation(db_name_buff, db_cl_name, sizeof (db_cl_name)))
{
mysql_free_result(event_list_res);
DBUG_RETURN(1);
}
}
if (switch_character_set_results(mysql, "binary"))
DBUG_RETURN(1);
......@@ -3262,7 +3265,10 @@ static uint get_table_structure(const char *table, const char *db, char *table_t
if (path)
{
if (!(sql_file= open_sql_file_for_table(table, O_WRONLY)))
{
mysql_free_result(result);
DBUG_RETURN(0);
}
write_header(sql_file, db);
}
......@@ -3663,7 +3669,7 @@ static int dump_triggers_for_table(char *table_name, char *db_name)
char name_buff[NAME_LEN*4+3];
char query_buff[QUERY_LENGTH];
uint old_opt_compatible_mode= opt_compatible_mode;
MYSQL_RES *show_triggers_rs;
MYSQL_RES *show_triggers_rs= NULL;
MYSQL_ROW row;
FILE *sql_file= md_result_file;
......@@ -3747,8 +3753,6 @@ static int dump_triggers_for_table(char *table_name, char *db_name)
}
skip:
mysql_free_result(show_triggers_rs);
if (switch_character_set_results(mysql, default_charset))
goto done;
......@@ -3763,7 +3767,7 @@ static int dump_triggers_for_table(char *table_name, char *db_name)
done:
if (path)
my_fclose(sql_file, MYF(0));
mysql_free_result(show_triggers_rs);
DBUG_RETURN(ret);
}
......@@ -3869,7 +3873,7 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,
uint num_fields;
size_t total_length, init_length;
MYSQL_RES *res;
MYSQL_RES *res= NULL;
MYSQL_FIELD *field;
MYSQL_ROW row;
DBUG_ENTER("dump_table");
......@@ -4055,6 +4059,8 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,
fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n",
my_progname_short, result_table);
error= EX_CONSCHECK;
if (!quick)
mysql_free_result(res);
goto err;
}
......@@ -4354,6 +4360,7 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,
err:
dynstr_free(&query_string);
maybe_exit(error);
mysql_free_result(res);
DBUG_VOID_RETURN;
} /* dump_table */
......@@ -4619,7 +4626,11 @@ static int dump_all_users_roles_and_grants()
" '@', QUOTE(DEFAULT_ROLE_HOST))) as r,"
" CONCAT(QUOTE(mu.USER),'@',QUOTE(mu.HOST)) as u "
"FROM mysql.user mu LEFT JOIN mysql.default_roles using (USER, HOST)"))
{
mysql_free_result(tableres);
return 1;
}
while ((row= mysql_fetch_row(tableres)))
{
if (dump_grants(row[1]))
......@@ -5696,7 +5707,8 @@ static int get_sys_var_lower_case_table_names()
lower_case_table_names= atoi(row[1]);
mysql_free_result(table_res);
}
if (!row)
mysql_free_result(table_res);
return lower_case_table_names;
}
......@@ -5939,9 +5951,13 @@ static int do_show_master_status(MYSQL *mysql_con, int consistent_binlog_pos,
}
if (have_mariadb_gtid && get_gtid_pos(gtid_pos, 1))
{
mysql_free_result(master);
return 1;
}
}
/* SHOW MASTER STATUS reports file and position */
print_comment(md_result_file, 0,
"\n--\n-- Position to start replication or point-in-time "
......@@ -6061,7 +6077,10 @@ static int do_show_slave_status(MYSQL *mysql_con, int use_gtid,
{
char gtid_pos[MAX_GTID_LENGTH];
if (have_mariadb_gtid && get_gtid_pos(gtid_pos, 0))
{
mysql_free_result(slave);
return 1;
}
if (opt_comments)
fprintf(md_result_file, "\n--\n-- Gtid position to start replication "
"from\n--\n\n");
......@@ -6257,7 +6276,7 @@ static ulong find_set(TYPELIB *lib, const char *x, size_t length,
{
const char *end= x + length;
ulong found= 0;
uint find;
int find;
char buff[255];
*err_pos= 0; /* No error yet */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment