[sr-dev] git:master:080bffeb: jsonrpcs: safety vars init and release checks
Daniel-Constantin Mierla
miconda at gmail.com
Fri Jul 7 09:54:45 CEST 2017
Module: kamailio
Branch: master
Commit: 080bffeb53181131f8fb8fab0ddcb771bbdd37dc
URL: https://github.com/kamailio/kamailio/commit/080bffeb53181131f8fb8fab0ddcb771bbdd37dc
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-07-07T09:48:53+02:00
jsonrpcs: safety vars init and release checks
---
Modified: src/modules/jsonrpcs/jsonrpcs_mod.c
Modified: src/modules/jsonrpcs/jsonrpcs_sock.c
---
Diff: https://github.com/kamailio/kamailio/commit/080bffeb53181131f8fb8fab0ddcb771bbdd37dc.diff
Patch: https://github.com/kamailio/kamailio/commit/080bffeb53181131f8fb8fab0ddcb771bbdd37dc.patch
---
diff --git a/src/modules/jsonrpcs/jsonrpcs_mod.c b/src/modules/jsonrpcs/jsonrpcs_mod.c
index 7e0502964b..cd99ad8a01 100644
--- a/src/modules/jsonrpcs/jsonrpcs_mod.c
+++ b/src/modules/jsonrpcs/jsonrpcs_mod.c
@@ -756,6 +756,7 @@ static int jsonrpc_struct_add(srjson_t *jnode, char* fmt, ...)
while(*fmt) {
mname.s = va_arg(ap, char*);
mname.len = (mname.s?strlen(mname.s):0);
+ if(mname.s==NULL) mname.s = "";
if (*fmt == '{' || *fmt == '[') {
void_ptr = va_arg(ap, void**);
diff --git a/src/modules/jsonrpcs/jsonrpcs_sock.c b/src/modules/jsonrpcs/jsonrpcs_sock.c
index fbc9f8f5e6..c61fa6da28 100644
--- a/src/modules/jsonrpcs/jsonrpcs_sock.c
+++ b/src/modules/jsonrpcs/jsonrpcs_sock.c
@@ -388,9 +388,9 @@ int jsonrpc_dgram_init_server(jsonrpc_dgram_sockaddr_t *addr,
return 0;
err_both:
- close(socks->tx_sock);
+ if(socks->tx_sock>=0) close(socks->tx_sock);
err_rx:
- close(socks->rx_sock);
+ if(socks->rx_sock>=0) close(socks->rx_sock);
return -1;
}
@@ -528,7 +528,7 @@ static int jsonrpc_dgram_send_data(int fd, char* buf, unsigned int len,
{
int n;
unsigned int optlen = sizeof(int);
- int optval;
+ int optval = 0;
if(len == 0 || tolen ==0)
return -1;
@@ -536,7 +536,9 @@ static int jsonrpc_dgram_send_data(int fd, char* buf, unsigned int len,
/*LM_DBG("destination address length is %i\n", tolen);*/
n=sendto(fd, buf, len, 0, to, tolen);
if(n!=len) {
- getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (int*)&optval, &optlen);
+ if(getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (int*)&optval, &optlen)==-1) {
+ LM_ERR("getsockopt failed\n");
+ }
LM_ERR("failed to send the response - ret: %d, len: %d (%d),"
" err: %d - %s)\n",
n, len, optval, errno, strerror(errno));
More information about the sr-dev
mailing list