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.

274 lines
7.9 KiB

  1. diff --git a/src/clnt_dg.c b/src/clnt_dg.c
  2. index 04a2aba..eb5467f 100644
  3. --- a/src/clnt_dg.c
  4. +++ b/src/clnt_dg.c
  5. @@ -160,15 +160,22 @@ clnt_dg_create(fd, svcaddr, program, version, sendsz, recvsz)
  6. thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
  7. mutex_lock(&clnt_fd_lock);
  8. if (dg_fd_locks == (int *) NULL) {
  9. - int cv_allocsz;
  10. - size_t fd_allocsz;
  11. - int dtbsize = __rpc_dtbsize();
  12. + size_t cv_allocsz, fd_allocsz;
  13. + unsigned int dtbsize = __rpc_dtbsize();
  14. +
  15. + if ( (size_t) dtbsize > SIZE_MAX/sizeof(cond_t)) {
  16. + mutex_unlock(&clnt_fd_lock);
  17. + thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
  18. + errno = EOVERFLOW;
  19. + goto err1;
  20. + }
  21. fd_allocsz = dtbsize * sizeof (int);
  22. dg_fd_locks = (int *) mem_alloc(fd_allocsz);
  23. if (dg_fd_locks == (int *) NULL) {
  24. mutex_unlock(&clnt_fd_lock);
  25. thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
  26. + errno = ENOMEM;
  27. goto err1;
  28. } else
  29. memset(dg_fd_locks, '\0', fd_allocsz);
  30. @@ -180,6 +187,7 @@ clnt_dg_create(fd, svcaddr, program, version, sendsz, recvsz)
  31. dg_fd_locks = (int *) NULL;
  32. mutex_unlock(&clnt_fd_lock);
  33. thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
  34. + errno = ENOMEM;
  35. goto err1;
  36. } else {
  37. int i;
  38. diff --git a/src/clnt_generic.c b/src/clnt_generic.c
  39. index e5a314f..3f3dabf 100644
  40. --- a/src/clnt_generic.c
  41. +++ b/src/clnt_generic.c
  42. @@ -47,7 +47,6 @@
  43. extern bool_t __rpc_is_local_host(const char *);
  44. int __rpc_raise_fd(int);
  45. -extern int __binddynport(int fd);
  46. #ifndef NETIDLEN
  47. #define NETIDLEN 32
  48. @@ -341,8 +340,7 @@ clnt_tli_create(int fd, const struct netconfig *nconf,
  49. servtype = nconf->nc_semantics;
  50. if (!__rpc_fd2sockinfo(fd, &si))
  51. goto err;
  52. - if (__binddynport(fd) == -1)
  53. - goto err;
  54. + bindresvport(fd, NULL);
  55. } else {
  56. if (!__rpc_fd2sockinfo(fd, &si))
  57. goto err;
  58. diff --git a/src/clnt_vc.c b/src/clnt_vc.c
  59. index 6098c3a..3d775c7 100644
  60. --- a/src/clnt_vc.c
  61. +++ b/src/clnt_vc.c
  62. @@ -63,6 +63,7 @@
  63. #include <string.h>
  64. #include <unistd.h>
  65. #include <signal.h>
  66. +#include <stdint.h>
  67. #include <rpc/rpc.h>
  68. #include "rpc_com.h"
  69. @@ -201,14 +202,25 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
  70. thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
  71. mutex_lock(&clnt_fd_lock);
  72. if (vc_fd_locks == (int *) NULL) {
  73. - int cv_allocsz, fd_allocsz;
  74. - int dtbsize = __rpc_dtbsize();
  75. + size_t cv_allocsz, fd_allocsz;
  76. + unsigned int dtbsize = __rpc_dtbsize();
  77. + struct rpc_createerr *ce = &get_rpc_createerr();
  78. +
  79. + if ( (size_t) dtbsize > SIZE_MAX/sizeof(cond_t)) {
  80. + mutex_unlock(&clnt_fd_lock);
  81. + thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
  82. + ce->cf_stat = RPC_SYSTEMERROR;
  83. + ce->cf_error.re_errno = EOVERFLOW;
  84. + goto err;
  85. + }
  86. fd_allocsz = dtbsize * sizeof (int);
  87. vc_fd_locks = (int *) mem_alloc(fd_allocsz);
  88. if (vc_fd_locks == (int *) NULL) {
  89. mutex_unlock(&clnt_fd_lock);
  90. thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
  91. + ce->cf_stat = RPC_SYSTEMERROR;
  92. + ce->cf_error.re_errno = ENOMEM;
  93. goto err;
  94. } else
  95. memset(vc_fd_locks, '\0', fd_allocsz);
  96. @@ -221,6 +233,8 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
  97. vc_fd_locks = (int *) NULL;
  98. mutex_unlock(&clnt_fd_lock);
  99. thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
  100. + ce->cf_stat = RPC_SYSTEMERROR;
  101. + ce->cf_error.re_errno = ENOMEM;
  102. goto err;
  103. } else {
  104. int i;
  105. diff --git a/src/rpc_soc.c b/src/rpc_soc.c
  106. index af6c482..5a6eeb7 100644
  107. --- a/src/rpc_soc.c
  108. +++ b/src/rpc_soc.c
  109. @@ -67,8 +67,6 @@
  110. extern mutex_t rpcsoc_lock;
  111. -extern int __binddynport(int fd);
  112. -
  113. static CLIENT *clnt_com_create(struct sockaddr_in *, rpcprog_t, rpcvers_t,
  114. int *, u_int, u_int, char *, int);
  115. static SVCXPRT *svc_com_create(int, u_int, u_int, char *);
  116. @@ -147,8 +145,7 @@ clnt_com_create(raddr, prog, vers, sockp, sendsz, recvsz, tp, flags)
  117. bindaddr.maxlen = bindaddr.len = sizeof (struct sockaddr_in);
  118. bindaddr.buf = raddr;
  119. - if (__binddynport(fd) == -1)
  120. - goto err;
  121. + bindresvport(fd, NULL);
  122. cl = clnt_tli_create(fd, nconf, &bindaddr, prog, vers,
  123. sendsz, recvsz);
  124. if (cl) {
  125. diff --git a/src/rpcb_clnt.c b/src/rpcb_clnt.c
  126. index a94fc73..e45736a 100644
  127. --- a/src/rpcb_clnt.c
  128. +++ b/src/rpcb_clnt.c
  129. @@ -752,7 +752,7 @@ __try_protocol_version_2(program, version, nconf, host, tp)
  130. client = getpmaphandle(nconf, host, &parms.r_addr);
  131. if (client == NULL)
  132. - return (NULL);
  133. + goto error;
  134. /*
  135. * Set retry timeout.
  136. @@ -771,11 +771,11 @@ __try_protocol_version_2(program, version, nconf, host, tp)
  137. if (clnt_st != RPC_SUCCESS) {
  138. rpc_createerr.cf_stat = RPC_PMAPFAILURE;
  139. clnt_geterr(client, &rpc_createerr.cf_error);
  140. - return (NULL);
  141. + goto error;
  142. } else if (port == 0) {
  143. pmapaddress = NULL;
  144. rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
  145. - return (NULL);
  146. + goto error;
  147. }
  148. port = htons(port);
  149. CLNT_CONTROL(client, CLGET_SVC_ADDR, (char *)&remote);
  150. @@ -789,14 +789,24 @@ __try_protocol_version_2(program, version, nconf, host, tp)
  151. free(pmapaddress);
  152. pmapaddress = NULL;
  153. }
  154. - return (NULL);
  155. + goto error;
  156. }
  157. memcpy(pmapaddress->buf, remote.buf, remote.len);
  158. memcpy(&((char *)pmapaddress->buf)[sizeof (short)],
  159. (char *)(void *)&port, sizeof (short));
  160. pmapaddress->len = pmapaddress->maxlen = remote.len;
  161. + CLNT_DESTROY(client);
  162. return pmapaddress;
  163. +
  164. +error:
  165. + if (client) {
  166. + CLNT_DESTROY(client);
  167. + client = NULL;
  168. +
  169. + }
  170. + return (NULL);
  171. +
  172. }
  173. #endif
  174. @@ -836,6 +846,7 @@ __rpcb_findaddr_timed(program, version, nconf, host, clpp, tp)
  175. struct netbuf *address = NULL;
  176. rpcvers_t start_vers = RPCBVERS4;
  177. struct netbuf servaddr;
  178. + struct rpc_err rpcerr;
  179. /* parameter checking */
  180. if (nconf == NULL) {
  181. @@ -892,7 +903,8 @@ __rpcb_findaddr_timed(program, version, nconf, host, clpp, tp)
  182. clnt_st = CLNT_CALL(client, (rpcproc_t)RPCBPROC_GETADDR,
  183. (xdrproc_t) xdr_rpcb, (char *)(void *)&parms,
  184. (xdrproc_t) xdr_wrapstring, (char *)(void *) &ua, *tp);
  185. - if (clnt_st == RPC_SUCCESS) {
  186. + switch (clnt_st) {
  187. + case RPC_SUCCESS:
  188. if ((ua == NULL) || (ua[0] == 0)) {
  189. /* address unknown */
  190. rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
  191. @@ -914,12 +926,15 @@ __rpcb_findaddr_timed(program, version, nconf, host, clpp, tp)
  192. (char *)(void *)&servaddr);
  193. __rpc_fixup_addr(address, &servaddr);
  194. goto done;
  195. - } else if (clnt_st == RPC_PROGVERSMISMATCH) {
  196. - struct rpc_err rpcerr;
  197. + case RPC_PROGVERSMISMATCH:
  198. clnt_geterr(client, &rpcerr);
  199. if (rpcerr.re_vers.low > RPCBVERS4)
  200. goto error; /* a new version, can't handle */
  201. - } else if (clnt_st != RPC_PROGUNAVAIL) {
  202. + /* Try the next lower version */
  203. + case RPC_PROGUNAVAIL:
  204. + case RPC_CANTDECODEARGS:
  205. + break;
  206. + default:
  207. /* Cant handle this error */
  208. rpc_createerr.cf_stat = clnt_st;
  209. clnt_geterr(client, &rpc_createerr.cf_error);
  210. @@ -929,7 +944,7 @@ __rpcb_findaddr_timed(program, version, nconf, host, clpp, tp)
  211. #ifdef PORTMAP /* Try version 2 for TCP or UDP */
  212. if (strcmp(nconf->nc_protofmly, NC_INET) == 0) {
  213. - address = __try_protocol_version_2(program, 2, nconf, host, tp);
  214. + address = __try_protocol_version_2(program, version, nconf, host, tp);
  215. if (address == NULL)
  216. goto error;
  217. }
  218. diff --git a/src/xdr_stdio.c b/src/xdr_stdio.c
  219. index 4410262..846c7bf 100644
  220. --- a/src/xdr_stdio.c
  221. +++ b/src/xdr_stdio.c
  222. @@ -38,6 +38,7 @@
  223. */
  224. #include <stdio.h>
  225. +#include <stdint.h>
  226. #include <arpa/inet.h>
  227. #include <rpc/types.h>
  228. @@ -103,10 +104,12 @@ xdrstdio_getlong(xdrs, lp)
  229. XDR *xdrs;
  230. long *lp;
  231. {
  232. + int32_t mycopy;
  233. - if (fread(lp, sizeof(int32_t), 1, (FILE *)xdrs->x_private) != 1)
  234. + if (fread(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs->x_private) != 1)
  235. return (FALSE);
  236. - *lp = (long)ntohl((u_int32_t)*lp);
  237. +
  238. + *lp = (long)ntohl(mycopy);
  239. return (TRUE);
  240. }
  241. @@ -115,8 +118,14 @@ xdrstdio_putlong(xdrs, lp)
  242. XDR *xdrs;
  243. const long *lp;
  244. {
  245. - long mycopy = (long)htonl((u_int32_t)*lp);
  246. + int32_t mycopy;
  247. +
  248. +#if defined(_LP64)
  249. + if ((*lp > UINT32_MAX) || (*lp < INT32_MIN))
  250. + return (FALSE);
  251. +#endif
  252. + mycopy = (int32_t)htonl((int32_t)*lp);
  253. if (fwrite(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs->x_private) != 1)
  254. return (FALSE);
  255. return (TRUE);