From d8c53b12a818ff7cf82d06a1a69c395bdef85ee6 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 8 Jul 2016 17:20:23 +0000 Subject: -avoid calling memcpy() with NULL argument, even if len is 0 --- src/vpn/gnunet-helper-vpn-windows.c | 12 +++++----- src/vpn/gnunet-service-vpn.c | 46 ++++++++++++++++++------------------- src/vpn/vpn_api.c | 4 ++-- 3 files changed, 31 insertions(+), 31 deletions(-) (limited to 'src/vpn') diff --git a/src/vpn/gnunet-helper-vpn-windows.c b/src/vpn/gnunet-helper-vpn-windows.c index 94af0e8e8..a9596752a 100644 --- a/src/vpn/gnunet-helper-vpn-windows.c +++ b/src/vpn/gnunet-helper-vpn-windows.c @@ -922,7 +922,7 @@ attempt_read_tap (struct io_facility * input_facility, hdr = (struct GNUNET_MessageHeader *) output_facility->buffer; size = input_facility->buffer_size + sizeof (struct GNUNET_MessageHeader); - memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), + GNUNET_memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), input_facility->buffer, input_facility->buffer_size); @@ -978,7 +978,7 @@ attempt_read_tap (struct io_facility * input_facility, hdr = (struct GNUNET_MessageHeader *) output_facility->buffer; size = input_facility->buffer_size + sizeof (struct GNUNET_MessageHeader); - memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), + GNUNET_memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), input_facility->buffer, input_facility->buffer_size); @@ -1012,7 +1012,7 @@ attempt_read_tap (struct io_facility * input_facility, hdr = (struct GNUNET_MessageHeader *) output_facility->buffer; size = input_facility->buffer_size + sizeof (struct GNUNET_MessageHeader); - memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), + GNUNET_memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), input_facility->buffer, input_facility->buffer_size); @@ -1105,7 +1105,7 @@ partial_read_iostate_ready: * send it our via STDOUT. Is that possible at the moment? */ /* hand over this buffers content and strip gnunet message header */ - memcpy (output_facility->buffer, + GNUNET_memcpy (output_facility->buffer, input_facility->buffer + sizeof (struct GNUNET_MessageHeader), input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader)); output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader); @@ -1169,7 +1169,7 @@ partial_read_iostate_ready: IOSTATE_WAITING == output_facility->facility_state) && input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader)) { /* hand over this buffers content and strip gnunet message header */ - memcpy (output_facility->buffer, + GNUNET_memcpy (output_facility->buffer, input_facility->buffer + sizeof(struct GNUNET_MessageHeader), input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader)); output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader); @@ -1196,7 +1196,7 @@ partial_read_iostate_ready: } return TRUE; case IOSTATE_RESUME: /* Our buffer was filled already but our write facility was busy. */ - memcpy (output_facility->buffer, + GNUNET_memcpy (output_facility->buffer, input_facility->buffer + sizeof (struct GNUNET_MessageHeader), input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader)); output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader); diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index 8741aa719..ae7cb57cc 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c @@ -453,29 +453,29 @@ get_channel_key_from_ips (int af, /* the GNUnet hashmap only uses the first sizeof(unsigned int) of the hash, so we put the ports in there (and hope for few collisions) */ off = (char*) key; - memcpy (off, &source_port, sizeof (uint16_t)); + GNUNET_memcpy (off, &source_port, sizeof (uint16_t)); off += sizeof (uint16_t); - memcpy (off, &destination_port, sizeof (uint16_t)); + GNUNET_memcpy (off, &destination_port, sizeof (uint16_t)); off += sizeof (uint16_t); switch (af) { case AF_INET: - memcpy (off, source_ip, sizeof (struct in_addr)); + GNUNET_memcpy (off, source_ip, sizeof (struct in_addr)); off += sizeof (struct in_addr); - memcpy (off, destination_ip, sizeof (struct in_addr)); + GNUNET_memcpy (off, destination_ip, sizeof (struct in_addr)); off += sizeof (struct in_addr); break; case AF_INET6: - memcpy (off, source_ip, sizeof (struct in6_addr)); + GNUNET_memcpy (off, source_ip, sizeof (struct in6_addr)); off += sizeof (struct in6_addr); - memcpy (off, destination_ip, sizeof (struct in6_addr)); + GNUNET_memcpy (off, destination_ip, sizeof (struct in6_addr)); off += sizeof (struct in6_addr); break; default: GNUNET_assert (0); break; } - memcpy (off, &protocol, sizeof (uint8_t)); + GNUNET_memcpy (off, &protocol, sizeof (uint8_t)); /* off += sizeof (uint8_t); */ } @@ -518,7 +518,7 @@ send_client_reply (struct GNUNET_SERVER_Client *client, res->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_CLIENT_USE_IP); res->result_af = htonl (result_af); res->request_id = request_id; - memcpy (&res[1], addr, rlen); + GNUNET_memcpy (&res[1], addr, rlen); GNUNET_SERVER_notification_context_add (nc, client); GNUNET_SERVER_notification_context_unicast (nc, client, @@ -618,7 +618,7 @@ send_to_peer_notify_callback (void *cls, size_t size, void *buf) ts->tmq_tail, tnq); ts->tmq_length--; - memcpy (buf, tnq->msg, tnq->len); + GNUNET_memcpy (buf, tnq->msg, tnq->len); ret = tnq->len; GNUNET_free (tnq); if (NULL != (tnq = ts->tmq_head)) @@ -1162,7 +1162,7 @@ route_packet (struct DestinationEntry *destination, usm->source_port = (ntohs (udp->source_port) < 32000) ? udp->source_port : 0; usm->destination_port = udp->destination_port; usm->service_descriptor = destination->details.service_destination.service_descriptor; - memcpy (&usm[1], + GNUNET_memcpy (&usm[1], &udp[1], payload_length - sizeof (struct GNUNET_TUN_UdpHeader)); } @@ -1204,7 +1204,7 @@ route_packet (struct DestinationEntry *destination, default: GNUNET_assert (0); } - memcpy (payload, + GNUNET_memcpy (payload, &udp[1], payload_length - sizeof (struct GNUNET_TUN_UdpHeader)); } @@ -1232,7 +1232,7 @@ route_packet (struct DestinationEntry *destination, tsm->reserved = htonl (0); tsm->service_descriptor = destination->details.service_destination.service_descriptor; tsm->tcp_header = *tcp; - memcpy (&tsm[1], + GNUNET_memcpy (&tsm[1], &tcp[1], payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); } @@ -1273,7 +1273,7 @@ route_packet (struct DestinationEntry *destination, default: GNUNET_assert (0); } - memcpy (payload, + GNUNET_memcpy (payload, &tcp[1], payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); } @@ -1297,7 +1297,7 @@ route_packet (struct DestinationEntry *destination, tdm->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT); tdm->reserved = htonl (0); tdm->tcp_header = *tcp; - memcpy (&tdm[1], + GNUNET_memcpy (&tdm[1], &tcp[1], payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); } @@ -1379,7 +1379,7 @@ route_packet (struct DestinationEntry *destination, tnq->len = mlen; ism->header.size = htons ((uint16_t) mlen); /* finally, copy payload (if there is any left...) */ - memcpy (&ism[1], + GNUNET_memcpy (&ism[1], &icmp[1], payload_length - sizeof (struct GNUNET_TUN_IcmpHeader)); } @@ -1532,7 +1532,7 @@ route_packet (struct DestinationEntry *destination, default: GNUNET_assert (0); } - memcpy (payload, + GNUNET_memcpy (payload, &icmp[1], payload_length - sizeof (struct GNUNET_TUN_IcmpHeader)); } @@ -1799,7 +1799,7 @@ receive_icmp_back (void *cls, &ts->destination_ip.v4, &ts->source_ip.v4); *icmp = i2v->icmp_header; - memcpy (&icmp[1], + GNUNET_memcpy (&icmp[1], &i2v[1], mlen); /* For some ICMP types, we need to adjust (make up) the payload here. @@ -1936,7 +1936,7 @@ receive_icmp_back (void *cls, &ts->destination_ip.v6, &ts->source_ip.v6); *icmp = i2v->icmp_header; - memcpy (&icmp[1], + GNUNET_memcpy (&icmp[1], &i2v[1], mlen); @@ -2152,7 +2152,7 @@ receive_udp_back (void *cls, udp, &reply[1], mlen); - memcpy (&udp[1], + GNUNET_memcpy (&udp[1], &reply[1], mlen); (void) GNUNET_HELPER_send (helper_handle, @@ -2196,7 +2196,7 @@ receive_udp_back (void *cls, GNUNET_TUN_calculate_udp6_checksum (ipv6, udp, &reply[1], mlen); - memcpy (&udp[1], + GNUNET_memcpy (&udp[1], &reply[1], mlen); (void) GNUNET_HELPER_send (helper_handle, @@ -2302,7 +2302,7 @@ receive_tcp_back (void *cls, tcp, &data[1], mlen); - memcpy (&tcp[1], + GNUNET_memcpy (&tcp[1], &data[1], mlen); (void) GNUNET_HELPER_send (helper_handle, @@ -2341,7 +2341,7 @@ receive_tcp_back (void *cls, tcp, &data[1], mlen); - memcpy (&tcp[1], + GNUNET_memcpy (&tcp[1], &data[1], mlen); (void) GNUNET_HELPER_send (helper_handle, @@ -2683,7 +2683,7 @@ service_redirect_to_ip (void *cls, de = GNUNET_new (struct DestinationEntry); de->is_service = GNUNET_NO; de->details.exit_destination.af = addr_af; - memcpy (&de->details.exit_destination.ip, + GNUNET_memcpy (&de->details.exit_destination.ip, &msg[1], alen); get_destination_key_from_ip (result_af, diff --git a/src/vpn/vpn_api.c b/src/vpn/vpn_api.c index adba0a666..42fe7d4b4 100644 --- a/src/vpn/vpn_api.c +++ b/src/vpn/vpn_api.c @@ -278,7 +278,7 @@ send_request (struct GNUNET_VPN_RedirectionRequest *rr) rip->result_af = htonl (rr->result_af); rip->addr_af = htonl (rr->addr_af); rip->request_id = rr->request_id = ++vh->request_id_gen; - memcpy (&rip[1], + GNUNET_memcpy (&rip[1], rr->addr, alen); } @@ -483,7 +483,7 @@ GNUNET_VPN_redirect_to_ip (struct GNUNET_VPN_Handle *vh, rr->expiration_time = expiration_time; rr->result_af = result_af; rr->addr_af = addr_af; - memcpy (&rr[1], + GNUNET_memcpy (&rr[1], addr, alen); GNUNET_CONTAINER_DLL_insert_tail (vh->rr_head, -- cgit v1.2.3