summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilind Changire <mchangir@redhat.com>2017-11-22 17:03:11 +0530
committerRaghavendra G <rgowdapp@redhat.com>2017-11-22 16:58:39 +0000
commit50a480701f4bf6885d3811e245a47d99661695d8 (patch)
treec3e4fb52830734fa3c2da0ac2edd93886941d3f8
parent8d53be68d8fb4272f0c88fef0a00dad452b941de (diff)
rpc-lib: coverity fixes
Scan URL: https://download.gluster.org/pub/gluster/glusterfs/static-analysis/master/glusterfs-coverity/2017-11-10-0f524f07/html/ ID: 9 (BAD_SHIFT) ID: 58 (CHECKED_RETURN) ID: 98 (DEAD_CODE) ID: 249, 250, 251, 252 (MIXED_ENUMS) ID: 289, 297 (NULL_RETURNS) ID: 609, 613, 622, 644, 653, 655 (UNUSED_VALUE) ID: 432 (RESOURCE_LEAK) Change-Id: I2349877214dd38b789e08b74be05539f09b751b9 BUG: 789278 Signed-off-by: Milind Changire <mchangir@redhat.com>
-rw-r--r--rpc/rpc-lib/src/rpc-clnt.c12
-rw-r--r--rpc/rpc-lib/src/rpc-transport.c29
-rw-r--r--rpc/rpc-lib/src/rpcsvc-auth.c8
-rw-r--r--rpc/rpc-lib/src/rpcsvc.c55
-rw-r--r--rpc/rpc-lib/src/rpcsvc.h4
5 files changed, 70 insertions, 38 deletions
diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c
index 2fc3b38df2c..adb8e3d4a60 100644
--- a/rpc/rpc-lib/src/rpc-clnt.c
+++ b/rpc/rpc-lib/src/rpc-clnt.c
@@ -946,6 +946,11 @@ rpc_clnt_notify (rpc_transport_t *trans, void *mydata,
clnt->mydata = NULL;
ret = clnt->notifyfn (clnt, clnt_mydata,
RPC_CLNT_DESTROY, NULL);
+ if (ret < 0) {
+ gf_log (trans->name, GF_LOG_WARNING,
+ "client notify handler returned error "
+ "while handling RPC_CLNT_DESTROY");
+ }
}
rpc_clnt_destroy (clnt);
ret = 0;
@@ -1667,6 +1672,13 @@ rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog,
if (conn->connected == 0 && !rpc->disabled) {
ret = rpc_transport_connect (conn->trans,
conn->config.remote_port);
+ if (ret < 0) {
+ gf_log (conn->name, GF_LOG_WARNING,
+ "error returned while attempting to "
+ "connect to host:%s, port:%d",
+ conn->config.remote_host,
+ conn->config.remote_port);
+ }
}
ret = rpc_transport_submit_request (conn->trans, &req);
diff --git a/rpc/rpc-lib/src/rpc-transport.c b/rpc/rpc-lib/src/rpc-transport.c
index 4c3d5279fe1..40b5917f9b8 100644
--- a/rpc/rpc-lib/src/rpc-transport.c
+++ b/rpc/rpc-lib/src/rpc-transport.c
@@ -175,6 +175,7 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name)
volume_opt_list_t *vol_opt = NULL;
gf_boolean_t bind_insecure = _gf_false;
xlator_t *this = NULL;
+ gf_boolean_t success = _gf_false;
GF_VALIDATE_OR_GOTO("rpc-transport", options, fail);
GF_VALIDATE_OR_GOTO("rpc-transport", ctx, fail);
@@ -357,26 +358,32 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name)
GF_FREE (name);
- return return_trans;
+ success = _gf_true;
fail:
- if (trans) {
- GF_FREE (trans->name);
+ if (!success) {
+ if (trans) {
+ GF_FREE (trans->name);
- if (trans->dl_handle)
- dlclose (trans->dl_handle);
+ if (trans->dl_handle)
+ dlclose (trans->dl_handle);
- GF_FREE (trans);
- }
+ GF_FREE (trans);
+ }
- GF_FREE (name);
+ GF_FREE (name);
- if (vol_opt && !list_empty (&vol_opt->list)) {
- list_del_init (&vol_opt->list);
+ return_trans = NULL;
+ }
+
+ if (vol_opt) {
+ if (!list_empty (&vol_opt->list)) {
+ list_del_init (&vol_opt->list);
+ }
GF_FREE (vol_opt);
}
- return NULL;
+ return return_trans;
}
diff --git a/rpc/rpc-lib/src/rpcsvc-auth.c b/rpc/rpc-lib/src/rpcsvc-auth.c
index b7d6c2216ef..bfff0bc557f 100644
--- a/rpc/rpc-lib/src/rpcsvc-auth.c
+++ b/rpc/rpc-lib/src/rpcsvc-auth.c
@@ -482,15 +482,13 @@ rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen)
switch (ret) {
case _gf_true:
- result = RPCSVC_AUTH_ACCEPT;
autharr[count] = auth->auth->authnum;
++count;
break;
- case _gf_false:
- result = RPCSVC_AUTH_REJECT;
- break;
+
default:
- result = RPCSVC_AUTH_DONTCARE;
+ /* nothing to do */
+ break;
}
}
diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c
index ffc6b763590..cd8e3f18b0a 100644
--- a/rpc/rpc-lib/src/rpcsvc.c
+++ b/rpc/rpc-lib/src/rpcsvc.c
@@ -46,10 +46,15 @@
struct rpcsvc_program gluster_dump_prog;
-#define rpcsvc_alloc_request(svc, request) \
- do { \
- request = (rpcsvc_request_t *) mem_get ((svc)->rxpool); \
- memset (request, 0, sizeof (rpcsvc_request_t)); \
+#define rpcsvc_alloc_request(svc, request) \
+ do { \
+ request = (rpcsvc_request_t *)mem_get ((svc)->rxpool); \
+ if (request) { \
+ memset (request, 0, sizeof (rpcsvc_request_t)); \
+ } else { \
+ gf_log ("rpcsvc", GF_LOG_ERROR, \
+ "error getting memory for rpc request"); \
+ } \
} while (0)
rpcsvc_listener_t *
@@ -1353,6 +1358,10 @@ rpcsvc_submit_generic (rpcsvc_request_t *req, struct iovec *proghdr,
proghdr, hdrcount,
payload, payloadcount);
UNLOCK (&drc->lock);
+ if (ret < 0) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR,
+ "failed to cache reply");
+ }
}
ret = rpcsvc_transport_submit (trans, &recordhdr, 1, proghdr, hdrcount,
@@ -1665,11 +1674,6 @@ rpcsvc_program_unregister (rpcsvc_t *svc, rpcsvc_program_t *program)
}
pthread_rwlock_unlock (&svc->rpclock);
- if (prog == NULL) {
- ret = -1;
- goto out;
- }
-
gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Program unregistered: %s, Num: %d,"
" Ver: %d, Port: %d", prog->progname, prog->prognum,
prog->progver, prog->progport);
@@ -2046,9 +2050,13 @@ rpcsvc_program_register (rpcsvc_t *svc, rpcsvc_program_t *program,
newprog->ownthread = _gf_false;
if (newprog->ownthread) {
- gf_thread_create (&newprog->thread, NULL,
- rpcsvc_request_handler,
- newprog, "rpcsvcrh");
+ ret = gf_thread_create (&newprog->thread, NULL,
+ rpcsvc_request_handler,
+ newprog, "rpcsvcrh");
+ if (ret != 0) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR,
+ "error creating request handler thread");
+ }
}
pthread_rwlock_wrlock (&svc->rpclock);
@@ -2884,17 +2892,24 @@ rpcsvc_match_subnet_v4 (const char *addrtok, const char *ipaddr)
goto out;
/* Find the network socket addr of subnet pattern */
- slash = strchr (netaddr, '/');
- *slash = '\0';
if (inet_pton (AF_INET, netaddr, &sin2.sin_addr) == 0)
goto out;
- /*
- * Find the IPv4 network mask in network byte order.
- * IMP: String slash+1 is already validated, it cant have value
- * more than IPv4_ADDR_SIZE (32).
- */
- prefixlen = (uint32_t) atoi (slash + 1);
+ slash = strchr (netaddr, '/');
+ if (slash) {
+ *slash = '\0';
+ /*
+ * Find the IPv4 network mask in network byte order.
+ * IMP: String slash+1 is already validated, it cant have value
+ * more than IPv4_ADDR_SIZE (32).
+ */
+ prefixlen = (uint32_t) atoi (slash + 1);
+ if (prefixlen > 31)
+ goto out;
+ } else {
+ goto out;
+ }
+
shift = IPv4_ADDR_SIZE - prefixlen;
mask.sin_addr.s_addr = htonl ((uint32_t)~0 << shift);
diff --git a/rpc/rpc-lib/src/rpcsvc.h b/rpc/rpc-lib/src/rpcsvc.h
index 1fdbc69c7ad..533e6bde374 100644
--- a/rpc/rpc-lib/src/rpcsvc.h
+++ b/rpc/rpc-lib/src/rpcsvc.h
@@ -514,8 +514,8 @@ rpcsvc_auth_check (rpcsvc_t *svc, char *volname, char *ipaddr);
extern int
rpcsvc_transport_privport_check (rpcsvc_t *svc, char *volname, uint16_t port);
-#define rpcsvc_request_seterr(req, err) (req)->rpc_err = err
-#define rpcsvc_request_set_autherr(req, err) (req)->auth_err = err
+#define rpcsvc_request_seterr(req, err) ((req)->rpc_err = (int)(err))
+#define rpcsvc_request_set_autherr(req, err) ((req)->auth_err = (int)(err))
extern int rpcsvc_submit_vectors (rpcsvc_request_t *req);