diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-08 17:20:23 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-08 17:20:23 +0000 |
commit | d8c53b12a818ff7cf82d06a1a69c395bdef85ee6 (patch) | |
tree | 0ebb0db416c157fcfde51a941185819dd12d51fd /src/nat | |
parent | 5184c17d32a39c928c2a0fec3ee1ad098bbaa562 (diff) | |
download | gnunet-d8c53b12a818ff7cf82d06a1a69c395bdef85ee6.tar.gz gnunet-d8c53b12a818ff7cf82d06a1a69c395bdef85ee6.zip |
-avoid calling memcpy() with NULL argument, even if len is 0
Diffstat (limited to 'src/nat')
-rw-r--r-- | src/nat/gnunet-helper-nat-client-windows.c | 20 | ||||
-rw-r--r-- | src/nat/gnunet-helper-nat-server-windows.c | 16 | ||||
-rw-r--r-- | src/nat/nat.c | 4 | ||||
-rw-r--r-- | src/nat/test_nat.c | 2 |
4 files changed, 21 insertions, 21 deletions
diff --git a/src/nat/gnunet-helper-nat-client-windows.c b/src/nat/gnunet-helper-nat-client-windows.c index fd2fbd716..89dad9e7b 100644 --- a/src/nat/gnunet-helper-nat-client-windows.c +++ b/src/nat/gnunet-helper-nat-client-windows.c | |||
@@ -265,14 +265,14 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other) | |||
265 | ip_pkt.dst_ip = other->s_addr; | 265 | ip_pkt.dst_ip = other->s_addr; |
266 | ip_pkt.checksum = | 266 | ip_pkt.checksum = |
267 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); | 267 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); |
268 | memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); | 268 | GNUNET_memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); |
269 | off += sizeof (struct ip_header); | 269 | off += sizeof (struct ip_header); |
270 | 270 | ||
271 | icmp_pkt.type = ICMP_TIME_EXCEEDED; | 271 | icmp_pkt.type = ICMP_TIME_EXCEEDED; |
272 | icmp_pkt.code = 0; | 272 | icmp_pkt.code = 0; |
273 | icmp_pkt.checksum = 0; | 273 | icmp_pkt.checksum = 0; |
274 | icmp_pkt.unused = 0; | 274 | icmp_pkt.unused = 0; |
275 | memcpy (&packet[off], &icmp_pkt, sizeof (struct icmp_ttl_exceeded_header)); | 275 | GNUNET_memcpy (&packet[off], &icmp_pkt, sizeof (struct icmp_ttl_exceeded_header)); |
276 | off += sizeof (struct icmp_ttl_exceeded_header); | 276 | off += sizeof (struct icmp_ttl_exceeded_header); |
277 | 277 | ||
278 | /* ip header of the presumably 'lost' udp packet */ | 278 | /* ip header of the presumably 'lost' udp packet */ |
@@ -289,7 +289,7 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other) | |||
289 | ip_pkt.dst_ip = dummy.s_addr; | 289 | ip_pkt.dst_ip = dummy.s_addr; |
290 | ip_pkt.checksum = | 290 | ip_pkt.checksum = |
291 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); | 291 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); |
292 | memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); | 292 | GNUNET_memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); |
293 | off += sizeof (struct ip_header); | 293 | off += sizeof (struct ip_header); |
294 | 294 | ||
295 | /* build UDP header */ | 295 | /* build UDP header */ |
@@ -297,7 +297,7 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other) | |||
297 | udp_pkt.dst_port = htons (NAT_TRAV_PORT); | 297 | udp_pkt.dst_port = htons (NAT_TRAV_PORT); |
298 | udp_pkt.length = htons (port); | 298 | udp_pkt.length = htons (port); |
299 | udp_pkt.crc = 0; | 299 | udp_pkt.crc = 0; |
300 | memcpy (&packet[off], &udp_pkt, sizeof (struct udp_header)); | 300 | GNUNET_memcpy (&packet[off], &udp_pkt, sizeof (struct udp_header)); |
301 | off += sizeof (struct udp_header); | 301 | off += sizeof (struct udp_header); |
302 | 302 | ||
303 | /* no go back to calculate ICMP packet checksum */ | 303 | /* no go back to calculate ICMP packet checksum */ |
@@ -306,7 +306,7 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other) | |||
306 | ((uint16_t *) & packet[off], | 306 | ((uint16_t *) & packet[off], |
307 | sizeof (struct icmp_ttl_exceeded_header) + | 307 | sizeof (struct icmp_ttl_exceeded_header) + |
308 | sizeof (struct ip_header) + sizeof (struct udp_header))); | 308 | sizeof (struct ip_header) + sizeof (struct udp_header))); |
309 | memcpy (&packet[sizeof (struct ip_header)], &icmp_pkt, | 309 | GNUNET_memcpy (&packet[sizeof (struct ip_header)], &icmp_pkt, |
310 | sizeof (struct icmp_ttl_exceeded_header)); | 310 | sizeof (struct icmp_ttl_exceeded_header)); |
311 | 311 | ||
312 | memset (&dst, 0, sizeof (dst)); | 312 | memset (&dst, 0, sizeof (dst)); |
@@ -359,7 +359,7 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other) | |||
359 | ip_pkt.dst_ip = other->s_addr; | 359 | ip_pkt.dst_ip = other->s_addr; |
360 | ip_pkt.checksum = | 360 | ip_pkt.checksum = |
361 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); | 361 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); |
362 | memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); | 362 | GNUNET_memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); |
363 | off += sizeof (ip_pkt); | 363 | off += sizeof (ip_pkt); |
364 | 364 | ||
365 | /* icmp reply: time exceeded */ | 365 | /* icmp reply: time exceeded */ |
@@ -367,7 +367,7 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other) | |||
367 | icmp_ttl.code = 0; | 367 | icmp_ttl.code = 0; |
368 | icmp_ttl.checksum = 0; | 368 | icmp_ttl.checksum = 0; |
369 | icmp_ttl.unused = 0; | 369 | icmp_ttl.unused = 0; |
370 | memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header)); | 370 | GNUNET_memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header)); |
371 | off += sizeof (struct icmp_ttl_exceeded_header); | 371 | off += sizeof (struct icmp_ttl_exceeded_header); |
372 | 372 | ||
373 | /* ip header of the presumably 'lost' udp packet */ | 373 | /* ip header of the presumably 'lost' udp packet */ |
@@ -384,7 +384,7 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other) | |||
384 | ip_pkt.checksum = 0; | 384 | ip_pkt.checksum = 0; |
385 | ip_pkt.checksum = | 385 | ip_pkt.checksum = |
386 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); | 386 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); |
387 | memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); | 387 | GNUNET_memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); |
388 | off += sizeof (struct ip_header); | 388 | off += sizeof (struct ip_header); |
389 | 389 | ||
390 | icmp_echo.type = ICMP_ECHO; | 390 | icmp_echo.type = ICMP_ECHO; |
@@ -394,7 +394,7 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other) | |||
394 | icmp_echo.checksum = | 394 | icmp_echo.checksum = |
395 | htons (calc_checksum | 395 | htons (calc_checksum |
396 | ((uint16_t *) & icmp_echo, sizeof (struct icmp_echo_header))); | 396 | ((uint16_t *) & icmp_echo, sizeof (struct icmp_echo_header))); |
397 | memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header)); | 397 | GNUNET_memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header)); |
398 | 398 | ||
399 | /* no go back to calculate ICMP packet checksum */ | 399 | /* no go back to calculate ICMP packet checksum */ |
400 | off = sizeof (struct ip_header); | 400 | off = sizeof (struct ip_header); |
@@ -403,7 +403,7 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other) | |||
403 | ((uint16_t *) & packet[off], | 403 | ((uint16_t *) & packet[off], |
404 | sizeof (struct icmp_ttl_exceeded_header) + | 404 | sizeof (struct icmp_ttl_exceeded_header) + |
405 | sizeof (struct ip_header) + sizeof (struct icmp_echo_header))); | 405 | sizeof (struct ip_header) + sizeof (struct icmp_echo_header))); |
406 | memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header)); | 406 | GNUNET_memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header)); |
407 | 407 | ||
408 | memset (&dst, 0, sizeof (dst)); | 408 | memset (&dst, 0, sizeof (dst)); |
409 | dst.sin_family = AF_INET; | 409 | dst.sin_family = AF_INET; |
diff --git a/src/nat/gnunet-helper-nat-server-windows.c b/src/nat/gnunet-helper-nat-server-windows.c index 97e04e5f1..c8e1193e4 100644 --- a/src/nat/gnunet-helper-nat-server-windows.c +++ b/src/nat/gnunet-helper-nat-server-windows.c | |||
@@ -284,7 +284,7 @@ send_icmp_echo (const struct in_addr *my_ip) | |||
284 | ip_pkt.dst_ip = dummy.s_addr; | 284 | ip_pkt.dst_ip = dummy.s_addr; |
285 | ip_pkt.checksum = | 285 | ip_pkt.checksum = |
286 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); | 286 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); |
287 | memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); | 287 | GNUNET_memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); |
288 | off += sizeof (struct ip_header); | 288 | off += sizeof (struct ip_header); |
289 | 289 | ||
290 | icmp_echo.type = ICMP_ECHO; | 290 | icmp_echo.type = ICMP_ECHO; |
@@ -294,7 +294,7 @@ send_icmp_echo (const struct in_addr *my_ip) | |||
294 | icmp_echo.checksum = | 294 | icmp_echo.checksum = |
295 | htons (calc_checksum | 295 | htons (calc_checksum |
296 | ((uint16_t *) & icmp_echo, sizeof (struct icmp_echo_header))); | 296 | ((uint16_t *) & icmp_echo, sizeof (struct icmp_echo_header))); |
297 | memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header)); | 297 | GNUNET_memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header)); |
298 | off += sizeof (struct icmp_echo_header); | 298 | off += sizeof (struct icmp_echo_header); |
299 | 299 | ||
300 | memset (&dst, 0, sizeof (dst)); | 300 | memset (&dst, 0, sizeof (dst)); |
@@ -377,10 +377,10 @@ process_icmp_response () | |||
377 | return; | 377 | return; |
378 | } | 378 | } |
379 | off = 0; | 379 | off = 0; |
380 | memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header)); | 380 | GNUNET_memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header)); |
381 | off += sizeof (struct ip_header); | 381 | off += sizeof (struct ip_header); |
382 | memcpy (&source_ip, &ip_pkt.src_ip, sizeof (source_ip)); | 382 | GNUNET_memcpy (&source_ip, &ip_pkt.src_ip, sizeof (source_ip)); |
383 | memcpy (&icmp_ttl, &buf[off], sizeof (struct icmp_ttl_exceeded_header)); | 383 | GNUNET_memcpy (&icmp_ttl, &buf[off], sizeof (struct icmp_ttl_exceeded_header)); |
384 | off += sizeof (struct icmp_ttl_exceeded_header); | 384 | off += sizeof (struct icmp_ttl_exceeded_header); |
385 | if ((ICMP_TIME_EXCEEDED != icmp_ttl.type) || (0 != icmp_ttl.code)) | 385 | if ((ICMP_TIME_EXCEEDED != icmp_ttl.type) || (0 != icmp_ttl.code)) |
386 | { | 386 | { |
@@ -388,7 +388,7 @@ process_icmp_response () | |||
388 | return; | 388 | return; |
389 | } | 389 | } |
390 | /* skip 2nd IP header */ | 390 | /* skip 2nd IP header */ |
391 | memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header)); | 391 | GNUNET_memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header)); |
392 | off += sizeof (struct ip_header); | 392 | off += sizeof (struct ip_header); |
393 | 393 | ||
394 | switch (ip_pkt.proto) | 394 | switch (ip_pkt.proto) |
@@ -403,7 +403,7 @@ process_icmp_response () | |||
403 | return; | 403 | return; |
404 | } | 404 | } |
405 | /* grab ICMP ECHO content */ | 405 | /* grab ICMP ECHO content */ |
406 | memcpy (&icmp_echo, &buf[off], sizeof (struct icmp_echo_header)); | 406 | GNUNET_memcpy (&icmp_echo, &buf[off], sizeof (struct icmp_echo_header)); |
407 | port = (uint16_t) ntohl (icmp_echo.reserved); | 407 | port = (uint16_t) ntohl (icmp_echo.reserved); |
408 | break; | 408 | break; |
409 | case IPPROTO_UDP: | 409 | case IPPROTO_UDP: |
@@ -415,7 +415,7 @@ process_icmp_response () | |||
415 | return; | 415 | return; |
416 | } | 416 | } |
417 | /* grab UDP content */ | 417 | /* grab UDP content */ |
418 | memcpy (&udp_pkt, &buf[off], sizeof (struct udp_header)); | 418 | GNUNET_memcpy (&udp_pkt, &buf[off], sizeof (struct udp_header)); |
419 | port = ntohs (udp_pkt.length); | 419 | port = ntohs (udp_pkt.length); |
420 | break; | 420 | break; |
421 | default: | 421 | default: |
diff --git a/src/nat/nat.c b/src/nat/nat.c index 042a0f686..6e9fcfd0e 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c | |||
@@ -519,7 +519,7 @@ add_to_address_list_as_is (struct GNUNET_NAT_Handle *h, | |||
519 | struct LocalAddressList *lal; | 519 | struct LocalAddressList *lal; |
520 | 520 | ||
521 | lal = GNUNET_malloc (sizeof (struct LocalAddressList) + arg_size); | 521 | lal = GNUNET_malloc (sizeof (struct LocalAddressList) + arg_size); |
522 | memcpy (&lal[1], arg, arg_size); | 522 | GNUNET_memcpy (&lal[1], arg, arg_size); |
523 | lal->addrlen = arg_size; | 523 | lal->addrlen = arg_size; |
524 | lal->source = src; | 524 | lal->source = src; |
525 | GNUNET_CONTAINER_DLL_insert (h->lal_head, | 525 | GNUNET_CONTAINER_DLL_insert (h->lal_head, |
@@ -1522,7 +1522,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1522 | GNUNET_assert (addrs[i] != NULL); | 1522 | GNUNET_assert (addrs[i] != NULL); |
1523 | h->local_addrlens[i] = addrlens[i]; | 1523 | h->local_addrlens[i] = addrlens[i]; |
1524 | h->local_addrs[i] = GNUNET_malloc (addrlens[i]); | 1524 | h->local_addrs[i] = GNUNET_malloc (addrlens[i]); |
1525 | memcpy (h->local_addrs[i], addrs[i], addrlens[i]); | 1525 | GNUNET_memcpy (h->local_addrs[i], addrs[i], addrlens[i]); |
1526 | } | 1526 | } |
1527 | } | 1527 | } |
1528 | if (GNUNET_OK == | 1528 | if (GNUNET_OK == |
diff --git a/src/nat/test_nat.c b/src/nat/test_nat.c index 3205e1f05..2e14a1ffa 100644 --- a/src/nat/test_nat.c +++ b/src/nat/test_nat.c | |||
@@ -110,7 +110,7 @@ process_if (void *cls, | |||
110 | return GNUNET_OK; | 110 | return GNUNET_OK; |
111 | GNUNET_free_non_null (data->addr); | 111 | GNUNET_free_non_null (data->addr); |
112 | data->addr = GNUNET_malloc (addrlen); | 112 | data->addr = GNUNET_malloc (addrlen); |
113 | memcpy (data->addr, addr, addrlen); | 113 | GNUNET_memcpy (data->addr, addr, addrlen); |
114 | data->addrlen = addrlen; | 114 | data->addrlen = addrlen; |
115 | if (isDefault) | 115 | if (isDefault) |
116 | return GNUNET_SYSERR; | 116 | return GNUNET_SYSERR; |