Fixes to Coverity defects.

This commit is contained in:
Markus Makela 2015-06-25 06:01:33 +03:00
parent 62b951e66e
commit e5d9abbdcb
5 changed files with 29 additions and 66 deletions

View File

@ -939,10 +939,10 @@ int dcb_read_n(
goto return_n;
}
if (b == 0 && nread == 0)
if (b == 0)
{
/** Handle closed client socket */
if (dcb_isclient(dcb))
if (nread == 0 && dcb_isclient(dcb))
{
char c;
int l_errno = 0;
@ -964,11 +964,6 @@ int dcb_read_n(
n = 0;
goto return_n;
}
else if (b == 0)
{
n = 0;
goto return_n;
}
dcb->last_read = hkheartbeat;
@ -1208,6 +1203,10 @@ int dcb_read_SSL(
}
gwbuf_rtrim(buffer,bufsize - n);
if(buffer == NULL)
{
goto return_n;
}
#ifdef SS_DEBUG
skygw_log_write(LD,"%lu SSL: Truncated buffer from %d to %d bytes. "
"Read %d bytes, %d bytes waiting.\n",pthread_self(),
@ -1234,9 +1233,6 @@ int dcb_read_SSL(
/*< Append read data to the gwbuf */
*head = gwbuf_append(*head, buffer);
rc = ioctl(dcb->fd, FIONREAD, &b);
pending = SSL_pending(dcb->ssl);
} /*< while (true) */
return_n:
return nread;
@ -1639,16 +1635,6 @@ dcb_write_SSL(DCB *dcb, GWBUF *queue)
dcb,
STRDCBSTATE(dcb->state),
dcb->fd,ssl_errno)));
if(ssl_errno == SSL_ERROR_SSL ||
ssl_errno == SSL_ERROR_SYSCALL)
{
while((ssl_errno = ERR_get_error()) != 0)
{
char errbuf[140];
ERR_error_string(ssl_errno,errbuf);
skygw_log_write(LD,"%s",errbuf);
}
}
break;
}
}
@ -1666,19 +1652,19 @@ dcb_write_SSL(DCB *dcb, GWBUF *queue)
STRDCBSTATE(dcb->state),
dcb->fd,
ssl_errno)));
if(ssl_errno == SSL_ERROR_SSL)
if(ssl_errno == SSL_ERROR_SSL || ssl_errno == SSL_ERROR_SYSCALL)
{
if(ssl_errno == SSL_ERROR_SYSCALL)
{
skygw_log_write(LE,"%d:%s",errno,strerror(errno));
}
do
{
char errbuf[140];
ERR_error_string(ssl_errno,errbuf);
skygw_log_write(LE,"%s",errbuf);
skygw_log_write(LE,"%d:%s",ssl_errno,errbuf);
}while((ssl_errno = ERR_get_error()) != 0);
}
if(ssl_errno == SSL_ERROR_SYSCALL)
{
skygw_log_write(LE,"%d:%s",errno,strerror(errno));
}
}
else if(w == 0)
{
@ -1686,7 +1672,7 @@ dcb_write_SSL(DCB *dcb, GWBUF *queue)
{
char errbuf[140];
ERR_error_string(ssl_errno,errbuf);
skygw_log_write(LE,"%s",errbuf);
skygw_log_write(LE,"%d:%s",ssl_errno,errbuf);
}while((ssl_errno = ERR_get_error()) != 0);
}
}
@ -1695,16 +1681,14 @@ dcb_write_SSL(DCB *dcb, GWBUF *queue)
break;
}
}while(w <= 0);
/*
* Pull the number of bytes we have written from
* queue with have.
*/
if(w == -1)
if(w <= 0)
{
while((queue = GWBUF_CONSUME_ALL(queue)));
break;
}
else
{
/** Remove written bytes from the queue */
queue = gwbuf_consume(queue, w);
LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG,
@ -1733,38 +1717,6 @@ dcb_write_SSL(DCB *dcb, GWBUF *queue)
}
} /* if (dcb->writeq) */
if (saved_errno != 0 &&
queue != NULL &&
saved_errno != EAGAIN &&
saved_errno != EWOULDBLOCK)
{
bool dolog = true;
/**
* Do not log if writing COM_QUIT to backend failed.
*/
if (GWBUF_IS_TYPE_MYSQL(queue))
{
uint8_t* data = GWBUF_DATA(queue);
if (data[4] == 0x01)
{
dolog = false;
}
}
if (dolog)
{
LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG,
"%lu [dcb_write] Writing to %s socket failed due %d, %s.",
pthread_self(),
dcb_isclient(dcb) ? "client" : "backend server",
saved_errno,
strerror(saved_errno))));
}
spinlock_release(&dcb->writeqlock);
return 0;
}
spinlock_release(&dcb->writeqlock);
if (dcb->high_water && dcb->writeqlen > dcb->high_water && below_water)

View File

@ -228,6 +228,12 @@ unsigned int randval;
MAXKEYS key;
char secret_file[PATH_MAX + 10];
if(strlen(path) > PATH_MAX)
{
skygw_log_write(LOGFILE_ERROR,"Error: Pathname too long.");
return 1;
}
sprintf(secret_file,"%s/.secrets",path);
/* Open for writing | Create | Truncate the file for writing */

View File

@ -268,7 +268,7 @@ GWPROTOCOL *funcs;
/* Save authentication data to file cache */
char *ptr, path[PATH_MAX + 1];
int mkdir_rval = 0;
strcpy(path, get_cachedir());
strncpy(path, get_cachedir(),PATH_MAX);
strncat(path, "/", 4096);
strncat(path, service->name, PATH_MAX);
if (access(path, R_OK) == -1)

View File

@ -155,7 +155,10 @@ startMonitor(void *arg,void* opt)
else if(!strcmp(params->name,"script"))
{
if(handle->script)
{
free(handle->script);
handle->script = NULL;
}
if(access(params->value,X_OK) == 0)
{

View File

@ -396,6 +396,7 @@ mlist_cursor_t* mlist_cursor_init(
if (c == NULL) {
goto return_cursor;
simple_mutex_unlock(&list->mlist_mutex);
}
c->mlcursor_chk_top = CHK_NUM_MLIST_CURSOR;
c->mlcursor_chk_tail = CHK_NUM_MLIST_CURSOR;
@ -581,6 +582,7 @@ bool mlist_cursor_move_to_first(
simple_mutex_lock(&list->mlist_mutex, true);
if (mc->mlcursor_list->mlist_deleted) {
simple_mutex_unlock(&list->mlist_mutex);
return false;
}
/** Set position point to first node */