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, errno,
strerror(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; return 0;
} }

View File

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

View File

@ -225,7 +225,9 @@ int gw_getsockerrno(
goto return_eno; 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:
return eno; return eno;

View File

@ -40,6 +40,7 @@
#include <httpd.h> #include <httpd.h>
#include <gw.h> #include <gw.h>
#include <modinfo.h> #include <modinfo.h>
#include <log_manager.h>
MODULE_INFO info = { MODULE_INFO info = {
MODULE_API_PROTOCOL, 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); dcb_printf(dcb, "Welcome to HTTPD MaxScale (c) %s\n\n", version_str);
if (strcmp(url, "/show") == 0) { if (strcmp(url, "/show") == 0) {
if (strlen(query_string)) { if (query_string && strlen(query_string)) {
if (strcmp(query_string, "dcb") == 0) if (strcmp(query_string, "dcb") == 0)
dprintAllDCBs(dcb); dprintAllDCBs(dcb);
if (strcmp(query_string, "session") == 0) if (strcmp(query_string, "session") == 0)
@ -327,23 +328,25 @@ int n_connect = 0;
else else
{ {
atomic_add(&dcb->stats.n_accepts, 1); atomic_add(&dcb->stats.n_accepts, 1);
client = dcb_alloc(DCB_ROLE_REQUEST_HANDLER);
client->fd = so; if((client = dcb_alloc(DCB_ROLE_REQUEST_HANDLER))){
client->remote = strdup(inet_ntoa(addr.sin_addr)); client->fd = so;
memcpy(&client->func, &MyObject, sizeof(GWPROTOCOL)); client->remote = strdup(inet_ntoa(addr.sin_addr));
memcpy(&client->func, &MyObject, sizeof(GWPROTOCOL));
/* we don't need the session */ /* we don't need the session */
client->session = NULL; client->session = NULL;
/* create the session data for HTTPD */ /* create the session data for HTTPD */
client_data = (HTTPD_session *)calloc(1, sizeof(HTTPD_session)); client_data = (HTTPD_session *)calloc(1, sizeof(HTTPD_session));
client->data = client_data; client->data = client_data;
if (poll_add_dcb(client) == -1) if (poll_add_dcb(client) == -1)
{ {
return n_connect; return n_connect;
}
n_connect++;
} }
n_connect++;
} }
} }
return n_connect; return n_connect;
@ -373,7 +376,8 @@ httpd_listen(DCB *listener, char *config)
{ {
struct sockaddr_in addr; struct sockaddr_in addr;
int one = 1; int one = 1;
int rc; int rc;
int syseno = 0;
memcpy(&listener->func, &MyObject, sizeof(GWPROTOCOL)); memcpy(&listener->func, &MyObject, sizeof(GWPROTOCOL));
if (!parse_bindconfig(config, 6442, &addr)) if (!parse_bindconfig(config, 6442, &addr))
@ -385,12 +389,16 @@ int rc;
} }
/* socket options */ /* socket options */
setsockopt(listener->fd, syseno = setsockopt(listener->fd,
SOL_SOCKET, SOL_SOCKET,
SO_REUSEADDR, SO_REUSEADDR,
(char *)&one, (char *)&one,
sizeof(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 */ /* set NONBLOCKING mode */
setnonblocking(listener->fd); setnonblocking(listener->fd);
@ -439,15 +447,19 @@ static int httpd_get_line(int sock, char *buf, int size) {
if (c == '\r') { if (c == '\r') {
n = recv(sock, &c, 1, MSG_PEEK); n = recv(sock, &c, 1, MSG_PEEK);
/* DEBUG printf("%02X\n", c); */ /* DEBUG printf("%02X\n", c); */
if ((n > 0) && (c == '\n')) if ((n > 0) && (c == '\n')) {
recv(sock, &c, 1, 0); if(recv(sock, &c, 1, 0) < 0){
else c = '\n';
}
} else {
c = '\n'; c = '\n';
}
} }
buf[i] = c; buf[i] = c;
i++; i++;
} else } else {
c = '\n'; c = '\n';
}
} }
buf[i] = '\0'; buf[i] = '\0';

View File

@ -940,6 +940,7 @@ int gw_MySQLListener(
char *config_bind) char *config_bind)
{ {
int l_so; int l_so;
int syseno = 0;
struct sockaddr_in serv_addr; struct sockaddr_in serv_addr;
struct sockaddr_un local_addr; struct sockaddr_un local_addr;
struct sockaddr *current_addr; struct sockaddr *current_addr;
@ -988,7 +989,10 @@ int gw_MySQLListener(
listen_dcb->fd = -1; listen_dcb->fd = -1;
// socket options // 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 // set NONBLOCKING mode
setnonblocking(l_so); setnonblocking(l_so);
@ -1101,6 +1105,7 @@ int gw_MySQLAccept(DCB *listener)
int sendbuf = GW_BACKEND_SO_SNDBUF; int sendbuf = GW_BACKEND_SO_SNDBUF;
socklen_t optlen = sizeof(sendbuf); socklen_t optlen = sizeof(sendbuf);
int eno = 0; int eno = 0;
int syseno = 0;
int i = 0; int i = 0;
CHK_DCB(listener); CHK_DCB(listener);
@ -1207,9 +1212,16 @@ int gw_MySQLAccept(DCB *listener)
#endif /* FAKE_CODE */ #endif /* FAKE_CODE */
/* set nonblocking */ /* set nonblocking */
sendbuf = GW_CLIENT_SO_SNDBUF; 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; 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); setnonblocking(c_sock);
client_dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER); client_dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER);

View File

@ -358,7 +358,8 @@ telnetd_listen(DCB *listener, char *config)
{ {
struct sockaddr_in addr; struct sockaddr_in addr;
int one = 1; int one = 1;
int rc; int rc;
int syseno = 0;
memcpy(&listener->func, &MyObject, sizeof(GWPROTOCOL)); memcpy(&listener->func, &MyObject, sizeof(GWPROTOCOL));
@ -372,7 +373,12 @@ int rc;
} }
// socket options // 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 // set NONBLOCKING mode
setnonblocking(listener->fd); setnonblocking(listener->fd);
// bind address and port // bind address and port