Explorar o código

Initialize stack allocated memory

Some functions allocated memory on stack without clearing memory and
then send them on wire. This is not an issue, but valgrind reports this
as a problem so it is easy to miss real problem then.

Solution is to clear stack memory.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Jan Friesse %!s(int64=6) %!d(string=hai) anos
pai
achega
d8d7296bfd
Modificáronse 5 ficheiros con 17 adicións e 2 borrados
  1. 9 2
      exec/cpg.c
  2. 4 0
      exec/sync.c
  3. 1 0
      exec/totemknet.c
  4. 2 0
      exec/totempg.c
  5. 1 0
      exec/votequorum.c

+ 9 - 2
exec/cpg.c

@@ -1086,6 +1086,8 @@ static int cpg_node_joinleave_send (unsigned int pid, const mar_cpg_name_t *grou
 	struct iovec req_exec_cpg_iovec;
 	int result;
 
+	memset(&req_exec_cpg_procjoin, 0, sizeof(req_exec_cpg_procjoin));
+
 	memcpy(&req_exec_cpg_procjoin.group_name, group_name, sizeof(mar_cpg_name_t));
 	req_exec_cpg_procjoin.pid = pid;
 	req_exec_cpg_procjoin.reason = reason;
@@ -1490,7 +1492,8 @@ static int cpg_exec_send_joinlist(void)
 	int count = 0;
 	struct qb_list_head *iter;
 	struct qb_ipc_response_header *res;
- 	char *buf;
+	char *buf;
+	size_t buf_size;
 	struct join_list_entry *jle;
 	struct iovec req_exec_cpg_iovec;
 
@@ -1506,11 +1509,13 @@ static int cpg_exec_send_joinlist(void)
 	if (!count)
 		return 0;
 
-	buf = alloca(sizeof(struct qb_ipc_response_header) + sizeof(struct join_list_entry) * count);
+	buf_size = sizeof(struct qb_ipc_response_header) + sizeof(struct join_list_entry) * count;
+	buf = alloca(buf_size);
 	if (!buf) {
 		log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate joinlist buffer");
 		return -1;
 	}
+	memset(buf, 0, buf_size);
 
 	jle = (struct join_list_entry *)(buf + sizeof(struct qb_ipc_response_header));
 	res = (struct qb_ipc_response_header *)buf;
@@ -1977,6 +1982,8 @@ static void message_handler_req_lib_cpg_mcast (void *conn, const void *message)
 	}
 
 	if (error == CS_OK) {
+		memset(&req_exec_cpg_mcast, 0, sizeof(req_exec_cpg_mcast));
+
 		req_exec_cpg_mcast.header.size = sizeof(req_exec_cpg_mcast) + msglen;
 		req_exec_cpg_mcast.header.id = SERVICE_ID_MAKE(CPG_SERVICE,
 			MESSAGE_REQ_EXEC_CPG_MCAST);

+ 4 - 0
exec/sync.c

@@ -335,6 +335,8 @@ static void barrier_message_transmit (void)
 	struct iovec iovec;
 	struct req_exec_barrier_message req_exec_barrier_message;
 
+	memset(&req_exec_barrier_message, 0, sizeof(req_exec_barrier_message));
+
 	req_exec_barrier_message.header.size = sizeof (struct req_exec_barrier_message);
 	req_exec_barrier_message.header.id = MESSAGE_REQ_SYNC_BARRIER;
 
@@ -436,6 +438,8 @@ static void sync_servicelist_build_enter (
 	int res;
 	struct sync_callbacks sync_callbacks;
 
+	memset(&service_build, 0, sizeof(service_build));
+
 	my_state = SYNC_SERVICELIST_BUILD;
 	for (i = 0; i < member_list_entries; i++) {
 		my_processor_list[i].nodeid = member_list[i];

+ 1 - 0
exec/totemknet.c

@@ -1343,6 +1343,7 @@ int totemknet_member_add (
 	}
 
 	memset(&local_ss, 0, sizeof(local_ss));
+	memset(&remote_ss, 0, sizeof(remote_ss));
 	/* Casts to remove const */
 	totemip_totemip_to_sockaddr_convert((struct totem_ip_address *)member, port, &remote_ss, &addrlen);
 	totemip_totemip_to_sockaddr_convert((struct totem_ip_address *)local, port, &local_ss, &addrlen);

+ 2 - 0
exec/totempg.c

@@ -923,6 +923,8 @@ static int mcast_msg (
 		return(-1);
 	}
 
+	memset(&mcast, 0, sizeof(mcast));
+
 	mcast.header.version = 0;
 	for (i = 0; i < iov_len; ) {
 		mcast.fragmented = 0;

+ 1 - 0
exec/votequorum.c

@@ -1682,6 +1682,7 @@ static int votequorum_exec_send_nodeinfo(uint32_t nodeid)
 		return -1;
 	}
 
+	memset(&req_exec_quorum_nodeinfo, 0, sizeof(req_exec_quorum_nodeinfo));
 	req_exec_quorum_nodeinfo.nodeid = nodeid;
 	req_exec_quorum_nodeinfo.votes = node->votes;
 	req_exec_quorum_nodeinfo.expected_votes = node->expected_votes;