You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
5.1 KiB

  1. From 4bc0dcae0b64eccd63f753d05b505b0becdcb2c8 Mon Sep 17 00:00:00 2001
  2. From: Peter Wagner <tripolar@gmx.at>
  3. Date: Tue, 19 Feb 2019 19:50:03 +0100
  4. Subject: [PATCH 1/2] don't free ai->ai_canonname
  5. ---
  6. support/export/hostname.c | 58 ++++++++-------------------------------
  7. utils/mountd/auth.c | 16 +++++------
  8. 2 files changed, 20 insertions(+), 54 deletions(-)
  9. diff --git a/support/export/hostname.c b/support/export/hostname.c
  10. index 5c4c824..96c5449 100644
  11. --- a/support/export/hostname.c
  12. +++ b/support/export/hostname.c
  13. @@ -264,9 +264,9 @@ host_canonname(const struct sockaddr *sap)
  14. * Reverse and forward lookups are performed to ensure the address has
  15. * matching forward and reverse mappings.
  16. *
  17. - * Returns addrinfo structure with just the provided address with
  18. - * ai_canonname filled in. If there is a problem with resolution or
  19. - * the resolved records don't match up properly then it returns NULL
  20. + * Returns addrinfo structure with just the provided address. If there
  21. + * is a problem with resolution or the resolved records don't match up
  22. + * properly then returns NULL.
  23. *
  24. * Caller must free the returned structure with freeaddrinfo(3).
  25. */
  26. @@ -277,13 +277,15 @@ host_reliable_addrinfo(const struct sockaddr *sap)
  27. struct addrinfo *ai, *a;
  28. char *hostname;
  29. + ai = NULL;
  30. hostname = host_canonname(sap);
  31. if (hostname == NULL)
  32. - return NULL;
  33. + goto out;
  34. ai = host_addrinfo(hostname);
  35. + free(hostname);
  36. if (!ai)
  37. - goto out_free_hostname;
  38. + goto out;
  39. /* make sure there's a matching address in the list */
  40. for (a = ai; a; a = a->ai_next)
  41. @@ -291,22 +293,15 @@ host_reliable_addrinfo(const struct sockaddr *sap)
  42. break;
  43. freeaddrinfo(ai);
  44. + ai = NULL;
  45. if (!a)
  46. - goto out_free_hostname;
  47. + goto out;
  48. /* get addrinfo with just the original address */
  49. ai = host_numeric_addrinfo(sap);
  50. - if (!ai)
  51. - goto out_free_hostname;
  52. - /* and populate its ai_canonname field */
  53. - free(ai->ai_canonname);
  54. - ai->ai_canonname = hostname;
  55. +out:
  56. return ai;
  57. -
  58. -out_free_hostname:
  59. - free(hostname);
  60. - return NULL;
  61. }
  62. /**
  63. @@ -323,7 +318,6 @@ host_numeric_addrinfo(const struct sockaddr *sap)
  64. {
  65. socklen_t salen = nfs_sockaddr_length(sap);
  66. char buf[INET6_ADDRSTRLEN];
  67. - struct addrinfo *ai;
  68. int error;
  69. if (salen == 0) {
  70. @@ -348,21 +342,7 @@ host_numeric_addrinfo(const struct sockaddr *sap)
  71. return NULL;
  72. }
  73. - ai = host_pton(buf);
  74. -
  75. - /*
  76. - * getaddrinfo(AI_NUMERICHOST) never fills in ai_canonname
  77. - */
  78. - if (ai != NULL) {
  79. - free(ai->ai_canonname); /* just in case */
  80. - ai->ai_canonname = strdup(buf);
  81. - if (ai->ai_canonname == NULL) {
  82. - freeaddrinfo(ai);
  83. - ai = NULL;
  84. - }
  85. - }
  86. -
  87. - return ai;
  88. + return host_pton(buf);
  89. }
  90. #else /* !HAVE_GETNAMEINFO */
  91. __attribute__((__malloc__))
  92. @@ -372,7 +352,6 @@ host_numeric_addrinfo(const struct sockaddr *sap)
  93. const struct sockaddr_in *sin = (const struct sockaddr_in *)sap;
  94. const struct in_addr *addr = &sin->sin_addr;
  95. char buf[INET_ADDRSTRLEN];
  96. - struct addrinfo *ai;
  97. if (sap->sa_family != AF_INET)
  98. return NULL;
  99. @@ -382,19 +361,6 @@ host_numeric_addrinfo(const struct sockaddr *sap)
  100. (socklen_t)sizeof(buf)) == NULL)
  101. return NULL;
  102. - ai = host_pton(buf);
  103. -
  104. - /*
  105. - * getaddrinfo(AI_NUMERICHOST) never fills in ai_canonname
  106. - */
  107. - if (ai != NULL) {
  108. - ai->ai_canonname = strdup(buf);
  109. - if (ai->ai_canonname == NULL) {
  110. - freeaddrinfo(ai);
  111. - ai = NULL;
  112. - }
  113. - }
  114. -
  115. - return ai;
  116. + return host_pton(buf);
  117. }
  118. #endif /* !HAVE_GETNAMEINFO */
  119. diff --git a/utils/mountd/auth.c b/utils/mountd/auth.c
  120. index 8299256..cb4848c 100644
  121. --- a/utils/mountd/auth.c
  122. +++ b/utils/mountd/auth.c
  123. @@ -261,40 +261,40 @@ auth_authenticate(const char *what, const struct sockaddr *caller,
  124. *p = '\0';
  125. }
  126. + host_ntop(caller, buf, sizeof(buf));
  127. switch (error) {
  128. case bad_path:
  129. xlog(L_WARNING, "bad path in %s request from %s: \"%s\"",
  130. - what, host_ntop(caller, buf, sizeof(buf)), path);
  131. + what, buf, path);
  132. break;
  133. case unknown_host:
  134. xlog(L_WARNING, "refused %s request from %s for %s (%s): unmatched host",
  135. - what, host_ntop(caller, buf, sizeof(buf)), path, epath);
  136. + what, buf, path, epath);
  137. break;
  138. case no_entry:
  139. xlog(L_WARNING, "refused %s request from %s for %s (%s): no export entry",
  140. - what, ai->ai_canonname, path, epath);
  141. + what, buf, path, epath);
  142. break;
  143. case not_exported:
  144. xlog(L_WARNING, "refused %s request from %s for %s (%s): not exported",
  145. - what, ai->ai_canonname, path, epath);
  146. + what, buf, path, epath);
  147. break;
  148. case illegal_port:
  149. xlog(L_WARNING, "refused %s request from %s for %s (%s): illegal port %u",
  150. - what, ai->ai_canonname, path, epath, nfs_get_port(caller));
  151. + what, buf, path, epath, nfs_get_port(caller));
  152. break;
  153. case success:
  154. xlog(L_NOTICE, "authenticated %s request from %s:%u for %s (%s)",
  155. - what, ai->ai_canonname, nfs_get_port(caller), path, epath);
  156. + what, buf, nfs_get_port(caller), path, epath);
  157. break;
  158. default:
  159. xlog(L_NOTICE, "%s request from %s:%u for %s (%s) gave %d",
  160. - what, ai->ai_canonname, nfs_get_port(caller),
  161. - path, epath, error);
  162. + what, buf, nfs_get_port(caller), path, epath, error);
  163. }
  164. freeaddrinfo(ai);
  165. --
  166. 2.20.1