From: Julius Bünger Date: Tue, 17 Feb 2015 14:04:44 +0000 (+0000) Subject: - fixed memory and coding issues X-Git-Tag: initial-import-from-subversion-38251~2299 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0ea0ba9874d6252da26a2ae20090ffe095559cf9;p=oweals%2Fgnunet.git - fixed memory and coding issues --- diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 0ec80d3a4..3d61de21b 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c @@ -1065,39 +1065,51 @@ handle_client_seed (void *cls, { struct GNUNET_RPS_CS_SeedMessage *in_msg; struct GNUNET_PeerIdentity *peers; + uint32_t num_peers; uint32_t i; - if (sizeof (struct GNUNET_RPS_CS_SeedMessage) < ntohs (message->size)) + if (sizeof (struct GNUNET_RPS_CS_SeedMessage) > ntohs (message->size)) { GNUNET_break_op (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); } + in_msg = (struct GNUNET_RPS_CS_SeedMessage *) message; + num_peers = ntohl (in_msg->num_peers); + peers = (struct GNUNET_PeerIdentity *) &in_msg[1]; + //peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); + //memcpy (peers, &in_msg[1], num_peers * sizeof (struct GNUNET_PeerIdentity)); + if ((ntohs (message->size) - sizeof (struct GNUNET_RPS_CS_SeedMessage)) / - sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers)) + sizeof (struct GNUNET_PeerIdentity) != num_peers) { GNUNET_break_op (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); } - in_msg = (struct GNUNET_RPS_CS_SeedMessage *) message; - peers = (struct GNUNET_PeerIdentity *) &message[1]; - LOG (GNUNET_ERROR_TYPE_DEBUG, "Client seeded peers:\n"); - print_peer_list (peers, ntohl (in_msg->num_peers)); + print_peer_list (peers, num_peers); + + // TODO check for validity of ids - for ( i = 0 ; i < ntohl (in_msg->num_peers) ; i++ ) + for (i = 0 ; i < num_peers ; i++) + { LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating samplers with seed %" PRIX32 ": %s\n", + i, GNUNET_i2s (&peers[i])); + RPS_sampler_update (prot_sampler, &peers[i]); RPS_sampler_update (client_sampler, &peers[i]); + } + + //GNUNET_free (peers); GNUNET_SERVER_receive_done (client, - GNUNET_OK); + GNUNET_OK); }