[sr-dev] git:master:0cc0b643: lib/binrpc: memset addr variable to avoind uninitialized fields

Daniel-Constantin Mierla miconda at gmail.com
Thu Nov 3 09:16:08 CET 2016


Module: kamailio
Branch: master
Commit: 0cc0b643ee6442a13f257e3d72b826f257501204
URL: https://github.com/kamailio/kamailio/commit/0cc0b643ee6442a13f257e3d72b826f257501204

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2016-11-03T08:50:13+01:00

lib/binrpc: memset addr variable to avoind uninitialized fields

---

Modified: lib/binrpc/binrpc_api.c

---

Diff:  https://github.com/kamailio/kamailio/commit/0cc0b643ee6442a13f257e3d72b826f257501204.diff
Patch: https://github.com/kamailio/kamailio/commit/0cc0b643ee6442a13f257e3d72b826f257501204.patch

---

diff --git a/lib/binrpc/binrpc_api.c b/lib/binrpc/binrpc_api.c
index 9145758..30cc003 100644
--- a/lib/binrpc/binrpc_api.c
+++ b/lib/binrpc/binrpc_api.c
@@ -13,11 +13,11 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
- 
+
 /**
  * send commands using binrpc
  *
@@ -67,7 +67,7 @@ static void (*internal_free)(void* ptr) = free;
 static char binrpc_last_errs[1024] = "";
 static int verbose = 0;
 
-char *binrpc_get_last_errs() 
+char *binrpc_get_last_errs()
 {
     return binrpc_last_errs;
 }
@@ -213,28 +213,29 @@ static int connect_tcpudp_socket(char* address, int port, int type)
 	struct sockaddr_in addr;
 	struct hostent* he;
 	int sock;
-	
+
 	sock=-1;
 	/* resolve destination */
 	he=gethostbyname(address);
 	if (he==0){
-		snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1, 
+		snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
 				"connect_tcpudp_socket: could not resolve %s", address);
 		goto error;
 	}
 	/* open socket*/
+	memset(&addr, 0, sizeof(struct sockaddr_in));
 	addr.sin_family=he->h_addrtype;
 	addr.sin_port=htons(port);
 	memcpy(&addr.sin_addr.s_addr, he->h_addr_list[0], he->h_length);
-	
+
 	sock = socket(he->h_addrtype, type, 0);
 	if (sock==-1){
-		snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1, 
+		snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
 			"connect_tcpudp_socket: socket: %s", strerror(errno));
 		goto error;
 	}
 	if (connect(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr))!=0){
-		snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1, 
+		snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
 				"connect_tcpudp_socket: connect: %s", strerror(errno));
 		goto error;
 	}
@@ -246,7 +247,7 @@ static int connect_tcpudp_socket(char* address, int port, int type)
 
 /* on exit cleanup */
 static void cleanup(struct sockaddr_un* mysun)
-{	
+{
 	if (mysun->sun_path[0] != '\0') {
 		if (unlink(mysun->sun_path) < 0) {
 			fprintf(stderr, "ERROR: failed to delete %s: %s\n",
@@ -259,7 +260,7 @@ int binrpc_open_connection(struct binrpc_handle* handle, char* name, int port, i
 		    char* reply_socket, char* sock_dir)
 {
 	struct sockaddr_un mysun;
-		
+
 	binrpc_last_errs[0] = '\0';
 	binrpc_last_errs[sizeof(binrpc_last_errs)-1] = '\0';  /* snprintf safe terminator */
 




More information about the sr-dev mailing list