Fixes to Coverity defects:

72643
72645
72655
72656
72657
72658
72664
72698
72712
This commit is contained in:
Markus Makela 2014-11-12 19:02:37 +02:00
parent b5445bdf63
commit fc5c3943e8
6 changed files with 89 additions and 34 deletions

View File

@ -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;
}

View File

@ -30,7 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <poll.h>
#include <dcb.h>
@ -44,6 +44,7 @@ test1()
{
DCB *dcb;
int result;
int eno = 0;
/* Poll tests */
ss_dfprintf(stderr,
@ -51,20 +52,32 @@ 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);
if(poll_add_dcb(dcb) != 0){
ss_dfprintf(stderr, "Error on function call: poll_add_dcb\n");
if(dcb->fd < 0){
ss_dfprintf(stderr, "\nError on function call: socket() returned %d: %s\n",errno,strerror(errno));
return 1;
}
if(poll_remove_dcb(dcb) != 0){
ss_dfprintf(stderr, "Error on function call: poll_remove_dcb\n");
if((eno = poll_add_dcb(dcb)) != 0){
ss_dfprintf(stderr, "\nError on function call: poll_add_dcb() returned %d.\n",eno);
return 1;
}
if(poll_add_dcb(dcb) != 0){
ss_dfprintf(stderr, "Error on function call: poll_add_dcb\n");
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;
}

View File

@ -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;

View File

@ -40,6 +40,7 @@
#include <httpd.h>
#include <gw.h>
#include <modinfo.h>
#include <log_manager.h>
MODULE_INFO info = {
MODULE_API_PROTOCOL,
@ -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,23 +328,25 @@ 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)
{
return n_connect;
}
n_connect++;
}
n_connect++;
}
}
return n_connect;
@ -373,7 +376,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 +389,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",syseno,strerror(syseno));
return 0;
}
/* set NONBLOCKING mode */
setnonblocking(listener->fd);
@ -439,15 +447,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';

View File

@ -940,6 +940,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;
@ -988,7 +989,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",syseno,strerror(syseno))));
}
// set NONBLOCKING mode
setnonblocking(l_so);
@ -1101,6 +1105,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);
@ -1207,9 +1212,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",syseno,strerror(syseno))));
}
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",syseno,strerror(syseno))));
}
setnonblocking(c_sock);
client_dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER);

View File

@ -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",syseno,strerror(syseno))));
return 0;
}
// set NONBLOCKING mode
setnonblocking(listener->fd);
// bind address and port