Fixes to Coverity tasks : 73267, 72686, 72672

Cleaned up warnings, and added checks to malloc return values and error log writes in case of failures.
This commit is contained in:
VilhoRaatikka
2014-10-31 15:25:59 +02:00
parent 848c7aa0b8
commit 00fded016b
9 changed files with 123 additions and 32 deletions

View File

@ -1300,14 +1300,33 @@ static int gw_change_user(
backend->session->client->remote,
password_set,
"");
if (message == NULL)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Creating error message failed.")));
rv = 0;
goto retblock;
}
/** TODO: Add custom message indicating that retry would probably help */
buf = modutil_create_mysql_err_msg(1, 0, 1045, "28000", message);
free(message);
if (buf == NULL)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Creating buffer for error message failed.")));
rv = 0;
goto retblock;
}
/** Set flags that help router to identify session commans reply */
gwbuf_set_type(buf, GWBUF_TYPE_MYSQL);
gwbuf_set_type(buf, GWBUF_TYPE_SESCMD_RESPONSE);
gwbuf_set_type(buf, GWBUF_TYPE_RESPONSE_END);
/** Create an incoming event for backend DCB */
poll_add_epollin_event_to_dcb(backend, buf);
poll_add_epollin_event_to_dcb(backend, gwbuf_clone(buf));
gwbuf_free(buf);
rv = 0;
} else {
rv = gw_send_change_user_to_backend(database, username, client_sha1, backend_protocol);
@ -1318,6 +1337,8 @@ static int gw_change_user(
strcpy(current_session->db, database);
memcpy(current_session->client_sha1, client_sha1, sizeof(current_session->client_sha1));
}
retblock:
gwbuf_free(queue);
return rv;

View File

@ -2106,19 +2106,34 @@ char *create_auth_fail_str(
else
db_len = 0;
if (db_len>0)
if (db_len > 0)
{
ferrstr = "Access denied for user '%s'@'%s' (using password: %s) to database '%s'";
}
else
{
ferrstr = "Access denied for user '%s'@'%s' (using password: %s)";
}
errstr = (char *)malloc(strlen(username)+strlen(ferrstr)+strlen(hostaddr)+strlen("YES")-6 + db_len + ((db_len > 0) ? (strlen(" to database ") +2) : 0) + 1);
if (errstr != NULL) {
if (db_len>0)
sprintf(errstr, ferrstr, username, hostaddr, (*sha1 == '\0' ? "NO" : "YES"), db);
else
sprintf(errstr, ferrstr, username, hostaddr, (*sha1 == '\0' ? "NO" : "YES"));
if (errstr == NULL)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Memory allocation failed due to %s.",
strerror(errno))));
goto retblock;
}
if (db_len > 0)
{
sprintf(errstr, ferrstr, username, hostaddr, (*sha1 == '\0' ? "NO" : "YES"), db);
}
else
{
sprintf(errstr, ferrstr, username, hostaddr, (*sha1 == '\0' ? "NO" : "YES"));
}
retblock:
return errstr;
}