From 50a480701f4bf6885d3811e245a47d99661695d8 Mon Sep 17 00:00:00 2001 From: Milind Changire Date: Wed, 22 Nov 2017 17:03:11 +0530 Subject: 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 --- rpc/rpc-lib/src/rpcsvc.c | 55 ++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'rpc/rpc-lib/src/rpcsvc.c') 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); -- cgit