summaryrefslogtreecommitdiffstats
path: root/rpc/rpc-lib/src/rpcsvc.c
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 /rpc/rpc-lib/src/rpcsvc.c
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>
Diffstat (limited to 'rpc/rpc-lib/src/rpcsvc.c')
-rw-r--r--rpc/rpc-lib/src/rpcsvc.c55
1 files changed, 35 insertions, 20 deletions
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);