diff --git a/CMakeLists.txt b/CMakeLists.txt index 00604caa2..a9d8cbef1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,11 @@ if(GCOV) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov") endif() +if(FAKE_CODE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFAKE_CODE") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFAKE_CODE") +endif() + subdirs(MYSQL_DIR_ALL ${MYSQL_DIR}) foreach(DIR ${MYSQL_DIR_ALL}) include_directories(${DIR}) diff --git a/query_classifier/test/canonical_tests/canonizer.c b/query_classifier/test/canonical_tests/canonizer.c index d44478399..6df5f0049 100644 --- a/query_classifier/test/canonical_tests/canonizer.c +++ b/query_classifier/test/canonical_tests/canonizer.c @@ -57,21 +57,19 @@ int main(int argc, char** argv) { fgets(readbuff,4092,infile); psize = strlen(readbuff); - if(psize > 4092){ - continue; - } - qbuff = gwbuf_alloc(psize + 7); - *(qbuff->sbuf->data + 0) = (unsigned char)psize; - *(qbuff->sbuf->data + 1) = (unsigned char)(psize>>8); - *(qbuff->sbuf->data + 2) = (unsigned char)(psize>>16); - *(qbuff->sbuf->data + 4) = 0x03; - memcpy(qbuff->start + 5,readbuff,psize + 1); - parse_query(qbuff); - tok = skygw_get_canonical(qbuff); - fprintf(outfile,"%s\n",tok); - free(tok); - gwbuf_free(qbuff); - + if(psize < 4092){ + qbuff = gwbuf_alloc(psize + 7); + *(qbuff->sbuf->data + 0) = (unsigned char)psize; + *(qbuff->sbuf->data + 1) = (unsigned char)(psize>>8); + *(qbuff->sbuf->data + 2) = (unsigned char)(psize>>16); + *(qbuff->sbuf->data + 4) = 0x03; + memcpy(qbuff->start + 5,readbuff,psize + 1); + parse_query(qbuff); + tok = skygw_get_canonical(qbuff); + fprintf(outfile,"%s\n",tok); + free(tok); + gwbuf_free(qbuff); + } } fclose(infile); fclose(outfile); diff --git a/server/core/secrets.c b/server/core/secrets.c index 2e09f661f..a27ee0d3b 100644 --- a/server/core/secrets.c +++ b/server/core/secrets.c @@ -269,7 +269,17 @@ MAXKEYS key; errno, strerror(errno)))); } - chmod(secret_file, S_IRUSR); + + if( chmod(secret_file, S_IRUSR) < 0) + { + LOGIF(LE, (skygw_log_write_flush( + LOGFILE_ERROR, + "Error : failed to change the permissions of the" + "secret file [%s]. Error %d, %s.", + secret_file, + errno, + strerror(errno)))); + } return 0; } diff --git a/server/core/test/testpoll.c b/server/core/test/testpoll.c index 4d8d4cc04..a790e03a6 100644 --- a/server/core/test/testpoll.c +++ b/server/core/test/testpoll.c @@ -30,7 +30,7 @@ #include #include #include - +#include #include #include @@ -44,6 +44,7 @@ test1() { DCB *dcb; int result; + int eno = 0; /* Poll tests */ ss_dfprintf(stderr, @@ -51,10 +52,35 @@ int result; poll_init(); ss_dfprintf(stderr, "\t..done\nAdd a DCB"); dcb = dcb_alloc(DCB_ROLE_SERVICE_LISTENER); + + if(dcb == NULL){ + ss_dfprintf(stderr, "\nError on function call: dcb_alloc() returned NULL.\n"); + return 1; + } + dcb->fd = socket(AF_UNIX, SOCK_STREAM, 0); - poll_add_dcb(dcb); - poll_remove_dcb(dcb); - poll_add_dcb(dcb); + + if(dcb->fd < 0){ + ss_dfprintf(stderr, "\nError on function call: socket() returned %d: %s\n",errno,strerror(errno)); + return 1; + } + + + if((eno = poll_add_dcb(dcb)) != 0){ + ss_dfprintf(stderr, "\nError on function call: poll_add_dcb() returned %d.\n",eno); + return 1; + } + + if((eno = poll_remove_dcb(dcb)) != 0){ + ss_dfprintf(stderr, "\nError on function call: poll_remove_dcb() returned %d.\n",eno); + return 1; + } + + if((eno = poll_add_dcb(dcb)) != 0){ + ss_dfprintf(stderr, "\nError on function call: poll_add_dcb() returned %d.\n",eno); + return 1; + } + ss_dfprintf(stderr, "\t..done\nStart wait for events."); sleep(10); poll_shutdown(); diff --git a/server/core/utils.c b/server/core/utils.c index 71c7888ed..937341f26 100644 --- a/server/core/utils.c +++ b/server/core/utils.c @@ -225,7 +225,9 @@ int gw_getsockerrno( goto return_eno; } - getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&eno, &elen); + if(getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&eno, &elen) != 0){ + eno = 0; + } return_eno: return eno; diff --git a/server/modules/filter/hint/hintparser.c b/server/modules/filter/hint/hintparser.c index df0888508..0d0e47dcb 100644 --- a/server/modules/filter/hint/hintparser.c +++ b/server/modules/filter/hint/hintparser.c @@ -435,7 +435,7 @@ HINT_MODE mode = HM_EXECUTE; token_free(tok); } /*< while */ - if (tok->token == TOK_EOL) + if ( tok && tok->token == TOK_EOL) { token_free(tok); } diff --git a/server/modules/filter/qlafilter.c b/server/modules/filter/qlafilter.c index 0f669b060..2f25ba1fb 100644 --- a/server/modules/filter/qlafilter.c +++ b/server/modules/filter/qlafilter.c @@ -398,7 +398,7 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue) QLA_INSTANCE *my_instance = (QLA_INSTANCE *)instance; QLA_SESSION *my_session = (QLA_SESSION *)session; char *ptr; -int length; +int length = 0; struct tm t; struct timeval tv; diff --git a/server/modules/filter/tee.c b/server/modules/filter/tee.c index 94dc29ea0..43f7075c5 100644 --- a/server/modules/filter/tee.c +++ b/server/modules/filter/tee.c @@ -415,8 +415,9 @@ GWBUF *clone = NULL; modutil_MySQL_Query(queue, &dummy, &length, &residual); clone = gwbuf_clone(queue); my_session->residual = residual; - free(ptr); + } + free(ptr); } /* Pass the query downstream */ diff --git a/server/modules/filter/topfilter.c b/server/modules/filter/topfilter.c index e4c16b2ba..eaf471910 100644 --- a/server/modules/filter/topfilter.c +++ b/server/modules/filter/topfilter.c @@ -314,10 +314,10 @@ char *remote, *user; else my_session->userName = NULL; my_session->active = 1; - if (my_instance->source && strcmp(my_session->clientHost, + if (my_instance->source && my_session->clientHost && strcmp(my_session->clientHost, my_instance->source)) my_session->active = 0; - if (my_instance->user && strcmp(my_session->userName, + if (my_instance->user && my_session->userName && strcmp(my_session->userName, my_instance->user)) my_session->active = 0; diff --git a/server/modules/protocol/httpd.c b/server/modules/protocol/httpd.c index 9729fb99d..f5e347924 100644 --- a/server/modules/protocol/httpd.c +++ b/server/modules/protocol/httpd.c @@ -40,6 +40,7 @@ #include #include #include +#include MODULE_INFO info = { MODULE_API_PROTOCOL, @@ -171,7 +172,7 @@ HTTPD_session *client_data = NULL; j++; } - while (!ISspace(buf[j]) && (i < sizeof(url) - 1) && (j < sizeof(buf))) { + while (!ISspace(buf[j]) && (i < sizeof(url) - 1) && (j < sizeof(buf) - 1)) { url[i] = buf[j]; i++; j++; } @@ -236,7 +237,7 @@ HTTPD_session *client_data = NULL; dcb_printf(dcb, "Welcome to HTTPD MaxScale (c) %s\n\n", version_str); if (strcmp(url, "/show") == 0) { - if (strlen(query_string)) { + if (query_string && strlen(query_string)) { if (strcmp(query_string, "dcb") == 0) dprintAllDCBs(dcb); if (strcmp(query_string, "session") == 0) @@ -327,25 +328,29 @@ int n_connect = 0; else { atomic_add(&dcb->stats.n_accepts, 1); - client = dcb_alloc(DCB_ROLE_REQUEST_HANDLER); - client->fd = so; - client->remote = strdup(inet_ntoa(addr.sin_addr)); - memcpy(&client->func, &MyObject, sizeof(GWPROTOCOL)); + + if((client = dcb_alloc(DCB_ROLE_REQUEST_HANDLER))){ + client->fd = so; + client->remote = strdup(inet_ntoa(addr.sin_addr)); + memcpy(&client->func, &MyObject, sizeof(GWPROTOCOL)); - /* we don't need the session */ - client->session = NULL; + /* we don't need the session */ + client->session = NULL; - /* create the session data for HTTPD */ - client_data = (HTTPD_session *)calloc(1, sizeof(HTTPD_session)); - client->data = client_data; + /* create the session data for HTTPD */ + client_data = (HTTPD_session *)calloc(1, sizeof(HTTPD_session)); + client->data = client_data; - if (poll_add_dcb(client) == -1) - { - return n_connect; + if (poll_add_dcb(client) == -1) + { + close(so); + return n_connect; + } + n_connect++; } - n_connect++; } } + return n_connect; } @@ -373,7 +378,8 @@ httpd_listen(DCB *listener, char *config) { struct sockaddr_in addr; int one = 1; -int rc; +int rc; +int syseno = 0; memcpy(&listener->func, &MyObject, sizeof(GWPROTOCOL)); if (!parse_bindconfig(config, 6442, &addr)) @@ -385,12 +391,16 @@ int rc; } /* socket options */ - setsockopt(listener->fd, + syseno = setsockopt(listener->fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one)); + if(syseno != 0){ + skygw_log_write_flush(LOGFILE_ERROR,"Error: Failed to set socket options. Error %d: %s",errno,strerror(errno)); + return 0; + } /* set NONBLOCKING mode */ setnonblocking(listener->fd); @@ -439,15 +449,19 @@ static int httpd_get_line(int sock, char *buf, int size) { if (c == '\r') { n = recv(sock, &c, 1, MSG_PEEK); /* DEBUG printf("%02X\n", c); */ - if ((n > 0) && (c == '\n')) - recv(sock, &c, 1, 0); - else + if ((n > 0) && (c == '\n')) { + if(recv(sock, &c, 1, 0) < 0){ + c = '\n'; + } + } else { c = '\n'; + } } buf[i] = c; i++; - } else + } else { c = '\n'; + } } buf[i] = '\0'; diff --git a/server/modules/protocol/mysql_client.c b/server/modules/protocol/mysql_client.c index e248373a2..99747fd7e 100644 --- a/server/modules/protocol/mysql_client.c +++ b/server/modules/protocol/mysql_client.c @@ -948,6 +948,7 @@ int gw_MySQLListener( char *config_bind) { int l_so; + int syseno = 0; struct sockaddr_in serv_addr; struct sockaddr_un local_addr; struct sockaddr *current_addr; @@ -996,7 +997,10 @@ int gw_MySQLListener( listen_dcb->fd = -1; // socket options - setsockopt(l_so, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one)); + if((syseno = setsockopt(l_so, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one))) != 0){ + LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,"Error: Failed to set socket options. Error %d: %s",errno,strerror(errno)))); + } + // set NONBLOCKING mode setnonblocking(l_so); @@ -1109,6 +1113,7 @@ int gw_MySQLAccept(DCB *listener) int sendbuf = GW_BACKEND_SO_SNDBUF; socklen_t optlen = sizeof(sendbuf); int eno = 0; + int syseno = 0; int i = 0; CHK_DCB(listener); @@ -1215,9 +1220,16 @@ int gw_MySQLAccept(DCB *listener) #endif /* FAKE_CODE */ /* set nonblocking */ sendbuf = GW_CLIENT_SO_SNDBUF; - setsockopt(c_sock, SOL_SOCKET, SO_SNDBUF, &sendbuf, optlen); + + if((syseno = setsockopt(c_sock, SOL_SOCKET, SO_SNDBUF, &sendbuf, optlen)) != 0){ + LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,"Error: Failed to set socket options. Error %d: %s",errno,strerror(errno)))); + } + sendbuf = GW_CLIENT_SO_RCVBUF; - setsockopt(c_sock, SOL_SOCKET, SO_RCVBUF, &sendbuf, optlen); + + if((syseno = setsockopt(c_sock, SOL_SOCKET, SO_RCVBUF, &sendbuf, optlen)) != 0){ + LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,"Error: Failed to set socket options. Error %d: %s",errno,strerror(errno)))); + } setnonblocking(c_sock); client_dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER); diff --git a/server/modules/protocol/telnetd.c b/server/modules/protocol/telnetd.c index 8250c9caf..e8c208c20 100644 --- a/server/modules/protocol/telnetd.c +++ b/server/modules/protocol/telnetd.c @@ -358,7 +358,8 @@ telnetd_listen(DCB *listener, char *config) { struct sockaddr_in addr; int one = 1; -int rc; +int rc; +int syseno = 0; memcpy(&listener->func, &MyObject, sizeof(GWPROTOCOL)); @@ -372,7 +373,12 @@ int rc; } // socket options - setsockopt(listener->fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one)); + syseno = setsockopt(listener->fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one)); + + if(syseno != 0){ + LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,"Error: Failed to set socket options. Error %d: %s",errno,strerror(errno)))); + return 0; + } // set NONBLOCKING mode setnonblocking(listener->fd); // bind address and port diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index 6b475a4e9..eca2a5615 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -1540,12 +1540,12 @@ skygw_query_type_t is_read_tmp_table( } } - for(i = 0; i