0038-ping6-Fix-memleak-in-ping_set_dest.patch 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. From 9ab7dff9279f8640752ffc640dd90ad1dcd19a2b Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Tim=20R=C3=BChsen?= <tim.ruehsen@gmx.de>
  3. Date: Mon, 17 Feb 2020 21:40:22 +0100
  4. Subject: [PATCH 38/60] ping6: Fix memleak in ping_set_dest
  5. ---
  6. ping/ping6.c | 18 +++++++++++-------
  7. ping/ping6.h | 2 +-
  8. 2 files changed, 12 insertions(+), 8 deletions(-)
  9. diff --git a/ping/ping6.c b/ping/ping6.c
  10. index b0e0bf1f..8bc92a8f 100644
  11. --- a/ping/ping6.c
  12. +++ b/ping/ping6.c
  13. @@ -998,7 +998,7 @@ ping_recv (PING * p)
  14. }
  15. static int
  16. -ping_set_dest (PING * ping, char *host)
  17. +ping_set_dest (PING * ping, const char *host)
  18. {
  19. int err;
  20. struct addrinfo *result, hints;
  21. @@ -1008,8 +1008,9 @@ ping_set_dest (PING * ping, char *host)
  22. err = idna_to_ascii_lz (host, &rhost, 0);
  23. if (err)
  24. return 1;
  25. + host = rhost;
  26. #else /* !HAVE_IDN */
  27. - rhost = host;
  28. + rhost = NULL;
  29. #endif
  30. memset (&hints, 0, sizeof (hints));
  31. @@ -1022,19 +1023,22 @@ ping_set_dest (PING * ping, char *host)
  32. hints.ai_flags |= AI_CANONIDN;
  33. #endif
  34. - err = getaddrinfo (rhost, NULL, &hints, &result);
  35. + err = getaddrinfo (host, NULL, &hints, &result);
  36. if (err)
  37. - return 1;
  38. + {
  39. + free (rhost);
  40. + return 1;
  41. + }
  42. memcpy (&ping->ping_dest.ping_sockaddr6, result->ai_addr, result->ai_addrlen);
  43. if (result->ai_canonname)
  44. ping->ping_hostname = strdup (result->ai_canonname);
  45. else
  46. - ping->ping_hostname = strdup (rhost);
  47. -
  48. #if HAVE_IDN
  49. - free (rhost);
  50. + ping->ping_hostname = host;
  51. +#else
  52. + ping->ping_hostname = strdup (host);
  53. #endif
  54. freeaddrinfo (result);
  55. diff --git a/ping/ping6.h b/ping/ping6.h
  56. index 76fc6b09..b15a407f 100644
  57. --- a/ping/ping6.h
  58. +++ b/ping/ping6.h
  59. @@ -24,7 +24,7 @@
  60. #define USE_IPV6 1
  61. static PING *ping_init (int type, int ident);
  62. -static int ping_set_dest (PING * ping, char *host);
  63. +static int ping_set_dest (PING * ping, const char *host);
  64. static int ping_recv (PING * p);
  65. static int ping_xmit (PING * p);
  66. --
  67. 2.26.0.292.g33ef6b2f38