Browse code

lib/binrpc: memset addr variable to avoind uninitialized fields

(cherry picked from commit 0cc0b643ee6442a13f257e3d72b826f257501204)

Daniel-Constantin Mierla authored on 03/11/2016 07:50:13
Showing 1 changed files
... ...
@@ -13,11 +13,11 @@
13 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
  * GNU General Public License for more details.
15 15
  *
16
- * You should have received a copy of the GNU General Public License 
17
- * along with this program; if not, write to the Free Software 
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 19
  */
20
- 
20
+
21 21
 /**
22 22
  * send commands using binrpc
23 23
  *
... ...
@@ -67,7 +67,7 @@ static void (*internal_free)(void* ptr) = free;
67 67
 static char binrpc_last_errs[1024] = "";
68 68
 static int verbose = 0;
69 69
 
70
-char *binrpc_get_last_errs() 
70
+char *binrpc_get_last_errs()
71 71
 {
72 72
     return binrpc_last_errs;
73 73
 }
... ...
@@ -213,28 +213,29 @@ static int connect_tcpudp_socket(char* address, int port, int type)
213 213
 	struct sockaddr_in addr;
214 214
 	struct hostent* he;
215 215
 	int sock;
216
-	
216
+
217 217
 	sock=-1;
218 218
 	/* resolve destination */
219 219
 	he=gethostbyname(address);
220 220
 	if (he==0){
221
-		snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1, 
221
+		snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
222 222
 				"connect_tcpudp_socket: could not resolve %s", address);
223 223
 		goto error;
224 224
 	}
225 225
 	/* open socket*/
226
+	memset(&addr, 0, sizeof(struct sockaddr_in));
226 227
 	addr.sin_family=he->h_addrtype;
227 228
 	addr.sin_port=htons(port);
228 229
 	memcpy(&addr.sin_addr.s_addr, he->h_addr_list[0], he->h_length);
229
-	
230
+
230 231
 	sock = socket(he->h_addrtype, type, 0);
231 232
 	if (sock==-1){
232
-		snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1, 
233
+		snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
233 234
 			"connect_tcpudp_socket: socket: %s", strerror(errno));
234 235
 		goto error;
235 236
 	}
236 237
 	if (connect(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr))!=0){
237
-		snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1, 
238
+		snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
238 239
 				"connect_tcpudp_socket: connect: %s", strerror(errno));
239 240
 		goto error;
240 241
 	}
... ...
@@ -246,7 +247,7 @@ error:
246 247
 
247 248
 /* on exit cleanup */
248 249
 static void cleanup(struct sockaddr_un* mysun)
249
-{	
250
+{
250 251
 	if (mysun->sun_path[0] != '\0') {
251 252
 		if (unlink(mysun->sun_path) < 0) {
252 253
 			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
259 260
 		    char* reply_socket, char* sock_dir)
260 261
 {
261 262
 	struct sockaddr_un mysun;
262
-		
263
+
263 264
 	binrpc_last_errs[0] = '\0';
264 265
 	binrpc_last_errs[sizeof(binrpc_last_errs)-1] = '\0';  /* snprintf safe terminator */
265 266