Skip to content

Commit

Permalink
Coverity fixes and travis integration
Browse files Browse the repository at this point in the history
  • Loading branch information
9EOR9 committed Jul 6, 2018
1 parent ffd9084 commit b0f2e4e
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 102 deletions.
19 changes: 18 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,33 @@ cache:
apt: true
ccache: true
services: docker

env:
global:
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
# via the "travis encrypt" command using the project repo's public key
- secure: "Pk5DUyHtal064Yc4bx0S2Zo4C3NqOURLOqYxW/tQJ73XDTRhyJqD5PFLhsFN+nqvZqx8b1LLtQuVoxP7sW12Qpys7Qs39QavSsa2GWAVf9Kf4PRRsUy5as72/Vh19XbQ1w8fFdPax6KPgnWMb97XZSDJP+2Tyuk8R5pk+/T2t2QsQeml5bJwD0diffLZi27APc0mcNSdaLpPYN4SlEKFmD2CxUAR5IxaBjGKoiuo0f6FSSB1tqlirAnAc5s28tGVkXf42o13oooNYwLgNatc4JRDMofbCVxo9OzqsVbVaN2OwOD3uQ+RxB7X1FydFQm2nfiDNt+D/dBlAz0LkUw1NRrDxl+r6+9xtzVZgHTNUOqG9W5JGJ7j99dUzwSJl6RS4QxeetlrRHGx9S2TTBa6JSkDxiRTQR2XfZxyMtARuHZkY7SAq6sHNKYoyAERuUoeq5e8UOa3dLj4gBwsB/J4y0eLWMxtfDKZj2vGI2BRJewBCBeouPAVIlmWGDyNg6f6X/o07N2IeWJOoj9ZF27Kbp7QxK/D0pQp4AONxtl15ZCfRs5lthKYIHQo0qzlukcir8e7zi5J0bUlOlTT4DtXAeaeIP9oUrLn9kCv7EyvLZMR4dPvREDThqQovF03jqwMDggVa3iGmxu/zrm+S11PwDmzq45+WLcYwyikvsqBFSE="


addons:
hosts:
- mariadb.example.com
coverity_scan:
project:
name: "MariaDB/mariadb-connector-c"
description: "MariaDB Connector/C"
notification_email: georg@mariadb.com
build_command_prepend: "cmake ."
build_command: "make"
branch_pattern: coverity_scan


before_script:
# Disable services enabled by default
- sudo /etc/init.d/mysql stop


before_install:
- echo -n | openssl s_client -connect https://scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
- chmod -R +x .travis/*
- chmod 777 .travis/build/
- export PROJ_PATH=`pwd`
Expand Down
8 changes: 7 additions & 1 deletion include/errmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ extern const char *mariadb_client_errors[]; /* Error messages */
#define CR_AUTH_PLUGIN_CANNOT_LOAD 2059
#define CR_DUPLICATE_CONNECTION_ATTR 2060
#define CR_AUTH_PLUGIN_ERR 2061
/* Always last, if you add new error codes please update the
value for CR_MYSQL_LAST_ERROR */
#define CR_MYSQL_LAST_ERROR CR_AUTH_PLUGIN_ERR

/*
* MariaDB Connector/C errors:
Expand All @@ -96,5 +99,8 @@ extern const char *mariadb_client_errors[]; /* Error messages */
#define CR_FILE_NOT_FOUND 5004
#define CR_FILE_READ 5005
#define CR_BULK_WITHOUT_PARAMETERS 5006

#define CR_INVALID_STMT 5007
/* Always last, if you add new error codes please update the
value for CR_MARIADB_LAST_ERROR */
#define CR_MARIADB_LAST_ERROR CR_INVALID_STMT
#endif
4 changes: 2 additions & 2 deletions include/mariadb_stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#define SET_CLIENT_STMT_ERROR(a, b, c, d) \
{ \
(a)->last_errno= (b);\
strncpy((a)->sqlstate, (c), sizeof((a)->sqlstate));\
strncpy((a)->last_error, (d) ? (d) : ER((b)), sizeof((a)->last_error));\
strncpy((a)->sqlstate, (c), SQLSTATE_LENGTH);\
strncpy((a)->last_error, (d) ? (d) : ER((b)), MYSQL_ERRMSG_SIZE - 1);\
}

#define CLEAR_CLIENT_STMT_ERROR(a) \
Expand Down
4 changes: 2 additions & 2 deletions include/mysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ extern unsigned int mariadb_deinitialize_ssl;
#define SET_CLIENT_ERROR(a, b, c, d) \
{ \
(a)->net.last_errno= (b);\
strncpy((a)->net.sqlstate, (c), sizeof((a)->net.sqlstate));\
strncpy((a)->net.last_error, (d) ? (d) : ER((b)), sizeof((a)->net.last_error));\
strncpy((a)->net.sqlstate, (c), SQLSTATE_LENGTH);\
strncpy((a)->net.last_error, (d) ? (d) : ER((b)), MYSQL_ERRMSG_SIZE - 1);\
}

/* For mysql_async.c */
Expand Down
2 changes: 1 addition & 1 deletion libmariadb/ma_charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ static void map_charset_name(const char *cs_name, my_bool target_cs, char *buffe

if (target_cs)
{
strncat(buffer, "//TRANSLIT", buff_len);
strncat(buffer, "//TRANSLIT", buff_len - strlen(buffer));
}
}
/* }}} */
Expand Down
28 changes: 15 additions & 13 deletions libmariadb/ma_client_plugin.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,20 @@ static void load_env_plugins(MYSQL *mysql)
{
char *plugs, *free_env, *s= getenv("LIBMYSQL_PLUGINS");

/* no plugins to load */
if (!s)
return;

free_env= plugs= strdup(s);
if ((s= getenv("LIBMYSQL_PLUGINS")))
{
s= strdup(s);
free_env= plugs= s;

do {
if ((s= strchr(plugs, ';')))
*s= '\0';
mysql_load_plugin(mysql, plugs, -1, 0);
plugs= s + 1;
} while (s);
do {
if ((s= strchr(plugs, ';')))
*s= '\0';
mysql_load_plugin(mysql, plugs, -1, 0);
plugs= s + 1;
} while (s);

free(free_env);
free(free_env);
}
}

/********** extern functions to be used by libmariadb *********************/
Expand Down Expand Up @@ -365,7 +365,7 @@ mysql_load_plugin_v(MYSQL *mysql, const char *name, int type,
char errbuf[1024];
#endif
char dlpath[FN_REFLEN+1];
void *sym, *dlhandle;
void *sym, *dlhandle = NULL;
struct st_mysql_client_plugin *plugin;
char *env_plugin_dir= getenv("MARIADB_PLUGIN_DIR");

Expand Down Expand Up @@ -448,6 +448,8 @@ mysql_load_plugin_v(MYSQL *mysql, const char *name, int type,
return plugin;

err:
if (dlhandle)
dlclose(dlhandle);
pthread_mutex_unlock(&LOCK_load_client_plugin);
my_set_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, SQLSTATE_UNKNOWN,
ER(CR_AUTH_PLUGIN_CANNOT_LOAD), name, errmsg);
Expand Down
7 changes: 1 addition & 6 deletions libmariadb/ma_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,7 @@ static my_bool _mariadb_read_options_from_file(MYSQL *mysql,
key= ptr;
for ( ; isspace(end[-1]) ; end--) ;
*end= 0;
if (!value)
{
if (!key)
key= ptr;
}
else
if (value)
{
/* Remove pre- and end space */
char *value_end;
Expand Down
2 changes: 2 additions & 0 deletions libmariadb/ma_dtoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,9 @@ static char *dtoa(double dd, int mode, int ndigits, int *decpt, int *sign,
*sign= 0;

/* If infinity, set decpt to DTOA_OVERFLOW, if 0 set it to 1 */
/* coverity[assign_where_compare_meant] */
if (((word0(&u) & Exp_mask) == Exp_mask && (*decpt= DTOA_OVERFLOW)) ||
/* coverity[assign_where_compare_meant] */
(!dval(&u) && (*decpt= 1)))
{
/* Infinity, NaN, 0 */
Expand Down
3 changes: 2 additions & 1 deletion libmariadb/ma_errmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const char *client_errors[]=
/* 2057 */ "The number of parameters in bound buffers differs from number of columns in resultset",
/* 2059 */ "Can't connect twice. Already connected",
/* 2058 */ "Plugin %s could not be loaded: %s",
/* 2059 */ "An attribute with same name already exists"
/* 2059 */ "An attribute with same name already exists",
/* 2060 */ "Plugin doesn't support this function",
""
};
Expand All @@ -157,6 +157,7 @@ const char *mariadb_client_errors[] =
/* 5004 */ "File '%s' not found (Errcode: %d)",
/* 5005 */ "Error reading file '%s' (Errcode: %d)",
/* 5006 */ "Bulk operation without parameters is not supported",
/* 5007 */ "Invalid statement handle",
""
};

Expand Down
1 change: 1 addition & 0 deletions libmariadb/ma_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql)
ma_file= (MA_FILE *)malloc(sizeof(MA_FILE));
if (!ma_file)
{
fclose(fp);
my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0);
return NULL;
}
Expand Down
1 change: 0 additions & 1 deletion libmariadb/ma_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,6 @@ ulong ma_net_read(NET *net)
return packet_error;
if (_mariadb_uncompress((unsigned char*) net->buff + net->where_b, &packet_length, &complen))
{
len= packet_error;
net->error=2; /* caller will close socket */
net->last_errno=ER_NET_UNCOMPRESS_ERROR;
break;
Expand Down
40 changes: 23 additions & 17 deletions libmariadb/ma_pvio.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo)
return NULL;
}


/* coverity[var_deref_op] */
if (!(pvio= (MARIADB_PVIO *)calloc(1, sizeof(MARIADB_PVIO))))
{
PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0);
Expand Down Expand Up @@ -399,20 +399,23 @@ ssize_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length)
void ma_pvio_close(MARIADB_PVIO *pvio)
{
/* free internal structures and close connection */
#ifdef HAVE_TLS
if (pvio && pvio->ctls)
if (pvio)
{
ma_pvio_tls_close(pvio->ctls);
free(pvio->ctls);
}
#ifdef HAVE_TLS
if (pvio->ctls)
{
ma_pvio_tls_close(pvio->ctls);
free(pvio->ctls);
}
#endif
if (pvio && pvio->methods->close)
pvio->methods->close(pvio);
if (pvio && pvio->methods->close)
pvio->methods->close(pvio);

if (pvio->cache)
free(pvio->cache);
if (pvio->cache)
free(pvio->cache);

free(pvio);
free(pvio);
}
}
/* }}} */

Expand Down Expand Up @@ -460,13 +463,16 @@ ma_pvio_wait_async(struct mysql_async_context *b, enum enum_pvio_io_event event,
/* {{{ ma_pvio_wait_io_or_timeout */
int ma_pvio_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout)
{
if (IS_PVIO_ASYNC_ACTIVE(pvio))
return ma_pvio_wait_async(pvio->mysql->options.extension->async_context,
(is_read) ? VIO_IO_EVENT_READ : VIO_IO_EVENT_WRITE,
timeout);
if (pvio)
{
if (IS_PVIO_ASYNC_ACTIVE(pvio))
return ma_pvio_wait_async(pvio->mysql->options.extension->async_context,
(is_read) ? VIO_IO_EVENT_READ : VIO_IO_EVENT_WRITE,
timeout);

if (pvio && pvio->methods->wait_io_or_timeout)
return pvio->methods->wait_io_or_timeout(pvio, is_read, timeout);
if (pvio && pvio->methods->wait_io_or_timeout)
return pvio->methods->wait_io_or_timeout(pvio, is_read, timeout);
}
return 1;
}
/* }}} */
Expand Down
2 changes: 1 addition & 1 deletion libmariadb/ma_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ size_t mariadb_time_to_string(const MYSQL_TIME *tm, char *time_str, size_t len,
return 0;

if (digits == AUTO_SEC_PART_DIGITS)
digits= MIN((tm->second_part) ? SEC_PART_DIGITS : 0, 15);
digits= (tm->second_part) ? SEC_PART_DIGITS : 0;

switch(tm->time_type) {
case MYSQL_TIMESTAMP_DATE:
Expand Down
5 changes: 4 additions & 1 deletion libmariadb/mariadb_dyncol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,10 @@ dynamic_new_column_store(DYNAMIC_COLUMN *str,
goto err;
}
if (!column_count)
{
free(columns_order);
return ER_DYNCOL_OK;
}

memset(str->str, 0, fmt->fixed_hdr);
str->length= fmt->fixed_hdr;
Expand Down Expand Up @@ -2755,7 +2758,7 @@ dynamic_column_update_copy(DYNAMIC_COLUMN *str, PLAN *plan,
new_hdr->header_size + new_hdr->nmpool_size;
for (i= 0, j= 0; i < add_column_count || j < hdr->column_count; i++)
{
size_t UNINIT_VAR(first_offset);
size_t first_offset= 0;
uint start= j, end;

/*
Expand Down
Loading

0 comments on commit b0f2e4e

Please sign in to comment.