diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-10-05 12:10:25 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-10-05 12:10:25 +0000 |
commit | 0d24b3403ac13a75e42407c0c0f9af69a95f87f2 (patch) | |
tree | a86a3fe7f9ce9fa02a2cbf972bc7f064ffce74db | |
parent | ee9df43928529ba3cfc860e52f07bf0191ebd1b5 (diff) | |
download | gnunet-0d24b3403ac13a75e42407c0c0f9af69a95f87f2.tar.gz gnunet-0d24b3403ac13a75e42407c0c0f9af69a95f87f2.zip |
-fix leak of sockaddr
-rw-r--r-- | src/transport/plugin_transport_http_common.c | 112 |
1 files changed, 67 insertions, 45 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c index f1246bdb4..3c14bb5d9 100644 --- a/src/transport/plugin_transport_http_common.c +++ b/src/transport/plugin_transport_http_common.c | |||
@@ -271,6 +271,7 @@ http_common_plugin_dnsresult_to_address (const char *plugin, | |||
271 | return NULL ; | 271 | return NULL ; |
272 | } | 272 | } |
273 | 273 | ||
274 | |||
274 | static void | 275 | static void |
275 | http_common_dns_reverse_lookup_cb (void *cls, const char *hostname) | 276 | http_common_dns_reverse_lookup_cb (void *cls, const char *hostname) |
276 | { | 277 | { |
@@ -296,39 +297,48 @@ http_common_dns_reverse_lookup_cb (void *cls, const char *hostname) | |||
296 | } | 297 | } |
297 | } | 298 | } |
298 | 299 | ||
300 | |||
299 | static int | 301 | static int |
300 | http_common_dns_reverse_lookup (const struct sockaddr *sockaddr, | 302 | http_common_dns_reverse_lookup (const struct sockaddr *sockaddr, |
301 | socklen_t sockaddr_len, const char *type, struct SplittedHTTPAddress *saddr, | 303 | socklen_t sockaddr_len, |
302 | uint32_t options, | 304 | const char *type, |
303 | struct GNUNET_TIME_Relative timeout, | 305 | struct SplittedHTTPAddress *saddr, |
304 | GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) | 306 | uint32_t options, |
307 | struct GNUNET_TIME_Relative timeout, | ||
308 | GNUNET_TRANSPORT_AddressStringCallback asc, | ||
309 | void *asc_cls) | ||
305 | { | 310 | { |
306 | struct PrettyPrinterContext *ppc; | 311 | struct PrettyPrinterContext *ppc; |
307 | ppc = GNUNET_new (struct PrettyPrinterContext); | ||
308 | 312 | ||
309 | ppc->sucess = GNUNET_NO; | 313 | ppc = GNUNET_new (struct PrettyPrinterContext); |
310 | ppc->saddr = saddr; | 314 | ppc->saddr = saddr; |
311 | ppc->asc = asc; | 315 | ppc->asc = asc; |
312 | ppc->asc_cls = asc_cls; | 316 | ppc->asc_cls = asc_cls; |
313 | ppc->plugin = GNUNET_strdup (type); | 317 | ppc->plugin = GNUNET_strdup (type); |
314 | ppc->options = options; | 318 | ppc->options = options; |
315 | 319 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sockaddr, | |
316 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sockaddr, sockaddr_len, | 320 | sockaddr_len, |
317 | GNUNET_YES, timeout, &http_common_dns_reverse_lookup_cb, ppc); | 321 | GNUNET_YES, |
322 | timeout, | ||
323 | &http_common_dns_reverse_lookup_cb, | ||
324 | ppc); | ||
318 | if (NULL == ppc->resolver_handle) | 325 | if (NULL == ppc->resolver_handle) |
319 | { | 326 | { |
320 | GNUNET_free(ppc->plugin); | 327 | GNUNET_free(ppc->plugin); |
321 | GNUNET_free(ppc); | 328 | GNUNET_free(ppc); |
322 | return GNUNET_SYSERR; | 329 | return GNUNET_SYSERR; |
323 | } | 330 | } |
324 | 331 | GNUNET_CONTAINER_DLL_insert (dll_ppc_head, | |
325 | GNUNET_CONTAINER_DLL_insert(dll_ppc_head, dll_ppc_tail, ppc); | 332 | dll_ppc_tail, |
333 | ppc); | ||
326 | return GNUNET_OK; | 334 | return GNUNET_OK; |
327 | } | 335 | } |
328 | 336 | ||
337 | |||
329 | static void | 338 | static void |
330 | http_common_dns_ip_lookup_cb (void *cls, const struct sockaddr *addr, | 339 | http_common_dns_ip_lookup_cb (void *cls, |
331 | socklen_t addrlen) | 340 | const struct sockaddr *addr, |
341 | socklen_t addrlen) | ||
332 | { | 342 | { |
333 | struct PrettyPrinterContext *ppc = cls; | 343 | struct PrettyPrinterContext *ppc = cls; |
334 | 344 | ||
@@ -398,9 +408,12 @@ http_common_dns_ip_lookup (const char *name, const char *type, | |||
398 | */ | 408 | */ |
399 | void | 409 | void |
400 | http_common_plugin_address_pretty_printer (void *cls, const char *type, | 410 | http_common_plugin_address_pretty_printer (void *cls, const char *type, |
401 | const void *addr, size_t addrlen, int numeric, | 411 | const void *addr, |
402 | struct GNUNET_TIME_Relative timeout, | 412 | size_t addrlen, |
403 | GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) | 413 | int numeric, |
414 | struct GNUNET_TIME_Relative timeout, | ||
415 | GNUNET_TRANSPORT_AddressStringCallback asc, | ||
416 | void *asc_cls) | ||
404 | { | 417 | { |
405 | const struct HttpAddress *address = addr; | 418 | const struct HttpAddress *address = addr; |
406 | struct SplittedHTTPAddress *saddr; | 419 | struct SplittedHTTPAddress *saddr; |
@@ -437,7 +450,7 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
437 | if (GNUNET_SYSERR == res) | 450 | if (GNUNET_SYSERR == res) |
438 | { | 451 | { |
439 | /* Malformed address */ | 452 | /* Malformed address */ |
440 | GNUNET_break(0); | 453 | GNUNET_break (0); |
441 | goto handle_error; | 454 | goto handle_error; |
442 | } | 455 | } |
443 | else if (GNUNET_NO == res) | 456 | else if (GNUNET_NO == res) |
@@ -453,7 +466,7 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
453 | else | 466 | else |
454 | { | 467 | { |
455 | /* Must not happen */ | 468 | /* Must not happen */ |
456 | GNUNET_break(0); | 469 | GNUNET_break (0); |
457 | goto handle_error; | 470 | goto handle_error; |
458 | } | 471 | } |
459 | 472 | ||
@@ -464,35 +477,42 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
464 | asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); | 477 | asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); |
465 | asc (asc_cls, NULL, GNUNET_OK); | 478 | asc (asc_cls, NULL, GNUNET_OK); |
466 | http_clean_splitted (saddr); | 479 | http_clean_splitted (saddr); |
467 | GNUNET_free_non_null(sock_addr); | 480 | GNUNET_free_non_null (sock_addr); |
468 | return; | 481 | return; |
469 | } | 482 | } |
470 | else if ((GNUNET_YES == numeric) && (GNUNET_NO == have_ip)) | 483 | else if ((GNUNET_YES == numeric) && (GNUNET_NO == have_ip)) |
471 | { | 484 | { |
472 | /* Forward lookup */ | 485 | /* Forward lookup */ |
473 | if (GNUNET_SYSERR | 486 | if (GNUNET_SYSERR == |
474 | == http_common_dns_ip_lookup (saddr->host, type, saddr, address->options, timeout, asc, | 487 | http_common_dns_ip_lookup (saddr->host, type, saddr, |
475 | asc_cls)) | 488 | address->options, timeout, |
489 | asc, asc_cls)) | ||
476 | { | 490 | { |
477 | GNUNET_break(0); | 491 | GNUNET_break(0); |
478 | goto handle_error; | 492 | goto handle_error; |
479 | } | 493 | } |
480 | /* Wait for resolver callback */ | 494 | /* Wait for resolver callback */ |
495 | GNUNET_free_non_null (sock_addr); | ||
481 | return; | 496 | return; |
482 | } | 497 | } |
483 | else if ((GNUNET_NO == numeric) && (GNUNET_YES == have_ip)) | 498 | else if ((GNUNET_NO == numeric) && (GNUNET_YES == have_ip)) |
484 | { | 499 | { |
485 | /* Reverse lookup */ | 500 | /* Reverse lookup */ |
486 | if (GNUNET_SYSERR | 501 | if (GNUNET_SYSERR == |
487 | == http_common_dns_reverse_lookup (sock_addr, | 502 | http_common_dns_reverse_lookup (sock_addr, |
488 | (AF_INET == sock_addr->sa_family) ? | 503 | (AF_INET == sock_addr->sa_family) |
489 | sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), type, | 504 | ? sizeof(struct sockaddr_in) |
490 | saddr, address->options, timeout, asc, asc_cls)) | 505 | : sizeof(struct sockaddr_in6), |
506 | type, | ||
507 | saddr, | ||
508 | address->options, timeout, | ||
509 | asc, asc_cls)) | ||
491 | { | 510 | { |
492 | GNUNET_break(0); | 511 | GNUNET_break(0); |
493 | goto handle_error; | 512 | goto handle_error; |
494 | } | 513 | } |
495 | /* Wait for resolver callback */ | 514 | /* Wait for resolver callback */ |
515 | GNUNET_free_non_null (sock_addr); | ||
496 | return; | 516 | return; |
497 | } | 517 | } |
498 | else if ((GNUNET_NO == numeric) && (GNUNET_NO == have_ip)) | 518 | else if ((GNUNET_NO == numeric) && (GNUNET_NO == have_ip)) |
@@ -501,7 +521,7 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
501 | ret = http_common_plugin_address_to_string (type, address, addrlen); | 521 | ret = http_common_plugin_address_to_string (type, address, addrlen); |
502 | asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); | 522 | asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); |
503 | asc (asc_cls, NULL, GNUNET_OK); | 523 | asc (asc_cls, NULL, GNUNET_OK); |
504 | GNUNET_free_non_null(sock_addr); | 524 | GNUNET_free_non_null (sock_addr); |
505 | http_clean_splitted (saddr); | 525 | http_clean_splitted (saddr); |
506 | return; | 526 | return; |
507 | } | 527 | } |
@@ -510,13 +530,14 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
510 | /* Error */ | 530 | /* Error */ |
511 | goto handle_error; | 531 | goto handle_error; |
512 | } | 532 | } |
533 | GNUNET_free_non_null (sock_addr); | ||
513 | return; | 534 | return; |
514 | 535 | ||
515 | handle_error: | 536 | handle_error: |
516 | /* Error */ | 537 | /* Error */ |
517 | asc (asc_cls, NULL, GNUNET_SYSERR); | 538 | asc (asc_cls, NULL, GNUNET_SYSERR); |
518 | asc (asc_cls, NULL, GNUNET_OK); | 539 | asc (asc_cls, NULL, GNUNET_OK); |
519 | GNUNET_free_non_null(sock_addr); | 540 | GNUNET_free_non_null (sock_addr); |
520 | if (NULL != saddr) | 541 | if (NULL != saddr) |
521 | http_clean_splitted (saddr); | 542 | http_clean_splitted (saddr); |
522 | return; | 543 | return; |
@@ -713,7 +734,9 @@ http_common_address_from_socket (const char *protocol, | |||
713 | * @return the string | 734 | * @return the string |
714 | */ | 735 | */ |
715 | struct sockaddr * | 736 | struct sockaddr * |
716 | http_common_socket_from_address (const void *addr, size_t addrlen, int *res) | 737 | http_common_socket_from_address (const void *addr, |
738 | size_t addrlen, | ||
739 | int *res) | ||
717 | { | 740 | { |
718 | const struct HttpAddress *ha; | 741 | const struct HttpAddress *ha; |
719 | struct SplittedHTTPAddress * spa; | 742 | struct SplittedHTTPAddress * spa; |
@@ -725,40 +748,40 @@ http_common_socket_from_address (const void *addr, size_t addrlen, int *res) | |||
725 | ha = (const struct HttpAddress *) addr; | 748 | ha = (const struct HttpAddress *) addr; |
726 | if (NULL == addr) | 749 | if (NULL == addr) |
727 | { | 750 | { |
728 | GNUNET_break(0); | 751 | GNUNET_break (0); |
729 | return NULL ; | 752 | return NULL; |
730 | } | 753 | } |
731 | if (0 >= addrlen) | 754 | if (0 >= addrlen) |
732 | { | 755 | { |
733 | GNUNET_break(0); | 756 | GNUNET_break (0); |
734 | return NULL ; | 757 | return NULL; |
735 | } | 758 | } |
736 | if (addrlen < sizeof(struct HttpAddress)) | 759 | if (addrlen < sizeof(struct HttpAddress)) |
737 | { | 760 | { |
738 | GNUNET_break(0); | 761 | GNUNET_break (0); |
739 | return NULL ; | 762 | return NULL; |
740 | } | 763 | } |
741 | urlen = ntohl (ha->urlen); | 764 | urlen = ntohl (ha->urlen); |
742 | if (sizeof(struct HttpAddress) + urlen != addrlen) | 765 | if (sizeof(struct HttpAddress) + urlen != addrlen) |
743 | { | 766 | { |
744 | /* This is a legacy addresses */ | 767 | /* This is a legacy addresses */ |
745 | return NULL ; | 768 | return NULL; |
746 | } | 769 | } |
747 | if (addrlen < sizeof(struct HttpAddress) + urlen) | 770 | if (addrlen < sizeof(struct HttpAddress) + urlen) |
748 | { | 771 | { |
749 | /* This is a legacy addresses */ | 772 | /* This is a legacy addresses */ |
750 | return NULL ; | 773 | return NULL; |
751 | } | 774 | } |
752 | if (((char *) addr)[addrlen - 1] != '\0') | 775 | if (((char *) addr)[addrlen - 1] != '\0') |
753 | { | 776 | { |
754 | GNUNET_break(0); | 777 | GNUNET_break (0); |
755 | return NULL ; | 778 | return NULL; |
756 | } | 779 | } |
757 | spa = http_split_address ((const char *) &ha[1]); | 780 | spa = http_split_address ((const char *) &ha[1]); |
758 | if (NULL == spa) | 781 | if (NULL == spa) |
759 | { | 782 | { |
760 | (*res) = GNUNET_SYSERR; | 783 | (*res) = GNUNET_SYSERR; |
761 | return NULL ; | 784 | return NULL; |
762 | } | 785 | } |
763 | 786 | ||
764 | s = GNUNET_new (struct sockaddr_storage); | 787 | s = GNUNET_new (struct sockaddr_storage); |
@@ -773,8 +796,7 @@ http_common_socket_from_address (const void *addr, size_t addrlen, int *res) | |||
773 | } | 796 | } |
774 | else if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family)) | 797 | else if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family)) |
775 | { | 798 | { |
776 | 799 | GNUNET_free (s); | |
777 | GNUNET_free(s); | ||
778 | (*res) = GNUNET_SYSERR; | 800 | (*res) = GNUNET_SYSERR; |
779 | s = NULL; | 801 | s = NULL; |
780 | } | 802 | } |
@@ -783,7 +805,7 @@ http_common_socket_from_address (const void *addr, size_t addrlen, int *res) | |||
783 | (*res) = GNUNET_YES; | 805 | (*res) = GNUNET_YES; |
784 | } | 806 | } |
785 | http_clean_splitted (spa); | 807 | http_clean_splitted (spa); |
786 | GNUNET_free(to_conv); | 808 | GNUNET_free (to_conv); |
787 | return (struct sockaddr *) s; | 809 | return (struct sockaddr *) s; |
788 | } | 810 | } |
789 | 811 | ||