From 3992f262ca0b20e520ef169549ce5ecc9485c193 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Tue, 14 Jul 2015 16:17:50 +0300 Subject: [PATCH] Fixed Coverity defects --- server/core/dcb.c | 2 +- server/core/poll.c | 29 +++++++++++++--------- server/modules/protocol/mysql_backend.c | 17 ++++++++++--- server/modules/protocol/mysql_client.c | 7 ------ server/modules/routing/binlog/blr_file.c | 4 +-- server/modules/routing/binlog/blr_master.c | 4 +-- utils/skygw_utils.cc | 2 +- 7 files changed, 37 insertions(+), 28 deletions(-) diff --git a/server/core/dcb.c b/server/core/dcb.c index 17b1204b8..7c6fe2bb6 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -1070,7 +1070,7 @@ int dcb_read_SSL( goto return_n; } - gwbuf_rtrim(buffer,bufsize - n); + buffer = gwbuf_rtrim(buffer,bufsize - n); if(buffer == NULL) { goto return_n; diff --git a/server/core/poll.c b/server/core/poll.c index d25ea8329..0fb5e20e1 100644 --- a/server/core/poll.c +++ b/server/core/poll.c @@ -366,24 +366,29 @@ poll_remove_dcb(DCB *dcb) * Set state to NOPOLLING and remove dcb from poll set. */ dcb->state = DCB_STATE_NOPOLLING; + spinlock_release(&dcb->dcb_initlock); + /** * Only positive fds can be removed from epoll set. * Cloned DCBs are in the epoll set but do not have a valid file descriptor. - */ - if (dcb->fd > 0) { - spinlock_release(&dcb->dcb_initlock); - rc = epoll_ctl(epoll_fd, EPOLL_CTL_DEL, dcb->fd, &ev); - /** - * The poll_resolve_error function will always - * return 0 or crash. So if it returns non-zero result, - * things have gone wrong and we crash. */ - if (rc) rc = poll_resolve_error(dcb, errno, false); - if (rc) raise(SIGABRT); - /*< Set bit for each maxscale thread */ + if (dcb->fd > 0) { + rc = epoll_ctl(epoll_fd, EPOLL_CTL_DEL, dcb->fd, &ev); + /** + * The poll_resolve_error function will always + * return 0 or crash. So if it returns non-zero result, + * things have gone wrong and we crash. + */ + if (rc) rc = poll_resolve_error(dcb, errno, false); + if (rc) raise(SIGABRT); + } + else + { + rc = 0; + } + /*< Set bit for each maxscale thread */ bitmask_copy(&dcb->memdata.bitmask, poll_bitmask()); return rc; - } } /** diff --git a/server/modules/protocol/mysql_backend.c b/server/modules/protocol/mysql_backend.c index c43ed621a..c66fad274 100644 --- a/server/modules/protocol/mysql_backend.c +++ b/server/modules/protocol/mysql_backend.c @@ -172,6 +172,12 @@ static int gw_read_backend_event(DCB *dcb) { dcb->dcb_errhandle_called = true; goto return_rc; } + + if(dcb->session == NULL) + { + goto return_rc; + } + CHK_SESSION(dcb->session); /*< return only with complete session */ @@ -278,14 +284,13 @@ static int gw_read_backend_event(DCB *dcb) { void *rsession = NULL; SESSION *session = dcb->session; int receive_rc = 0; - - CHK_SESSION(session); if (session == NULL) { rc = 0; goto return_with_lock; } + CHK_SESSION(session); router = session->service->router; router_instance = session->service->router_instance; rsession = session->router_session; @@ -1055,7 +1060,13 @@ gw_backend_hangup(DCB *dcb) goto retblock; } session = dcb->session; - CHK_SESSION(session); + + if(session == NULL) + { + goto retblock; + } + + CHK_SESSION(session); rsession = session->router_session; router = session->service->router; diff --git a/server/modules/protocol/mysql_client.c b/server/modules/protocol/mysql_client.c index 8fcf13ad2..12dd51aae 100644 --- a/server/modules/protocol/mysql_client.c +++ b/server/modules/protocol/mysql_client.c @@ -1050,13 +1050,6 @@ int gw_read_client_event( (char*)((MYSQL_session *)dcb->data)->db); modutil_send_mysql_err_packet(dcb, 3, 0, 1049, "42000", fail_str); - }else if(auth_val == 3){ - /** Send error 1045 to client */ - fail_str = create_auth_fail_str((char *)((MYSQL_session *)dcb->data)->user, - dcb->remote, - (char*)((MYSQL_session *)dcb->data)->client_sha1, - (char*)((MYSQL_session *)dcb->data)->db,auth_val); - modutil_send_mysql_err_packet(dcb, 3, 0, 1045, "28000", fail_str); }else { /** Send error 1045 to client */ fail_str = create_auth_fail_str((char *)((MYSQL_session *)dcb->data)->user, diff --git a/server/modules/routing/binlog/blr_file.c b/server/modules/routing/binlog/blr_file.c index d9a62f00e..d67def773 100644 --- a/server/modules/routing/binlog/blr_file.c +++ b/server/modules/routing/binlog/blr_file.c @@ -671,7 +671,7 @@ blr_cache_response(ROUTER_INSTANCE *router, char *response, GWBUF *buf) char path[PATH_MAX+1], *ptr; int fd; - strcpy(path,get_datadir()); + strncpy(path,get_datadir(),PATH_MAX); strncat(path,"/",PATH_MAX); strncat(path, router->service->name, PATH_MAX); @@ -706,7 +706,7 @@ char path[PATH_MAX+1], *ptr; int fd; GWBUF *buf; - strcpy(path, get_datadir()); + strncpy(path, get_datadir(),PATH_MAX); strncat(path, "/", PATH_MAX); strncat(path, router->service->name, PATH_MAX); strncat(path, "/.cache/", PATH_MAX); diff --git a/server/modules/routing/binlog/blr_master.c b/server/modules/routing/binlog/blr_master.c index 86bee0b6b..14e7e1838 100644 --- a/server/modules/routing/binlog/blr_master.c +++ b/server/modules/routing/binlog/blr_master.c @@ -1249,8 +1249,8 @@ MYSQL_session *auth_info; if ((auth_info = calloc(1, sizeof(MYSQL_session))) == NULL) return NULL; - strncpy(auth_info->user, username,MYSQL_USER_MAXLEN+1); - strncpy(auth_info->db, database,MYSQL_DATABASE_MAXLEN+1); + strncpy(auth_info->user, username,MYSQL_USER_MAXLEN); + strncpy(auth_info->db, database,MYSQL_DATABASE_MAXLEN); gw_sha1_str((const uint8_t *)password, strlen(password), auth_info->client_sha1); return auth_info; diff --git a/utils/skygw_utils.cc b/utils/skygw_utils.cc index a5a97c1eb..5748cd613 100644 --- a/utils/skygw_utils.cc +++ b/utils/skygw_utils.cc @@ -379,8 +379,8 @@ mlist_cursor_t* mlist_cursor_init( c = (mlist_cursor_t *)calloc(1, sizeof(mlist_cursor_t)); if (c == NULL) { - goto return_cursor; simple_mutex_unlock(&list->mlist_mutex); + goto return_cursor; } c->mlcursor_chk_top = CHK_NUM_MLIST_CURSOR; c->mlcursor_chk_tail = CHK_NUM_MLIST_CURSOR;