Skip to content

Commit cacd251

Browse files
authored
Merge pull request #275 from PavolSloboda/static-analysis-result
Static analysis result bug fixes
2 parents dad72b6 + ba69f71 commit cacd251

File tree

8 files changed

+85
-6
lines changed

8 files changed

+85
-6
lines changed

libmariadb/ma_client_plugin.c.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ static void load_env_plugins(MYSQL *mysql)
248248
free_env= strdup(s);
249249
plugs= s= free_env;
250250

251+
if (!free_env)
252+
{
253+
SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0);
254+
return;
255+
}
256+
251257
do {
252258
if ((s= strchr(plugs, ';')))
253259
*s= '\0';

libmariadb/ma_pvio.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ int ma_pvio_register_callback(my_bool register_callback,
557557
if (register_callback)
558558
{
559559
list= (LIST *)malloc(sizeof(LIST));
560+
if (!list)
561+
return 1;
560562

561563
list->data= (void *)callback_function;
562564
pvio_callback= list_add(pvio_callback, list);

libmariadb/mariadb_async.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ my_connect_async(MARIADB_PVIO *pvio,
9494
#else
9595
int err= errno;
9696
if (err != EINPROGRESS && err != EALREADY && err != EAGAIN)
97-
return res;
97+
{
98+
close(sock);
99+
return res;
100+
}
98101
#endif
99102
b->events_to_wait_for|= MYSQL_WAIT_WRITE;
100103
if (vio_timeout >= 0)

libmariadb/mariadb_lib.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,11 @@ static int parse_connection_string(MYSQL *mysql, const char *unused __attribute_
878878

879879
/* don't modify original dsn */
880880
conn_save= (char *)malloc(len + 1);
881+
if (!conn_save)
882+
{
883+
SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0);
884+
return 1;
885+
}
881886
memcpy(conn_save, conn_str, len);
882887
conn_save[len]= 0;
883888

@@ -4595,6 +4600,7 @@ my_bool mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void *arg, ...
45954600
size= va_arg(ap, unsigned int);
45964601
if (!ma_pvio_tls_get_peer_cert_info(mysql->net.pvio->ctls, size))
45974602
*((MARIADB_X509_INFO **)arg)= (MARIADB_X509_INFO *)&mysql->net.pvio->ctls->cert_info;
4603+
va_end(ap);
45984604
return 0;
45994605
}
46004606
*((MARIADB_X509_INFO **)arg)= NULL;

libmariadb/mariadb_rpl.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,9 +1884,9 @@ MARIADB_RPL_EVENT * STDCALL mariadb_rpl_fetch(MARIADB_RPL *rpl, MARIADB_RPL_EVEN
18841884
/* We need to report an error if this event can't be ignored */
18851885
if (!(rpl_event->flags & LOG_EVENT_IGNORABLE_F))
18861886
{
1887-
mariadb_free_rpl_event(rpl_event);
18881887
rpl_set_error(rpl, CR_UNKNOWN_BINLOG_EVENT, 0, RPL_ERR_POS(rpl),
18891888
rpl_event->event_type);
1889+
mariadb_free_rpl_event(rpl_event);
18901890
return 0;
18911891
}
18921892
return rpl_event;
@@ -1976,6 +1976,12 @@ int STDCALL mariadb_rpl_optionsv(MARIADB_RPL *rpl,
19761976
else if (arg1)
19771977
{
19781978
rpl->filename= strdup((const char *)arg1);
1979+
if (!rpl->filename)
1980+
{
1981+
va_end(ap);
1982+
rpl_set_error(rpl, CR_OUT_OF_MEMORY, 0);
1983+
return 1;
1984+
}
19791985
rpl->filename_length= (uint32_t)strlen(rpl->filename);
19801986
}
19811987
break;

unittest/libmariadb/connection.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,7 @@ static int test_conc327(MYSQL *unused __attribute__((unused)))
15221522
const char *env= getenv("MYSQL_TMP_DIR");
15231523
char cnf_file1[FN_REFLEN + 1];
15241524
char cnf_file2[FN_REFLEN + 1];
1525+
my_bool failed_opening_files;
15251526

15261527
SKIP_SKYSQL;
15271528

@@ -1540,7 +1541,19 @@ static int test_conc327(MYSQL *unused __attribute__((unused)))
15401541

15411542
fp1= fopen(cnf_file1, "w");
15421543
fp2= fopen(cnf_file2, "w");
1543-
FAIL_IF(!fp1 || !fp2, "fopen failed");
1544+
if((failed_opening_files = !fp1 || !fp2))
1545+
{
1546+
if(fp1)
1547+
{
1548+
fclose(fp1);
1549+
}
1550+
if(fp2)
1551+
{
1552+
fclose(fp2);
1553+
}
1554+
}
1555+
1556+
FAIL_IF(failed_opening_files, "fopen failed");
15441557

15451558
fprintf(fp1, "!include %s\n", cnf_file2);
15461559

@@ -1565,7 +1578,18 @@ static int test_conc327(MYSQL *unused __attribute__((unused)))
15651578
snprintf(cnf_file1, FN_REFLEN, "%s%cmy.cnf", env, FN_LIBCHAR);
15661579
fp1= fopen(cnf_file1, "w");
15671580
fp2= fopen(cnf_file2, "w");
1568-
FAIL_IF(!fp1 || !fp2, "fopen failed");
1581+
if((failed_opening_files = !fp1 || !fp2))
1582+
{
1583+
if(fp1)
1584+
{
1585+
fclose(fp1);
1586+
}
1587+
if(fp2)
1588+
{
1589+
fclose(fp2);
1590+
}
1591+
}
1592+
FAIL_IF(failed_opening_files, "fopen failed");
15691593

15701594
fprintf(fp2, "!includedir %s\n", env);
15711595

unittest/libmariadb/misc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,21 +287,31 @@ static int test_frm_bug(MYSQL *mysql)
287287
}
288288

289289
rc= mysql_query(mysql, "SHOW TABLE STATUS like 'test_frm_bug'");
290+
if (rc)
291+
fclose(test_file);
290292
check_mysql_rc(rc, mysql);
291293

292294
result= mysql_store_result(mysql);
295+
if(!result)
296+
fclose(test_file);
293297
FAIL_IF(!result, "Invalid result set");/* It can't be NULL */
294298

295299
rc= 0;
296300
while (mysql_fetch_row(result))
297301
rc++;
302+
if(rc != 1)
303+
fclose(test_file);
298304
FAIL_UNLESS(rc == 1, "rowcount != 1");
299305

300306
mysql_data_seek(result, 0);
301307

302308
row= mysql_fetch_row(result);
309+
if(!row)
310+
fclose(test_file);
303311
FAIL_IF(!row, "couldn't fetch row");
304312

313+
if(row[17] != 0)
314+
fclose(test_file);
305315
FAIL_UNLESS(row[17] != 0, "row[17] != 0");
306316

307317
mysql_free_result(result);

unittest/libmariadb/ps_bugs.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,11 +2677,19 @@ static int test_bug5194(MYSQL *mysql)
26772677
check_mysql_rc(rc, mysql);
26782678

26792679
my_bind= (MYSQL_BIND*) malloc(MAX_PARAM_COUNT * sizeof(MYSQL_BIND));
2680+
FAIL_UNLESS(my_bind, "Not enough memory");
26802681
query= (char*) malloc(strlen(query_template) +
26812682
MAX_PARAM_COUNT * CHARS_PER_PARAM + 1);
2683+
if(!query)
2684+
free(my_bind);
2685+
FAIL_UNLESS(query, "Not enough memory");
26822686
param_str= (char*) malloc(COLUMN_COUNT * CHARS_PER_PARAM);
2683-
2684-
FAIL_IF(my_bind == 0 || query == 0 || param_str == 0, "Not enough memory");
2687+
if(!param_str)
2688+
{
2689+
free(my_bind);
2690+
free(query);
2691+
}
2692+
FAIL_UNLESS(param_str, "Not enough memory");
26852693

26862694
stmt= mysql_stmt_init(mysql);
26872695

@@ -5164,18 +5172,28 @@ static int test_maxparam(MYSQL *mysql)
51645172
MYSQL_BIND* bind;
51655173

51665174
bind = calloc(65535, sizeof *bind);
5175+
FAIL_UNLESS(bind, "Not enough memory");
51675176

51685177
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
5178+
if (rc)
5179+
free(bind);
51695180
check_mysql_rc(rc, mysql);
51705181

51715182
rc= mysql_query(mysql, "CREATE TABLE t1 (a int)");
5183+
if (rc)
5184+
free(bind);
51725185
check_mysql_rc(rc, mysql);
51735186

51745187
buffer= calloc(1, mem);
5188+
if(!buffer)
5189+
free(bind);
5190+
FAIL_UNLESS(bind, "Not enough memory");
51755191
strcpy(buffer, query);
51765192
for (i=0; i < 65534.; i++)
51775193
strcat(buffer, ",(?)");
51785194
rc= mysql_stmt_prepare(stmt, SL(buffer));
5195+
if (rc)
5196+
free(bind);
51795197
check_stmt_rc(rc, stmt);
51805198

51815199
for (i=0; i < 65534; i++)
@@ -5185,9 +5203,13 @@ static int test_maxparam(MYSQL *mysql)
51855203
}
51865204

51875205
rc= mysql_stmt_bind_param(stmt, bind);
5206+
if (rc)
5207+
free(bind);
51885208
check_stmt_rc(rc, stmt);
51895209

51905210
rc= mysql_stmt_execute(stmt);
5211+
if (rc)
5212+
free(bind);
51915213
check_stmt_rc(rc, stmt);
51925214

51935215
FAIL_IF(mysql_stmt_affected_rows(stmt) != 65535, "Expected affected_rows=65535");

0 commit comments

Comments
 (0)