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.

566 lines
15 KiB

  1. From 877184f733d13d7db0ec9265a53ede9c30d03ba4 Mon Sep 17 00:00:00 2001
  2. From: Peter Wagner <tripolar@gmx.at>
  3. Date: Tue, 19 Feb 2019 20:00:22 +0100
  4. Subject: [PATCH 2/2] define and use wrapper function nfs_freeaddrinfo
  5. to handle freeaddrinfo versions that don't tolerate NULL pointers
  6. Signed-off-by: Peter Wagner <tripolar@gmx.at>
  7. ---
  8. support/export/client.c | 6 +++---
  9. support/export/hostname.c | 4 ++--
  10. support/include/exportfs.h | 11 +++++++++++
  11. support/nfs/getport.c | 7 ++++---
  12. support/nfs/svc_create.c | 8 +++++---
  13. support/nfsidmap/umich_ldap.c | 2 +-
  14. tests/nsm_client/nsm_client.c | 2 +-
  15. utils/exportfs/exportfs.c | 10 +++++-----
  16. utils/gssd/gssd.c | 4 ++--
  17. utils/gssd/krb5_util.c | 2 +-
  18. utils/mount/network.c | 7 ++++---
  19. utils/mount/stropts.c | 3 ++-
  20. utils/mountd/auth.c | 2 +-
  21. utils/mountd/cache.c | 10 +++++-----
  22. utils/mountd/mountd.c | 4 ++--
  23. utils/mountd/rmtab.c | 2 +-
  24. utils/nfsd/nfssvc.c | 4 ++--
  25. utils/statd/hostname.c | 11 ++++++-----
  26. utils/statd/sm-notify.c | 14 +++++++-------
  27. 19 files changed, 65 insertions(+), 48 deletions(-)
  28. diff --git a/support/export/client.c b/support/export/client.c
  29. index baf59c8..a1fba01 100644
  30. --- a/support/export/client.c
  31. +++ b/support/export/client.c
  32. @@ -210,7 +210,7 @@ init_subnetwork(nfs_client *clp)
  33. set_addrlist(clp, 0, ai->ai_addr);
  34. family = ai->ai_addr->sa_family;
  35. - freeaddrinfo(ai);
  36. + nfs_freeaddrinfo(ai);
  37. switch (family) {
  38. case AF_INET:
  39. @@ -309,7 +309,7 @@ client_lookup(char *hname, int canonical)
  40. init_addrlist(clp, ai);
  41. out:
  42. - freeaddrinfo(ai);
  43. + nfs_freeaddrinfo(ai);
  44. return clp;
  45. }
  46. @@ -674,7 +674,7 @@ check_netgroup(const nfs_client *clp, const struct addrinfo *ai)
  47. tmp = host_pton(hname);
  48. if (tmp != NULL) {
  49. char *cname = host_canonname(tmp->ai_addr);
  50. - freeaddrinfo(tmp);
  51. + nfs_freeaddrinfo(tmp);
  52. /* The resulting FQDN may be in our netgroup. */
  53. if (cname != NULL) {
  54. diff --git a/support/export/hostname.c b/support/export/hostname.c
  55. index 96c5449..be4d7f6 100644
  56. --- a/support/export/hostname.c
  57. +++ b/support/export/hostname.c
  58. @@ -130,7 +130,7 @@ host_pton(const char *paddr)
  59. if (!inet4 && ai->ai_addr->sa_family == AF_INET) {
  60. xlog(D_GENERAL, "%s: failed to convert %s",
  61. __func__, paddr);
  62. - freeaddrinfo(ai);
  63. + nfs_freeaddrinfo(ai);
  64. break;
  65. }
  66. return ai;
  67. @@ -292,7 +292,7 @@ host_reliable_addrinfo(const struct sockaddr *sap)
  68. if (nfs_compare_sockaddr(a->ai_addr, sap))
  69. break;
  70. - freeaddrinfo(ai);
  71. + nfs_freeaddrinfo(ai);
  72. ai = NULL;
  73. if (!a)
  74. goto out;
  75. diff --git a/support/include/exportfs.h b/support/include/exportfs.h
  76. index 4e0d9d1..b81f963 100644
  77. --- a/support/include/exportfs.h
  78. +++ b/support/include/exportfs.h
  79. @@ -47,6 +47,17 @@ typedef struct mclient {
  80. int m_count;
  81. } nfs_client;
  82. +/*
  83. + * Some versions of freeaddrinfo(3) do not tolerate being
  84. + * passed a NULL pointer.
  85. + */
  86. +static inline void nfs_freeaddrinfo(struct addrinfo *ai)
  87. +{
  88. + if (ai) {
  89. + freeaddrinfo(ai);
  90. + }
  91. +}
  92. +
  93. static inline const struct sockaddr *
  94. get_addrlist(const nfs_client *clp, const int i)
  95. {
  96. diff --git a/support/nfs/getport.c b/support/nfs/getport.c
  97. index 081594c..26ec85e 100644
  98. --- a/support/nfs/getport.c
  99. +++ b/support/nfs/getport.c
  100. @@ -47,6 +47,7 @@
  101. #include "sockaddr.h"
  102. #include "nfsrpc.h"
  103. +#include "exportfs.h"
  104. /*
  105. * Try a local socket first to access the local rpcbind daemon
  106. @@ -109,7 +110,7 @@ static int nfs_gp_loopback_address(struct sockaddr *sap, socklen_t *salen)
  107. ret = 1;
  108. }
  109. - freeaddrinfo(gai_results);
  110. + nfs_freeaddrinfo(gai_results);
  111. return ret;
  112. }
  113. @@ -134,8 +135,8 @@ static in_port_t nfs_gp_getservbyname(const char *service,
  114. sin = (const struct sockaddr_in *)gai_results->ai_addr;
  115. port = sin->sin_port;
  116. -
  117. - freeaddrinfo(gai_results);
  118. +
  119. + nfs_freeaddrinfo(gai_results);
  120. return port;
  121. }
  122. diff --git a/support/nfs/svc_create.c b/support/nfs/svc_create.c
  123. index ef7ff05..d0b747b 100644
  124. --- a/support/nfs/svc_create.c
  125. +++ b/support/nfs/svc_create.c
  126. @@ -39,6 +39,8 @@
  127. #include <rpc/rpc.h>
  128. #include <rpc/svc.h>
  129. +#include "exportfs.h"
  130. +
  131. #ifdef HAVE_TCP_WRAPPER
  132. #include "tcpwrapper.h"
  133. #endif
  134. @@ -273,7 +275,7 @@ svc_create_nconf_rand_port(const char *name, const rpcprog_t program,
  135. bindaddr.qlen = SOMAXCONN;
  136. xprt = svc_tli_create(RPC_ANYFD, nconf, &bindaddr, 0, 0);
  137. - freeaddrinfo(ai);
  138. + nfs_freeaddrinfo(ai);
  139. if (xprt == NULL) {
  140. xlog(L_ERROR, "Failed to create listener xprt "
  141. "(%s, %u, %s)", name, version, nconf->nc_netid);
  142. @@ -364,11 +366,11 @@ svc_create_nconf_fixed_port(const char *name, const rpcprog_t program,
  143. svc_create_cache_xprt(xprt);
  144. - freeaddrinfo(ai);
  145. + nfs_freeaddrinfo(ai);
  146. return 1;
  147. out_free:
  148. - freeaddrinfo(ai);
  149. + nfs_freeaddrinfo(ai);
  150. return 0;
  151. }
  152. diff --git a/support/nfsidmap/umich_ldap.c b/support/nfsidmap/umich_ldap.c
  153. index b661110..b8ee184 100644
  154. --- a/support/nfsidmap/umich_ldap.c
  155. +++ b/support/nfsidmap/umich_ldap.c
  156. @@ -1089,7 +1089,7 @@ get_canonical_hostname(const char *inname)
  157. return_name = strdup (tmphost);
  158. out_free:
  159. - freeaddrinfo(ap);
  160. + nfs_freeaddrinfo(ap);
  161. out_err:
  162. return return_name;
  163. }
  164. diff --git a/tests/nsm_client/nsm_client.c b/tests/nsm_client/nsm_client.c
  165. index 0fa3422..8dc0591 100644
  166. --- a/tests/nsm_client/nsm_client.c
  167. +++ b/tests/nsm_client/nsm_client.c
  168. @@ -243,7 +243,7 @@ nsm_client_get_rpcclient(const char *node)
  169. printf("RPC client creation failed\n");
  170. }
  171. out:
  172. - freeaddrinfo(ai);
  173. + nfs_freeaddrinfo(ai);
  174. return client;
  175. }
  176. diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
  177. index cd3c979..333eadc 100644
  178. --- a/utils/exportfs/exportfs.c
  179. +++ b/utils/exportfs/exportfs.c
  180. @@ -282,7 +282,7 @@ exportfs_parsed(char *hname, char *path, char *options, int verbose)
  181. validate_export(exp);
  182. out:
  183. - freeaddrinfo(ai);
  184. + nfs_freeaddrinfo(ai);
  185. }
  186. static int exportfs_generic(char *arg, char *options, int verbose)
  187. @@ -395,7 +395,7 @@ unexportfs_parsed(char *hname, char *path, int verbose)
  188. if (!success)
  189. xlog(L_ERROR, "Could not find '%s:%s' to unexport.", hname, path);
  190. - freeaddrinfo(ai);
  191. + nfs_freeaddrinfo(ai);
  192. }
  193. static int unexportfs_generic(char *arg, int verbose)
  194. @@ -588,7 +588,7 @@ address_list(const char *hostname)
  195. if (ai != NULL) {
  196. /* @hostname was a presentation address */
  197. cname = host_canonname(ai->ai_addr);
  198. - freeaddrinfo(ai);
  199. + nfs_freeaddrinfo(ai);
  200. if (cname != NULL)
  201. goto out;
  202. }
  203. @@ -639,8 +639,8 @@ matchhostname(const char *hostname1, const char *hostname2)
  204. }
  205. out:
  206. - freeaddrinfo(results1);
  207. - freeaddrinfo(results2);
  208. + nfs_freeaddrinfo(results1);
  209. + nfs_freeaddrinfo(results2);
  210. return result;
  211. }
  212. diff --git a/utils/gssd/gssd.c b/utils/gssd/gssd.c
  213. index 2e92f28..7eeb05f 100644
  214. --- a/utils/gssd/gssd.c
  215. +++ b/utils/gssd/gssd.c
  216. @@ -172,14 +172,14 @@ gssd_addrstr_to_sockaddr(struct sockaddr *sa, const char *node, const char *port
  217. if (sin6->sin6_scope_id) {
  218. printerr(0, "ERROR: address %s has non-zero "
  219. "sin6_scope_id!\n", node);
  220. - freeaddrinfo(res);
  221. + nfs_freeaddrinfo(res);
  222. return false;
  223. }
  224. }
  225. #endif /* IPV6_SUPPORTED */
  226. memcpy(sa, res->ai_addr, res->ai_addrlen);
  227. - freeaddrinfo(res);
  228. + nfs_freeaddrinfo(res);
  229. return true;
  230. }
  231. diff --git a/utils/gssd/krb5_util.c b/utils/gssd/krb5_util.c
  232. index eba1aac..adbde93 100644
  233. --- a/utils/gssd/krb5_util.c
  234. +++ b/utils/gssd/krb5_util.c
  235. @@ -587,7 +587,7 @@ get_full_hostname(const char *inhost, char *outhost, int outhostlen)
  236. goto out;
  237. }
  238. strncpy(outhost, addrs->ai_canonname, outhostlen);
  239. - freeaddrinfo(addrs);
  240. + nfs_freeaddrinfo(addrs);
  241. for (c = outhost; *c != '\0'; c++)
  242. *c = tolower(*c);
  243. diff --git a/utils/mount/network.c b/utils/mount/network.c
  244. index 356f663..fcb0b9f 100644
  245. --- a/utils/mount/network.c
  246. +++ b/utils/mount/network.c
  247. @@ -53,6 +53,7 @@
  248. #include <net/if.h>
  249. #include <ifaddrs.h>
  250. +#include "exportfs.h"
  251. #include "sockaddr.h"
  252. #include "xcommon.h"
  253. #include "mount.h"
  254. @@ -250,7 +251,7 @@ int nfs_lookup(const char *hostname, const sa_family_t family,
  255. break;
  256. }
  257. - freeaddrinfo(gai_results);
  258. + nfs_freeaddrinfo(gai_results);
  259. return ret;
  260. }
  261. @@ -307,7 +308,7 @@ int nfs_string_to_sockaddr(const char *address, struct sockaddr *sap,
  262. }
  263. break;
  264. }
  265. - freeaddrinfo(gai_results);
  266. + nfs_freeaddrinfo(gai_results);
  267. }
  268. return ret;
  269. @@ -1180,7 +1181,7 @@ static int nfs_ca_gai(const struct sockaddr *sap,
  270. *buflen = gai_results->ai_addrlen;
  271. memcpy(buf, gai_results->ai_addr, *buflen);
  272. - freeaddrinfo(gai_results);
  273. + nfs_freeaddrinfo(gai_results);
  274. return 1;
  275. }
  276. diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
  277. index 0a25b1f..b170552 100644
  278. --- a/utils/mount/stropts.c
  279. +++ b/utils/mount/stropts.c
  280. @@ -35,6 +35,7 @@
  281. #include <netinet/in.h>
  282. #include <arpa/inet.h>
  283. +#include "exportfs.h"
  284. #include "sockaddr.h"
  285. #include "xcommon.h"
  286. #include "mount.h"
  287. @@ -1268,7 +1269,7 @@ int nfsmount_string(const char *spec, const char *node, char *type,
  288. } else
  289. nfs_error(_("%s: internal option parsing error"), progname);
  290. - freeaddrinfo(mi.address);
  291. + nfs_freeaddrinfo(mi.address);
  292. free(mi.hostname);
  293. return retval;
  294. }
  295. diff --git a/utils/mountd/auth.c b/utils/mountd/auth.c
  296. index cb4848c..67627f7 100644
  297. --- a/utils/mountd/auth.c
  298. +++ b/utils/mountd/auth.c
  299. @@ -297,7 +297,7 @@ auth_authenticate(const char *what, const struct sockaddr *caller,
  300. what, buf, nfs_get_port(caller), path, epath, error);
  301. }
  302. - freeaddrinfo(ai);
  303. + nfs_freeaddrinfo(ai);
  304. return exp;
  305. }
  306. diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c
  307. index 7e8d403..2cb370f 100644
  308. --- a/utils/mountd/cache.c
  309. +++ b/utils/mountd/cache.c
  310. @@ -113,7 +113,7 @@ static void auth_unix_ip(int f)
  311. ai = client_resolve(tmp->ai_addr);
  312. if (ai) {
  313. client = client_compose(ai);
  314. - freeaddrinfo(ai);
  315. + nfs_freeaddrinfo(ai);
  316. }
  317. }
  318. bp = buf; blen = sizeof(buf);
  319. @@ -133,7 +133,7 @@ static void auth_unix_ip(int f)
  320. xlog(D_CALL, "auth_unix_ip: client %p '%s'", client, client?client: "DEFAULT");
  321. free(client);
  322. - freeaddrinfo(tmp);
  323. + nfs_freeaddrinfo(tmp);
  324. }
  325. @@ -667,7 +667,7 @@ static struct addrinfo *lookup_client_addr(char *dom)
  326. if (tmp == NULL)
  327. return NULL;
  328. ret = client_resolve(tmp->ai_addr);
  329. - freeaddrinfo(tmp);
  330. + nfs_freeaddrinfo(tmp);
  331. return ret;
  332. }
  333. @@ -834,7 +834,7 @@ static void nfsd_fh(int f)
  334. out:
  335. if (found_path)
  336. free(found_path);
  337. - freeaddrinfo(ai);
  338. + nfs_freeaddrinfo(ai);
  339. free(dom);
  340. xlog(D_CALL, "nfsd_fh: found %p path %s", found, found ? found->e_path : NULL);
  341. }
  342. @@ -1355,7 +1355,7 @@ static void nfsd_export(int f)
  343. xlog(D_CALL, "nfsd_export: found %p path %s", found, path ? path : NULL);
  344. if (dom) free(dom);
  345. if (path) free(path);
  346. - freeaddrinfo(ai);
  347. + nfs_freeaddrinfo(ai);
  348. }
  349. diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c
  350. index 086c39b..fb7bba4 100644
  351. --- a/utils/mountd/mountd.c
  352. +++ b/utils/mountd/mountd.c
  353. @@ -578,10 +578,10 @@ static void prune_clients(nfs_export *exp, struct exportnode *e)
  354. *cp = c->gr_next;
  355. xfree(c->gr_name);
  356. xfree(c);
  357. - freeaddrinfo(ai);
  358. + nfs_freeaddrinfo(ai);
  359. continue;
  360. }
  361. - freeaddrinfo(ai);
  362. + nfs_freeaddrinfo(ai);
  363. }
  364. cp = &(c->gr_next);
  365. }
  366. diff --git a/utils/mountd/rmtab.c b/utils/mountd/rmtab.c
  367. index 3ae0dbb..c896243 100644
  368. --- a/utils/mountd/rmtab.c
  369. +++ b/utils/mountd/rmtab.c
  370. @@ -226,7 +226,7 @@ mountlist_list(void)
  371. ai = host_pton(rep->r_client);
  372. if (ai != NULL) {
  373. m->ml_hostname = host_canonname(ai->ai_addr);
  374. - freeaddrinfo(ai);
  375. + nfs_freeaddrinfo(ai);
  376. }
  377. }
  378. if (m->ml_hostname == NULL)
  379. diff --git a/utils/nfsd/nfssvc.c b/utils/nfsd/nfssvc.c
  380. index 1e6ffd6..47b1882 100644
  381. --- a/utils/nfsd/nfssvc.c
  382. +++ b/utils/nfsd/nfssvc.c
  383. @@ -25,6 +25,7 @@
  384. #include "nfslib.h"
  385. #include "xlog.h"
  386. #include "nfssvc.h"
  387. +#include "exportfs.h"
  388. #include "../mount/version.h"
  389. #ifndef NFSD_FS_DIR
  390. @@ -246,8 +247,7 @@ error:
  391. close(fd);
  392. if (sockfd >= 0)
  393. close(sockfd);
  394. - if (addrhead)
  395. - freeaddrinfo(addrhead);
  396. + nfs_freeaddrinfo(addrhead);
  397. return (bounded ? 0 : rc);
  398. }
  399. diff --git a/utils/statd/hostname.c b/utils/statd/hostname.c
  400. index 8cccdb8..c9e22d3 100644
  401. --- a/utils/statd/hostname.c
  402. +++ b/utils/statd/hostname.c
  403. @@ -35,6 +35,7 @@
  404. #include <netdb.h>
  405. #include <arpa/inet.h>
  406. +#include "exportfs.h"
  407. #include "sockaddr.h"
  408. #include "statd.h"
  409. #include "xlog.h"
  410. @@ -203,7 +204,7 @@ statd_canonical_name(const char *hostname)
  411. _Bool result;
  412. result = get_nameinfo(ai->ai_addr, ai->ai_addrlen,
  413. buf, (socklen_t)sizeof(buf));
  414. - freeaddrinfo(ai);
  415. + nfs_freeaddrinfo(ai);
  416. if (!result || buf[0] == '\0')
  417. /* OK to use presentation address,
  418. * if no reverse map exists */
  419. @@ -217,7 +218,7 @@ statd_canonical_name(const char *hostname)
  420. if (ai == NULL)
  421. return NULL;
  422. strcpy(buf, ai->ai_canonname);
  423. - freeaddrinfo(ai);
  424. + nfs_freeaddrinfo(ai);
  425. return strdup(buf);
  426. }
  427. @@ -253,7 +254,7 @@ statd_canonical_list(const char *hostname)
  428. _Bool result;
  429. result = get_nameinfo(ai->ai_addr, ai->ai_addrlen,
  430. buf, (socklen_t)sizeof(buf));
  431. - freeaddrinfo(ai);
  432. + nfs_freeaddrinfo(ai);
  433. if (result)
  434. goto out;
  435. }
  436. @@ -308,8 +309,8 @@ statd_matchhostname(const char *hostname1, const char *hostname2)
  437. }
  438. out:
  439. - freeaddrinfo(results2);
  440. - freeaddrinfo(results1);
  441. + nfs_freeaddrinfo(results2);
  442. + nfs_freeaddrinfo(results1);
  443. xlog(D_CALL, "%s: hostnames %s and %s %s", __func__,
  444. hostname1, hostname2,
  445. diff --git a/utils/statd/sm-notify.c b/utils/statd/sm-notify.c
  446. index 29dad38..05d72a3 100644
  447. --- a/utils/statd/sm-notify.c
  448. +++ b/utils/statd/sm-notify.c
  449. @@ -37,6 +37,7 @@
  450. #include "xlog.h"
  451. #include "nsm.h"
  452. #include "nfsrpc.h"
  453. +#include "exportfs.h"
  454. /* glibc before 2.3.4 */
  455. #ifndef AI_NUMERICSERV
  456. @@ -179,7 +180,7 @@ smn_verify_my_name(const char *name)
  457. case 0:
  458. /* @name was a presentation address */
  459. retval = smn_get_hostname(ai->ai_addr, ai->ai_addrlen, name);
  460. - freeaddrinfo(ai);
  461. + nfs_freeaddrinfo(ai);
  462. if (retval == NULL)
  463. return NULL;
  464. break;
  465. @@ -253,8 +254,7 @@ static void smn_forget_host(struct nsm_host *host)
  466. free((void *)host->my_name);
  467. free((void *)host->mon_name);
  468. free(host->name);
  469. - if (host->ai)
  470. - freeaddrinfo(host->ai);
  471. + nfs_freeaddrinfo(host->ai);
  472. free(host);
  473. }
  474. @@ -430,7 +430,7 @@ retry:
  475. if (srcport) {
  476. if (bind(sock, ai->ai_addr, ai->ai_addrlen) == -1) {
  477. xlog(L_ERROR, "Failed to bind RPC socket: %m");
  478. - freeaddrinfo(ai);
  479. + nfs_freeaddrinfo(ai);
  480. (void)close(sock);
  481. return -1;
  482. }
  483. @@ -440,7 +440,7 @@ retry:
  484. if (smn_bindresvport(sock, ai->ai_addr) == -1) {
  485. xlog(L_ERROR,
  486. "bindresvport on RPC socket failed: %m");
  487. - freeaddrinfo(ai);
  488. + nfs_freeaddrinfo(ai);
  489. (void)close(sock);
  490. return -1;
  491. }
  492. @@ -449,13 +449,13 @@ retry:
  493. se = getservbyport((int)nfs_get_port(ai->ai_addr), "udp");
  494. if (se != NULL && retry_cnt < 100) {
  495. retry_cnt++;
  496. - freeaddrinfo(ai);
  497. + nfs_freeaddrinfo(ai);
  498. (void)close(sock);
  499. goto retry;
  500. }
  501. }
  502. - freeaddrinfo(ai);
  503. + nfs_freeaddrinfo(ai);
  504. return sock;
  505. }
  506. --
  507. 2.20.1