summary refs log tree commit diff
path: root/sunrpc
diff options
context:
space:
mode:
Diffstat (limited to 'sunrpc')
-rw-r--r--sunrpc/Makefile32
-rw-r--r--sunrpc/auth_des.c14
-rw-r--r--sunrpc/auth_none.c6
-rw-r--r--sunrpc/auth_unix.c12
-rw-r--r--sunrpc/bindrsvprt.c30
-rw-r--r--sunrpc/clnt_perr.c21
-rw-r--r--sunrpc/clnt_raw.c4
-rw-r--r--sunrpc/clnt_tcp.c12
-rw-r--r--sunrpc/clnt_udp.c12
-rw-r--r--sunrpc/clnt_unix.c12
-rw-r--r--sunrpc/create_xid.c2
-rw-r--r--sunrpc/des_impl.c35
-rw-r--r--sunrpc/key_call.c91
-rw-r--r--sunrpc/openchild.c2
-rw-r--r--sunrpc/pm_getmaps.c15
-rw-r--r--sunrpc/pm_getport.c52
-rw-r--r--sunrpc/pmap_rmt.c3
-rw-r--r--sunrpc/rpc_clntout.c4
-rw-r--r--sunrpc/rpc_cout.c5
-rw-r--r--sunrpc/rpc_hout.c4
-rw-r--r--sunrpc/rpc_main.c48
-rw-r--r--sunrpc/rpc_parse.c11
-rw-r--r--sunrpc/rpc_sample.c4
-rw-r--r--sunrpc/rpc_scan.c5
-rw-r--r--sunrpc/rpc_svcout.c4
-rw-r--r--sunrpc/rpc_tblout.c4
-rw-r--r--sunrpc/rpc_thread.c5
-rw-r--r--sunrpc/rpc_util.c4
-rw-r--r--sunrpc/rtime.c2
-rw-r--r--sunrpc/svc.c14
-rw-r--r--sunrpc/svc_raw.c4
-rw-r--r--sunrpc/svc_run.c6
-rw-r--r--sunrpc/svc_simple.c14
-rw-r--r--sunrpc/svc_tcp.c18
-rw-r--r--sunrpc/svc_udp.c43
-rw-r--r--sunrpc/svc_unix.c18
-rw-r--r--sunrpc/svcauth_des.c6
-rw-r--r--sunrpc/tst-xdrmem.c205
-rw-r--r--sunrpc/tst-xdrmem2.c114
-rw-r--r--sunrpc/xdr.c33
-rw-r--r--sunrpc/xdr_array.c15
-rw-r--r--sunrpc/xdr_intXX_t.c9
-rw-r--r--sunrpc/xdr_mem.c10
-rw-r--r--sunrpc/xdr_rec.c9
-rw-r--r--sunrpc/xdr_ref.c12
-rw-r--r--sunrpc/xdr_stdio.c12
46 files changed, 417 insertions, 580 deletions
diff --git a/sunrpc/Makefile b/sunrpc/Makefile
index 30f74dc135..284e355cc3 100644
--- a/sunrpc/Makefile
+++ b/sunrpc/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1994-2004, 2005, 2006 Free Software Foundation, Inc.
+# Copyright (C) 1994-2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -85,7 +85,6 @@ all: # Make this the default target; it will be defined in Rules.
 
 include ../Makeconfig
 
-tests = tst-xdrmem tst-xdrmem2
 xtests := tst-getmyaddr
 
 ifeq ($(have-thread-library),yes)
@@ -108,25 +107,28 @@ librpcsvc-inhibit-o = .os # Build no shared rpcsvc library.
 omit-deps = $(librpcsvc-routines)
 endif
 
-CFLAGS-xbootparam_prot.c = -Wno-unused $(PIC-ccflag)
-CFLAGS-xnlm_prot.c = -Wno-unused $(PIC-ccflag)
-CFLAGS-xrstat.c = -Wno-unused $(PIC-ccflag)
-CFLAGS-xyppasswd.c = -Wno-unused $(PIC-ccflag)
-CFLAGS-xklm_prot.c = -Wno-unused $(PIC-ccflag)
-CFLAGS-xrex.c = -Wno-unused $(PIC-ccflag)
-CFLAGS-xsm_inter.c = -Wno-unused $(PIC-ccflag)
-CFLAGS-xmount.c = -Wno-unused $(PIC-ccflag)
-CFLAGS-xrusers.c = -Wno-unused $(PIC-ccflag)
-CFLAGS-xspray.c = -Wno-unused $(PIC-ccflag)
-CFLAGS-xnfs_prot.c = -Wno-unused $(PIC-ccflag)
-CFLAGS-xrquota.c = -Wno-unused $(PIC-ccflag)
-CFLAGS-xkey_prot.c = -Wno-unused $(PIC-ccflag)
+CFLAGS-xbootparam_prot.c = -Wno-unused
+CFLAGS-xnlm_prot.c = -Wno-unused
+CFLAGS-xrstat.c = -Wno-unused
+CFLAGS-xyppasswd.c = -Wno-unused
+CFLAGS-xklm_prot.c = -Wno-unused
+CFLAGS-xrex.c = -Wno-unused
+CFLAGS-xsm_inter.c = -Wno-unused
+CFLAGS-xmount.c = -Wno-unused
+CFLAGS-xrusers.c = -Wno-unused
+CFLAGS-xspray.c = -Wno-unused
+CFLAGS-xnfs_prot.c = -Wno-unused
+CFLAGS-xrquota.c = -Wno-unused
+CFLAGS-xkey_prot.c = -Wno-unused
 CFLAGS-auth_unix.c = -fexceptions
 CFLAGS-key_call.c = -fexceptions
 CFLAGS-pmap_rmt.c = -fexceptions
 CFLAGS-clnt_perr.c = -fexceptions
 CFLAGS-openchild.c = -fexceptions
 
+ifeq (yes,$(have_doors))
+CPPFLAGS-key_call.c += -DHAVE_DOORS=1
+endif
 CPPFLAGS += -D_RPC_THREAD_SAFE_
 
 include ../Rules
diff --git a/sunrpc/auth_des.c b/sunrpc/auth_des.c
index a76f0278ce..fc5956dcd7 100644
--- a/sunrpc/auth_des.c
+++ b/sunrpc/auth_des.c
@@ -66,7 +66,7 @@ static void authdes_destroy (AUTH *);
 static bool_t synchronize (struct sockaddr *, struct rpc_timeval *)
      internal_function;
 
-static const struct auth_ops authdes_ops = {
+static struct auth_ops authdes_ops = {
   authdes_nextverf,
   authdes_marshal,
   authdes_validate,
@@ -107,14 +107,14 @@ authdes_create (const char *servername, u_int window,
   /* syncaddr   - optional addr of host to sync with */
   /* ckey       - optional conversation key to use */
 {
-  char pkey_data[1024];
+  u_char pkey_data[1024];
   netobj pkey;
 
   if (!getpublickey (servername, pkey_data))
     return NULL;
 
-  pkey.n_bytes = pkey_data;
-  pkey.n_len = strlen (pkey_data) + 1;
+  pkey.n_bytes = (char *) pkey_data;
+  pkey.n_len = strlen ((char *) pkey_data) + 1;
   return INTUSE(authdes_pk_create) (servername, &pkey, window, syncaddr, ckey);
 }
 
@@ -174,7 +174,7 @@ authdes_pk_create (const char *servername, netobj *pkey, u_int window,
       if (key_gendes (&auth->ah_key) < 0)
 	{
 	  debug ("authdes_create: unable to gen conversation key");
-	  goto failed;
+	  return NULL;
 	}
     }
   else
@@ -185,7 +185,7 @@ authdes_pk_create (const char *servername, netobj *pkey, u_int window,
    */
   auth->ah_cred.oa_flavor = AUTH_DES;
   auth->ah_verf.oa_flavor = AUTH_DES;
-  auth->ah_ops = (struct auth_ops *) &authdes_ops;
+  auth->ah_ops = &authdes_ops;
   auth->ah_private = (caddr_t) ad;
 
   if (!authdes_refresh (auth))
@@ -237,7 +237,7 @@ authdes_marshal (AUTH *auth, XDR *xdrs)
   des_block cryptbuf[2];
   des_block ivec;
   int status;
-  int len;
+  unsigned int len;
   register int32_t *ixdr;
   struct timeval tval;
 
diff --git a/sunrpc/auth_none.c b/sunrpc/auth_none.c
index f459520a2c..9c4d3fde66 100644
--- a/sunrpc/auth_none.c
+++ b/sunrpc/auth_none.c
@@ -49,7 +49,7 @@ static bool_t authnone_marshal (AUTH *, XDR *);
 static bool_t authnone_validate (AUTH *, struct opaque_auth *);
 static bool_t authnone_refresh (AUTH *);
 
-static const struct auth_ops ops = {
+static struct auth_ops ops = {
   authnone_verf,
   authnone_marshal,
   authnone_validate,
@@ -80,7 +80,7 @@ authnone_create_once (void)
   ap = &authnone_private;
 
   ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
-  ap->no_client.ah_ops = (struct auth_ops *) &ops;
+  ap->no_client.ah_ops = &ops;
   xdrs = &xdr_stream;
   INTUSE(xdrmem_create) (xdrs, ap->marshalled_client,
 			 (u_int) MAX_MARSHAL_SIZE, XDR_ENCODE);
@@ -88,7 +88,7 @@ authnone_create_once (void)
   (void) INTUSE(xdr_opaque_auth) (xdrs, &ap->no_client.ah_verf);
   ap->mcnt = XDR_GETPOS (xdrs);
   XDR_DESTROY (xdrs);
-}
+}  
 
 AUTH *
 authnone_create (void)
diff --git a/sunrpc/auth_unix.c b/sunrpc/auth_unix.c
index 1740e58cdc..1cf18cb6b3 100644
--- a/sunrpc/auth_unix.c
+++ b/sunrpc/auth_unix.c
@@ -65,7 +65,7 @@ static bool_t authunix_validate (AUTH *, struct opaque_auth *);
 static bool_t authunix_refresh (AUTH *);
 static void authunix_destroy (AUTH *);
 
-static const struct auth_ops auth_unix_ops = {
+static struct auth_ops auth_unix_ops = {
   authunix_nextverf,
   authunix_marshal,
   authunix_validate,
@@ -111,12 +111,18 @@ authunix_create (char *machname, uid_t uid, gid_t gid, int len,
   if (auth == NULL || au == NULL)
     {
 no_memory:
-      (void) __fxprintf (NULL, "%s", _("authunix_create: out of memory\n"));
+#ifdef USE_IN_LIBIO
+      if (_IO_fwide (stderr, 0) > 0)
+	(void) __fwprintf (stderr, L"%s",
+			   _("authunix_create: out of memory\n"));
+      else
+#endif
+	(void) fputs (_("authunix_create: out of memory\n"), stderr);
       mem_free (auth, sizeof (*auth));
       mem_free (au, sizeof (*au));
       return NULL;
     }
-  auth->ah_ops = (struct auth_ops *) &auth_unix_ops;
+  auth->ah_ops = &auth_unix_ops;
   auth->ah_private = (caddr_t) au;
   auth->ah_verf = au->au_shcred = _null_auth;
   au->au_shfaults = 0;
diff --git a/sunrpc/bindrsvprt.c b/sunrpc/bindrsvprt.c
index 023ae1723b..374518716e 100644
--- a/sunrpc/bindrsvprt.c
+++ b/sunrpc/bindrsvprt.c
@@ -43,15 +43,14 @@
 int
 bindresvport (int sd, struct sockaddr_in *sin)
 {
+  int res;
   static short port;
   struct sockaddr_in myaddr;
   int i;
 
 #define STARTPORT 600
-#define LOWPORT 512
 #define ENDPORT (IPPORT_RESERVED - 1)
 #define NPORTS	(ENDPORT - STARTPORT + 1)
-  static short startport = STARTPORT;
 
   if (sin == (struct sockaddr_in *) 0)
     {
@@ -69,30 +68,17 @@ bindresvport (int sd, struct sockaddr_in *sin)
     {
       port = (__getpid () % NPORTS) + STARTPORT;
     }
+  res = -1;
+  __set_errno (EADDRINUSE);
 
-  /* Initialize to make gcc happy.  */
-  int res = -1;
-
-  int nports = ENDPORT - startport + 1;
-  int endport = ENDPORT;
- again:
-  for (i = 0; i < nports; ++i)
+  for (i = 0; i < NPORTS && res < 0 && errno == EADDRINUSE; ++i)
     {
       sin->sin_port = htons (port++);
-      if (port > endport)
-	port = startport;
+      if (port > ENDPORT)
+	{
+	  port = STARTPORT;
+	}
       res = __bind (sd, sin, sizeof (struct sockaddr_in));
-      if (res >= 0 || errno != EADDRINUSE)
-	break;
-    }
-
-  if (i == nports && startport != LOWPORT)
-    {
-      startport = LOWPORT;
-      endport = STARTPORT - 1;
-      nports = STARTPORT - LOWPORT;
-      port = LOWPORT + port % (STARTPORT - LOWPORT);
-      goto again;
     }
 
   return res;
diff --git a/sunrpc/clnt_perr.c b/sunrpc/clnt_perr.c
index 6446b32740..4fa5e62c0f 100644
--- a/sunrpc/clnt_perr.c
+++ b/sunrpc/clnt_perr.c
@@ -155,7 +155,12 @@ libc_hidden_def (clnt_sperror)
 void
 clnt_perror (CLIENT * rpch, const char *msg)
 {
-  (void) __fxprintf (NULL, "%s", clnt_sperror (rpch, msg));
+#ifdef USE_IN_LIBIO
+  if (_IO_fwide (stderr, 0) > 0)
+    (void) __fwprintf (stderr, L"%s", clnt_sperror (rpch, msg));
+  else
+#endif
+    (void) fputs (clnt_sperror (rpch, msg), stderr);
 }
 libc_hidden_def (clnt_perror)
 
@@ -284,7 +289,12 @@ libc_hidden_def (clnt_sperrno)
 void
 clnt_perrno (enum clnt_stat num)
 {
-  (void) __fxprintf (NULL, "%s", clnt_sperrno (num));
+#ifdef USE_IN_LIBIO
+  if (_IO_fwide (stderr, 0) > 0)
+    (void) __fwprintf (stderr, L"%s", clnt_sperrno (num));
+  else
+#endif
+    (void) fputs (clnt_sperrno (num), stderr);
 }
 
 
@@ -327,7 +337,12 @@ libc_hidden_def (clnt_spcreateerror)
 void
 clnt_pcreateerror (const char *msg)
 {
-  (void) __fxprintf (NULL, "%s", clnt_spcreateerror (msg));
+#ifdef USE_IN_LIBIO
+  if (_IO_fwide (stderr, 0) > 0)
+    (void) __fwprintf (stderr, L"%s", clnt_spcreateerror (msg));
+  else
+#endif
+    (void) fputs (clnt_spcreateerror (msg), stderr);
 }
 
 struct auth_errtab
diff --git a/sunrpc/clnt_raw.c b/sunrpc/clnt_raw.c
index 019f1bbae0..e8613422a5 100644
--- a/sunrpc/clnt_raw.c
+++ b/sunrpc/clnt_raw.c
@@ -74,7 +74,7 @@ static bool_t clntraw_freeres (CLIENT *, xdrproc_t, caddr_t);
 static bool_t clntraw_control (CLIENT *, int, char *);
 static void clntraw_destroy (CLIENT *);
 
-static const struct clnt_ops client_ops =
+static struct clnt_ops client_ops =
 {
   clntraw_call,
   clntraw_abort,
@@ -127,7 +127,7 @@ clntraw_create (u_long prog, u_long vers)
   /*
    * create client handle
    */
-  client->cl_ops = (struct clnt_ops *) &client_ops;
+  client->cl_ops = &client_ops;
   client->cl_auth = INTUSE(authnone_create) ();
   return client;
 }
diff --git a/sunrpc/clnt_tcp.c b/sunrpc/clnt_tcp.c
index 5bec3bcf3a..5d02cd99cb 100644
--- a/sunrpc/clnt_tcp.c
+++ b/sunrpc/clnt_tcp.c
@@ -91,7 +91,7 @@ static bool_t clnttcp_freeres (CLIENT *, xdrproc_t, caddr_t);
 static bool_t clnttcp_control (CLIENT *, int, char *);
 static void clnttcp_destroy (CLIENT *);
 
-static const struct clnt_ops tcp_ops =
+static struct clnt_ops tcp_ops =
 {
   clnttcp_call,
   clnttcp_abort,
@@ -128,7 +128,13 @@ clnttcp_create (struct sockaddr_in *raddr, u_long prog, u_long vers,
   if (h == NULL || ct == NULL)
     {
       struct rpc_createerr *ce = &get_rpc_createerr ();
-      (void) __fxprintf (NULL, "%s", _("clnttcp_create: out of memory\n"));
+#ifdef USE_IN_LIBIO
+      if (_IO_fwide (stderr, 0) > 0)
+	(void) __fwprintf (stderr, L"%s",
+			   _("clnttcp_create: out of memory\n"));
+      else
+#endif
+	(void) fputs (_("clnttcp_create: out of memory\n"), stderr);
       ce->cf_stat = RPC_SYSTEMERROR;
       ce->cf_error.re_errno = ENOMEM;
       goto fooy;
@@ -213,7 +219,7 @@ clnttcp_create (struct sockaddr_in *raddr, u_long prog, u_long vers,
    */
   INTUSE(xdrrec_create) (&(ct->ct_xdrs), sendsz, recvsz,
 			 (caddr_t) ct, readtcp, writetcp);
-  h->cl_ops = (struct clnt_ops *) &tcp_ops;
+  h->cl_ops = &tcp_ops;
   h->cl_private = (caddr_t) ct;
   h->cl_auth = INTUSE(authnone_create) ();
   return h;
diff --git a/sunrpc/clnt_udp.c b/sunrpc/clnt_udp.c
index 8c24677c83..f3787dd1a5 100644
--- a/sunrpc/clnt_udp.c
+++ b/sunrpc/clnt_udp.c
@@ -74,7 +74,7 @@ static bool_t clntudp_freeres (CLIENT *, xdrproc_t, caddr_t);
 static bool_t clntudp_control (CLIENT *, int, char *);
 static void clntudp_destroy (CLIENT *);
 
-static const struct clnt_ops udp_ops =
+static struct clnt_ops udp_ops =
 {
   clntudp_call,
   clntudp_abort,
@@ -136,7 +136,13 @@ clntudp_bufcreate (struct sockaddr_in *raddr, u_long program, u_long version,
   if (cl == NULL || cu == NULL)
     {
       struct rpc_createerr *ce = &get_rpc_createerr ();
-      (void) __fxprintf (NULL, "%s", _("clntudp_create: out of memory\n"));
+#ifdef USE_IN_LIBIO
+      if (_IO_fwide (stderr, 0) > 0)
+	(void) __fwprintf (stderr, L"%s",
+			   _("clntudp_create: out of memory\n"));
+      else
+#endif
+	(void) fputs (_("clntudp_create: out of memory\n"), stderr);
       ce->cf_stat = RPC_SYSTEMERROR;
       ce->cf_error.re_errno = ENOMEM;
       goto fooy;
@@ -153,7 +159,7 @@ clntudp_bufcreate (struct sockaddr_in *raddr, u_long program, u_long version,
 	}
       raddr->sin_port = htons (port);
     }
-  cl->cl_ops = (struct clnt_ops *) &udp_ops;
+  cl->cl_ops = &udp_ops;
   cl->cl_private = (caddr_t) cu;
   cu->cu_raddr = *raddr;
   cu->cu_rlen = sizeof (cu->cu_raddr);
diff --git a/sunrpc/clnt_unix.c b/sunrpc/clnt_unix.c
index 848a480581..fae1cd8229 100644
--- a/sunrpc/clnt_unix.c
+++ b/sunrpc/clnt_unix.c
@@ -88,7 +88,7 @@ static bool_t clntunix_freeres (CLIENT *, xdrproc_t, caddr_t);
 static bool_t clntunix_control (CLIENT *, int, char *);
 static void clntunix_destroy (CLIENT *);
 
-static const struct clnt_ops unix_ops =
+static struct clnt_ops unix_ops =
 {
   clntunix_call,
   clntunix_abort,
@@ -125,7 +125,13 @@ clntunix_create (struct sockaddr_un *raddr, u_long prog, u_long vers,
   if (h == NULL || ct == NULL)
     {
       struct rpc_createerr *ce = &get_rpc_createerr ();
-      (void) __fxprintf (NULL, "%s", _("clntunix_create: out of memory\n"));
+#ifdef USE_IN_LIBIO
+      if (_IO_fwide (stderr, 0) > 0)
+	(void) __fwprintf (stderr, L"%s",
+			   _("clntunix_create: out of memory\n"));
+      else
+#endif
+	(void) fputs (_("clntunix_create: out of memory\n"), stderr);
       ce->cf_stat = RPC_SYSTEMERROR;
       ce->cf_error.re_errno = ENOMEM;
       goto fooy;
@@ -192,7 +198,7 @@ clntunix_create (struct sockaddr_un *raddr, u_long prog, u_long vers,
    */
   INTUSE(xdrrec_create) (&(ct->ct_xdrs), sendsz, recvsz,
 			 (caddr_t) ct, readunix, writeunix);
-  h->cl_ops = (struct clnt_ops *) &unix_ops;
+  h->cl_ops = &unix_ops;
   h->cl_private = (caddr_t) ct;
   h->cl_auth = INTUSE(authnone_create) ();
   return h;
diff --git a/sunrpc/create_xid.c b/sunrpc/create_xid.c
index 4e76918644..21b83a7656 100644
--- a/sunrpc/create_xid.c
+++ b/sunrpc/create_xid.c
@@ -33,7 +33,7 @@ static struct drand48_data __rpc_lrand48_data;
 unsigned long
 _create_xid (void)
 {
-  long int res;
+  unsigned long res;
 
   __libc_lock_lock (createxid_lock);
 
diff --git a/sunrpc/des_impl.c b/sunrpc/des_impl.c
index dc94e221ab..702bd02c77 100644
--- a/sunrpc/des_impl.c
+++ b/sunrpc/des_impl.c
@@ -6,11 +6,10 @@
 /* write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,*/
 /* Boston, MA 02111, USA to obtain a copy. */
 #include <string.h>
-#include <stdint.h>
 #include "des.h"
 
 
-static const uint32_t des_SPtrans[8][64] =
+static const unsigned long des_SPtrans[8][64] =
 {
   {				/* nibble 0 */
     0x00820200, 0x00020000, 0x80800000, 0x80820200,
@@ -156,7 +155,7 @@ static const uint32_t des_SPtrans[8][64] =
     0x00000020, 0x08208000, 0x00208020, 0x00000000,
     0x08000000, 0x08200020, 0x00008000, 0x00208020}};
 
-static const uint32_t des_skb[8][64] =
+static const unsigned long des_skb[8][64] =
 {
   {				/* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
     0x00000000, 0x00000010, 0x20000000, 0x20000010,
@@ -353,6 +352,26 @@ static const uint32_t des_skb[8][64] =
 	(a)=(a)^(t)^(t>>(16-(n))))
 
 
+/* The changes to this macro may help or hinder, depending on the
+ * compiler and the achitecture.  gcc2 always seems to do well :-).
+ * Inspired by Dana How <how@isl.stanford.edu>
+ * DO NOT use the alternative version on machines with 8 byte longs.
+ */
+#ifdef ALT_ECB
+#define D_ENCRYPT(L,R,S) \
+	u=((R^s[S  ])<<2);	\
+	t= R^s[S+1]; \
+	t=((t>>2)+(t<<30)); \
+	L^= \
+	*(const unsigned long *)(des_SP+0x0100+((t    )&0xfc))+ \
+	*(const unsigned long *)(des_SP+0x0300+((t>> 8)&0xfc))+ \
+	*(const unsigned long *)(des_SP+0x0500+((t>>16)&0xfc))+ \
+	*(const unsigned long *)(des_SP+0x0700+((t>>24)&0xfc))+ \
+	*(const unsigned long *)(des_SP+       ((u    )&0xfc))+ \
+  	*(const unsigned long *)(des_SP+0x0200+((u>> 8)&0xfc))+ \
+  	*(const unsigned long *)(des_SP+0x0400+((u>>16)&0xfc))+ \
+ 	*(const unsigned long *)(des_SP+0x0600+((u>>24)&0xfc));
+#else /* original version */
 #define D_ENCRYPT(L,R,S)	\
 	u=(R^s[S  ]); \
 	t=R^s[S+1]; \
@@ -365,20 +384,21 @@ static const uint32_t des_skb[8][64] =
 		des_SPtrans[2][(u>> 8)&0x3f]| \
 		des_SPtrans[4][(u>>16)&0x3f]| \
 		des_SPtrans[6][(u>>24)&0x3f];
+#endif
 
 #define ITERATIONS 16
 
 static const char shifts2[16] =
 {0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0};
 
-static void des_set_key (unsigned char *, unsigned long *) internal_function;
+static void des_set_key (char *, unsigned long *) internal_function;
 static void des_encrypt (unsigned long *, unsigned long *, int)
      internal_function;
 int _des_crypt (char *, unsigned, struct desparams *);
 
 static void
 internal_function
-des_set_key (unsigned char *key, unsigned long *schedule)
+des_set_key (char *key, unsigned long *schedule)
 {
   register unsigned long c, d, t, s;
   register unsigned char *in;
@@ -386,7 +406,7 @@ des_set_key (unsigned char *key, unsigned long *schedule)
   register int i;
 
   k = (unsigned long *) schedule;
-  in = key;
+  in = (unsigned char *) key;
 
   c2l (in, c);
   c2l (in, d);
@@ -444,6 +464,9 @@ internal_function
 des_encrypt (unsigned long *buf, unsigned long *schedule, int encrypt)
 {
   register unsigned long l, r, t, u;
+#ifdef ALT_ECB
+  register const unsigned char *des_SP = (const unsigned char *) des_SPtrans;
+#endif
   register int i;
   register unsigned long *s;
 
diff --git a/sunrpc/key_call.c b/sunrpc/key_call.c
index 611c37256c..211f61db70 100644
--- a/sunrpc/key_call.c
+++ b/sunrpc/key_call.c
@@ -51,6 +51,10 @@
 #include <rpc/key_prot.h>
 #include <bits/libc-lock.h>
 
+#ifdef HAVE_DOORS
+# include "door/door.h"
+#endif
+
 #define KEY_TIMEOUT	5	/* per-try timeout in seconds */
 #define KEY_NRETRY	12	/* number of retries */
 
@@ -382,7 +386,7 @@ getkeyserv_handle (int vers)
   struct timeval wait_time;
   int fd;
   struct sockaddr_un name;
-  socklen_t namelen = sizeof(struct sockaddr_un);
+  int namelen = sizeof(struct sockaddr_un);
 
 #define TOTAL_TIMEOUT   30      /* total timeout talking to keyserver */
 #define TOTAL_TRIES     5       /* Number of tries */
@@ -400,7 +404,6 @@ getkeyserv_handle (int vers)
   /* if pid has changed, destroy client and rebuild */
   if (kcp->client != NULL && kcp->pid != __getpid ())
     {
-      auth_destroy (kcp->client->cl_auth);
       clnt_destroy (kcp->client);
       kcp->client = NULL;
     }
@@ -500,6 +503,73 @@ key_call_socket (u_long proc, xdrproc_t xdr_arg, char *arg,
   return result;
 }
 
+#ifdef HAVE_DOORS
+/* returns 0 on failure, 1 on success */
+static int
+internal_function
+key_call_door (u_long proc, xdrproc_t xdr_arg, char *arg,
+	       xdrproc_t xdr_rslt, char *rslt)
+{
+  XDR xdrs;
+  int fd, ret;
+  door_arg_t args;
+  char *data_ptr;
+  u_long data_len = 0;
+  char res[255];
+
+  if ((fd = open("/var/run/keyservdoor", O_RDONLY)) < 0)
+    return 0;
+  res[0] = 0;
+
+  data_len = xdr_sizeof (xdr_arg, arg);
+  data_ptr = calloc (1, data_len + 2 * sizeof (u_long));
+  if (data_ptr == NULL)
+    return 0;
+
+  INTUSE(xdrmem_create) (&xdrs, &data_ptr[2 * sizeof (u_long)], data_len,
+			 XDR_ENCODE);
+  if (!xdr_arg (&xdrs, arg))
+    {
+      xdr_destroy (&xdrs);
+      free (data_ptr);
+      return 0;
+    }
+  xdr_destroy (&xdrs);
+
+  memcpy (data_ptr, &proc, sizeof (u_long));
+  memcpy (&data_ptr[sizeof (proc)], &data_len, sizeof (u_long));
+
+  args.data_ptr = data_ptr;
+  args.data_size = data_len + 2 * sizeof (u_long);
+  args.desc_ptr = NULL;
+  args.desc_num = 0;
+  args.rbuf = res;
+  args.rsize = sizeof (res);
+
+  ret = __door_call (fd, &args);
+  free (data_ptr);
+  close (fd);
+
+  if (ret < 0)
+    return 0;
+
+  memcpy (&data_len, args.data_ptr, sizeof (u_long));
+  if (data_len != 0)
+    return 0;
+
+  memcpy (&data_len, &args.data_ptr[sizeof (u_long)], sizeof (u_long));
+  INTUSE(xdrmem_create) (&xdrs, &args.data_ptr[2 * sizeof (u_long)],
+			 data_len, XDR_DECODE);
+  if (!xdr_rslt (&xdrs, rslt))
+    {
+      xdr_destroy (&xdrs);
+      return 0;
+    }
+  xdr_destroy (&xdrs);
+
+  return 1;
+}
+#endif
 
 /* returns 0 on failure, 1 on success */
 static int
@@ -510,6 +580,9 @@ key_call (u_long proc, xdrproc_t xdr_arg, char *arg,
 #ifndef SO_PASSCRED
   static int use_keyenvoy;
 #endif
+#ifdef HAVE_DOORS
+  static int not_use_doors;
+#endif
 
   if (proc == KEY_ENCRYPT_PK && __key_encryptsession_pk_LOCAL)
     {
@@ -533,6 +606,15 @@ key_call (u_long proc, xdrproc_t xdr_arg, char *arg,
       return 1;
     }
 
+#ifdef HAVE_DOORS
+  if (!not_use_doors)
+    {
+      if (key_call_door (proc, xdr_arg, arg, xdr_rslt, rslt))
+	return 1;
+      not_use_doors = 1;
+    }
+#endif
+
 #ifdef SO_PASSCRED
   return key_call_socket (proc, xdr_arg, arg, xdr_rslt, rslt);
 #else
@@ -553,11 +635,8 @@ __rpc_thread_key_cleanup (void)
 	struct key_call_private *kcp = RPC_THREAD_VARIABLE(key_call_private_s);
 
 	if (kcp) {
-		if (kcp->client) {
-			if (kcp->client->cl_auth)
-				auth_destroy (kcp->client->cl_auth);
+		if (kcp->client)
 			clnt_destroy(kcp->client);
-		}
 		free (kcp);
 	}
 }
diff --git a/sunrpc/openchild.c b/sunrpc/openchild.c
index 29ddfa6b75..16f6a34e7a 100644
--- a/sunrpc/openchild.c
+++ b/sunrpc/openchild.c
@@ -81,7 +81,7 @@ _openchild (const char *command, FILE ** fto, FILE ** ffrom)
       for (i = _rpc_dtablesize () - 1; i >= 3; i--)
 	__close (i);
       fflush (stderr);
-      execlp (command, command, NULL);
+      execlp (command, command, 0);
       perror ("exec");
       _exit (~0);
 
diff --git a/sunrpc/pm_getmaps.c b/sunrpc/pm_getmaps.c
index 2a6876d9d8..d1d4ca8769 100644
--- a/sunrpc/pm_getmaps.c
+++ b/sunrpc/pm_getmaps.c
@@ -44,12 +44,9 @@ static char sccsid[] = "@(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro";
 #include <rpc/pmap_clnt.h>
 #include <sys/socket.h>
 #include <netdb.h>
-#include <stdbool.h>
 #include <stdio.h>
 #include <errno.h>
 #include <libintl.h>
-#include <unistd.h>
-
 
 /*
  * Get a copy of the current port maps.
@@ -59,19 +56,13 @@ struct pmaplist *
 pmap_getmaps (struct sockaddr_in *address)
 {
   struct pmaplist *head = (struct pmaplist *) NULL;
+  int socket = -1;
   struct timeval minutetimeout;
   CLIENT *client;
-  bool closeit = false;
 
   minutetimeout.tv_sec = 60;
   minutetimeout.tv_usec = 0;
   address->sin_port = htons (PMAPPORT);
-
-  /* Don't need a reserved port to get ports from the portmapper.  */
-  int socket = __get_socket (address);
-  if (socket != -1)
-    closeit = true;
-
   client = INTUSE(clnttcp_create) (address, PMAPPROG,
 				   PMAPVERS, &socket, 50, 500);
   if (client != (CLIENT *) NULL)
@@ -84,9 +75,7 @@ pmap_getmaps (struct sockaddr_in *address)
 	}
       CLNT_DESTROY (client);
     }
-  /* We only need to close the socket here if we opened  it.  */
-  if (closeit)
-    (void) __close (socket);
+  /* (void)close(socket); CLNT_DESTROY already closed it */
   address->sin_port = 0;
   return head;
 }
diff --git a/sunrpc/pm_getport.c b/sunrpc/pm_getport.c
index 2d309841f3..00e1ba95bf 100644
--- a/sunrpc/pm_getport.c
+++ b/sunrpc/pm_getport.c
@@ -38,8 +38,6 @@ static char sccsid[] = "@(#)pmap_getport.c 1.9 87/08/11 Copyr 1984 Sun Micro";
  * Copyright (C) 1984, Sun Microsystems, Inc.
  */
 
-#include <stdbool.h>
-#include <unistd.h>
 #include <rpc/rpc.h>
 #include <rpc/pmap_prot.h>
 #include <rpc/pmap_clnt.h>
@@ -51,41 +49,6 @@ static const struct timeval tottimeout =
 {60, 0};
 
 /*
- * Create a socket that is locally bound to a non-reserve port. For
- * any failures, -1 is returned which will cause the RPC code to
- * create the socket.
- */
-int
-internal_function
-__get_socket (struct sockaddr_in *saddr)
-{
-  int so = __socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
-  if (so < 0)
-    return -1;
-
-  struct sockaddr_in laddr;
-  socklen_t namelen = sizeof (laddr);
-  laddr.sin_family = AF_INET;
-  laddr.sin_port = 0;
-  laddr.sin_addr.s_addr = htonl (INADDR_ANY);
-
-  int cc = __bind (so, (struct sockaddr *) &laddr, namelen);
-  if (__builtin_expect (cc < 0, 0))
-    {
-    fail:
-      __close (so);
-      return -1;
-    }
-
-  cc = __connect (so, (struct sockaddr *) saddr, namelen);
-  if (__builtin_expect (cc < 0, 0))
-    goto fail;
-
-  return so;
-}
-
-
-/*
  * Find the mapped port for program,version.
  * Calls the pmap service remotely to do the lookup.
  * Returns 0 if no map exists.
@@ -101,18 +64,11 @@ pmap_getport (address, program, version, protocol)
   int socket = -1;
   CLIENT *client;
   struct pmap parms;
-  bool closeit = false;
 
   address->sin_port = htons (PMAPPORT);
   if (protocol == IPPROTO_TCP)
-    {
-      /* Don't need a reserved port to get ports from the portmapper.  */
-      socket = __get_socket(address);
-      if (socket != -1)
-	closeit = true;
-      client = INTUSE(clnttcp_create) (address, PMAPPROG, PMAPVERS, &socket,
-				       RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
-    }
+    client = INTUSE(clnttcp_create) (address, PMAPPROG, PMAPVERS, &socket,
+				     RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
   else
     client = INTUSE(clntudp_bufcreate) (address, PMAPPROG, PMAPVERS, timeout,
 					&socket, RPCSMALLMSGSIZE,
@@ -137,9 +93,7 @@ pmap_getport (address, program, version, protocol)
 	}
       CLNT_DESTROY (client);
     }
-  /* We only need to close the socket here if we opened  it.  */
-  if (closeit)
-    (void) __close (socket);
+  /* (void)close(socket); CLNT_DESTROY already closed it */
   address->sin_port = 0;
   return port;
 }
diff --git a/sunrpc/pmap_rmt.c b/sunrpc/pmap_rmt.c
index e068848919..644d503a1f 100644
--- a/sunrpc/pmap_rmt.c
+++ b/sunrpc/pmap_rmt.c
@@ -125,9 +125,8 @@ xdr_rmtcall_args (XDR *xdrs, struct rmtcallargs *cap)
       INTUSE(xdr_u_long) (xdrs, &(cap->vers)) &&
       INTUSE(xdr_u_long) (xdrs, &(cap->proc)))
     {
-      u_long dummy_arglen = 0;
       lenposition = XDR_GETPOS (xdrs);
-      if (!INTUSE(xdr_u_long) (xdrs, &dummy_arglen))
+      if (!INTUSE(xdr_u_long) (xdrs, &(cap->arglen)))
 	return FALSE;
       argposition = XDR_GETPOS (xdrs);
       if (!(*(cap->xdr_args)) (xdrs, cap->args_ptr))
diff --git a/sunrpc/rpc_clntout.c b/sunrpc/rpc_clntout.c
index 08d9601212..4e2832ff56 100644
--- a/sunrpc/rpc_clntout.c
+++ b/sunrpc/rpc_clntout.c
@@ -31,6 +31,10 @@
 /*
  * From: @(#)rpc_clntout.c 1.11 89/02/22 (C) 1987 SMI
  */
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char clntout_rcsid[] =
+  "$Id$";
+#endif
 
 /*
  * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
diff --git a/sunrpc/rpc_cout.c b/sunrpc/rpc_cout.c
index 21056e84a6..a803feb65a 100644
--- a/sunrpc/rpc_cout.c
+++ b/sunrpc/rpc_cout.c
@@ -31,6 +31,10 @@
 /*
  * From: @(#)rpc_cout.c 1.13 89/02/22 (C) 1987 SMI
  */
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char cout_rcsid[] =
+"$Id$";
+#endif
 
 /*
  * rpc_cout.c, XDR routine outputter for the RPC protocol compiler
@@ -551,7 +555,6 @@ inline_struct (definition *def, int flag)
 	    }
 	  size = 0;
 	  i = 0;
-	  free (sizestr);
 	  sizestr = NULL;
 	  print_stat (indent + 1, &dl->decl);
 	}
diff --git a/sunrpc/rpc_hout.c b/sunrpc/rpc_hout.c
index 270d149a6e..38cb419527 100644
--- a/sunrpc/rpc_hout.c
+++ b/sunrpc/rpc_hout.c
@@ -31,6 +31,10 @@
 /*
  * From: @(#)rpc_hout.c 1.12 89/02/22 (C) 1987 SMI
  */
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char hout_rcsid[] =
+  "$Id$";
+#endif
 
 /*
  * rpc_hout.c, Header file outputter for the RPC protocol compiler
diff --git a/sunrpc/rpc_main.c b/sunrpc/rpc_main.c
index 954657a7e4..fee83514d1 100644
--- a/sunrpc/rpc_main.c
+++ b/sunrpc/rpc_main.c
@@ -31,6 +31,10 @@
 /*
  * From @(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI;
  */
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char main_rcsid[] =
+  "$Id$";
+#endif
 
 /*
  * rpc_main.c, Top level of the RPC protocol compiler.
@@ -531,7 +535,7 @@ generate_guard (const char *pathname)
 
   filename = strrchr (pathname, '/');	/* find last component */
   filename = ((filename == NULL) ? pathname : filename + 1);
-  guard = extendfile (filename, "_H_RPCGEN");
+  guard = strdup (filename);
   /* convert to upper case */
   tmp = guard;
   while (*tmp)
@@ -541,6 +545,7 @@ generate_guard (const char *pathname)
       tmp++;
     }
 
+  guard = extendfile (guard, "_H_RPCGEN");
   return guard;
 }
 
@@ -660,7 +665,6 @@ h_output (const char *infile, const char *define, int extend,
     }
 
   fprintf (fout, "\n#endif /* !_%s */\n", guard);
-  free (guard);
   close_input ();
   close_output (outfilename);
 }
@@ -691,9 +695,11 @@ s_output (int argc, const char *argv[], const char *infile, const char *define,
 
   fprintf (fout, "#include <stdio.h>\n");
   fprintf (fout, "#include <stdlib.h>\n");
-  fprintf (fout, "#include <rpc/pmap_clnt.h>\n");
   if (Cflag)
-    fprintf (fout, "#include <string.h>\n");
+    {
+      fprintf (fout, "#include <rpc/pmap_clnt.h>\n");
+      fprintf (fout, "#include <string.h>\n");
+    }
   if (strcmp (svcclosetime, "-1") == 0)
     indefinitewait = 1;
   else if (strcmp (svcclosetime, "0") == 0)
@@ -946,8 +952,6 @@ clnt_output (const char *infile, const char *define, int extend,
   close_output (outfilename);
 }
 
-static const char space[] = " ";
-
 static char *
 file_name (const char *file, const char *ext)
 {
@@ -956,17 +960,16 @@ file_name (const char *file, const char *ext)
 
   if (access (temp, F_OK) != -1)
     return (temp);
-
-  free (temp);
-  return (char *) space;
+  else
+    return ((char *) " ");
 }
 
 static void
 mkfile_output (struct commandline *cmd)
 {
   char *mkfilename;
-  char *clientname, *clntname, *xdrname, *hdrname;
-  char *servername, *svcname, *servprogname, *clntprogname;
+  const char *clientname, *clntname, *xdrname, *hdrname;
+  const char *servername, *svcname, *servprogname, *clntprogname;
 
   svcname = file_name (cmd->infile, "_svc.c");
   clntname = file_name (cmd->infile, "_clnt.c");
@@ -980,8 +983,8 @@ mkfile_output (struct commandline *cmd)
     }
   else
     {
-      servername = (char *) space;
-      clientname = (char *) space;
+      servername = " ";
+      clientname = " ";
     }
   servprogname = extendfile (cmd->infile, "_server");
   clntprogname = extendfile (cmd->infile, "_client");
@@ -991,8 +994,6 @@ mkfile_output (struct commandline *cmd)
       char *cp, *temp;
 
       mkfilename = alloc (strlen ("Makefile.") + strlen (cmd->infile) + 1);
-      if (mkfilename == NULL)
-	abort ();
       temp = rindex (cmd->infile, '.');
       cp = stpcpy (mkfilename, "Makefile.");
       strncpy (cp, cmd->infile, (temp - cmd->infile));
@@ -1051,23 +1052,6 @@ $(LDLIBS) \n\n");
   f_print (fout, "clean:\n\t $(RM) core $(TARGETS) $(OBJECTS_CLNT) \
 $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
   close_output (mkfilename);
-
-  free (clntprogname);
-  free (servprogname);
-  if (servername != space)
-    free (servername);
-  if (clientname != space)
-    free (clientname);
-  if (mkfilename != (char *) cmd->outfile)
-    free (mkfilename);
-  if (svcname != space)
-    free (svcname);
-  if (clntname != space)
-    free (clntname);
-  if (xdrname != space)
-    free (xdrname);
-  if (hdrname != space)
-    free (hdrname);
 }
 
 /*
diff --git a/sunrpc/rpc_parse.c b/sunrpc/rpc_parse.c
index f66538701f..7115cbdd08 100644
--- a/sunrpc/rpc_parse.c
+++ b/sunrpc/rpc_parse.c
@@ -31,6 +31,10 @@
 /*
  * From: @(#)rpc_parse.c 1.8 89/02/22 (C) 1987 SMI
  */
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char parse_rcsid[] =
+  "$Id$";
+#endif
 
 /*
  * rpc_parse.c, Parser for the RPC protocol compiler
@@ -91,7 +95,6 @@ get_definition (void)
       def_const (defp);
       break;
     case TOK_EOF:
-      free (defp);
       return (NULL);
     default:
       error ("definition keyword expected");
@@ -303,9 +306,7 @@ def_union (definition *defp)
   case_list *cases;
 /*  case_list *tcase; */
   case_list **tailp;
-#if 0
   int flag;
-#endif
 
   defp->def_kind = DEF_UNION;
   scan (TOK_IDENT, &tok);
@@ -325,9 +326,7 @@ def_union (definition *defp)
       cases->case_name = tok.str;
       scan (TOK_COLON, &tok);
       /* now peek at next token */
-#if 0
       flag = 0;
-#endif
       if (peekscan (TOK_CASE, &tok))
 	{
 
@@ -344,7 +343,6 @@ def_union (definition *defp)
 	    }
 	  while (peekscan (TOK_CASE, &tok));
 	}
-#if 0
       else if (flag)
 	{
 
@@ -352,7 +350,6 @@ def_union (definition *defp)
 	  tailp = &cases->next;
 	  cases = ALLOC (case_list);
 	};
-#endif
 
       get_declaration (&dec, DEF_UNION);
       cases->case_decl = dec;
diff --git a/sunrpc/rpc_sample.c b/sunrpc/rpc_sample.c
index 00b58d5bc2..50c3d5554b 100644
--- a/sunrpc/rpc_sample.c
+++ b/sunrpc/rpc_sample.c
@@ -31,6 +31,10 @@
 /*
  * From: @(#)rpc_sample.c  1.1  90/08/30  (C) 1987 SMI
  */
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char sample_rcsid[] =
+  "$Id$";
+#endif
 
 /*
  * rpc_sample.c, Sample client-server code outputter for the RPC protocol compiler
diff --git a/sunrpc/rpc_scan.c b/sunrpc/rpc_scan.c
index af90ef6973..d6211e9105 100644
--- a/sunrpc/rpc_scan.c
+++ b/sunrpc/rpc_scan.c
@@ -31,6 +31,10 @@
 /*
  * From: @(#)rpc_scan.c 1.11 89/02/22 (C) 1987 SMI
  */
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char scan_rcsid[] =
+  "$Id$";
+#endif
 
 /*
  * rpc_scan.c, Scanner for the RPC protocol compiler
@@ -535,7 +539,6 @@ docppline (const char *line, int *lineno, const char **fname)
   *p = 0;
   if (*file == 0)
     {
-      free (file);
       *fname = NULL;
     }
   else
diff --git a/sunrpc/rpc_svcout.c b/sunrpc/rpc_svcout.c
index 6774cc8c0f..9a807c4096 100644
--- a/sunrpc/rpc_svcout.c
+++ b/sunrpc/rpc_svcout.c
@@ -31,6 +31,10 @@
 /*
  * From: @(#)rpc_svcout.c 1.29 89/03/30 (C) 1987 SMI
  */
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char svcout_rcsid[] =
+  "$Id$";
+#endif
 
 /*
  * rpc_svcout.c, Server-skeleton outputter for the RPC protocol compiler
diff --git a/sunrpc/rpc_tblout.c b/sunrpc/rpc_tblout.c
index 8fd2b1267d..bf4037fc37 100644
--- a/sunrpc/rpc_tblout.c
+++ b/sunrpc/rpc_tblout.c
@@ -31,6 +31,10 @@
 /*
  * From: @(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI
  */
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char tblout_rcsid[] =
+  "$Id$";
+#endif
 
 /*
  * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
diff --git a/sunrpc/rpc_thread.c b/sunrpc/rpc_thread.c
index 91e94c2eab..fbc1cf72fe 100644
--- a/sunrpc/rpc_thread.c
+++ b/sunrpc/rpc_thread.c
@@ -20,7 +20,7 @@ __rpc_thread_destroy (void)
 {
 	struct rpc_thread_variables *tvp = __libc_tsd_get (RPC_VARS);
 
-	if (tvp != NULL) {
+	if (tvp != NULL && tvp != &__libc_tsd_RPC_VARS_mem) {
 		__rpc_thread_svc_cleanup ();
 		__rpc_thread_clnt_cleanup ();
 		__rpc_thread_key_cleanup ();
@@ -29,8 +29,7 @@ __rpc_thread_destroy (void)
 		free (tvp->svcraw_private_s);
 		free (tvp->authdes_cache_s);
 		free (tvp->authdes_lru_s);
-		if (tvp != &__libc_tsd_RPC_VARS_mem)
-			free (tvp);
+		free (tvp);
 		__libc_tsd_set (RPC_VARS, NULL);
 	}
 }
diff --git a/sunrpc/rpc_util.c b/sunrpc/rpc_util.c
index b910401a31..31e1d3143c 100644
--- a/sunrpc/rpc_util.c
+++ b/sunrpc/rpc_util.c
@@ -31,6 +31,10 @@
 /*
  * From: @(#)rpc_util.c 1.11 89/02/22 (C) 1987 SMI
  */
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char util_rcsid[] =
+  "$Id$";
+#endif
 
 /*
  * rpc_util.c, Utility routines for the RPC protocol compiler
diff --git a/sunrpc/rtime.c b/sunrpc/rtime.c
index ff71a55aeb..4996f01ba9 100644
--- a/sunrpc/rtime.c
+++ b/sunrpc/rtime.c
@@ -80,7 +80,7 @@ rtime (struct sockaddr_in *addrp, struct rpc_timeval *timep,
   /* RFC 868 says the time is transmitted as a 32-bit value.  */
   uint32_t thetime;
   struct sockaddr_in from;
-  socklen_t fromlen;
+  int fromlen;
   int type;
 
   if (timeout == NULL)
diff --git a/sunrpc/svc.c b/sunrpc/svc.c
index 1e358e247c..6caf8412d5 100644
--- a/sunrpc/svc.c
+++ b/sunrpc/svc.c
@@ -372,7 +372,7 @@ svc_getreqset (fd_set *readfds)
     setsize = FD_SETSIZE;
   maskp = readfds->fds_bits;
   for (sock = 0; sock < setsize; sock += NFDBITS)
-    for (mask = *maskp++; (bit = ffsl (mask)); mask ^= (1L << (bit - 1)))
+    for (mask = *maskp++; (bit = ffs (mask)); mask ^= (1 << (bit - 1)))
       INTUSE(svc_getreq_common) (sock + bit - 1);
 }
 INTDEF (svc_getreqset)
@@ -380,24 +380,22 @@ INTDEF (svc_getreqset)
 void
 svc_getreq_poll (struct pollfd *pfdp, int pollretval)
 {
-  if (pollretval == 0)
-    return;
-
+  register int i;
   register int fds_found;
-  for (int i = fds_found = 0; i < svc_max_pollfd; ++i)
+
+  for (i = fds_found = 0; i < svc_max_pollfd && fds_found < pollretval; ++i)
     {
       register struct pollfd *p = &pfdp[i];
 
       if (p->fd != -1 && p->revents)
 	{
 	  /* fd has input waiting */
+	  ++fds_found;
+
 	  if (p->revents & POLLNVAL)
 	    xprt_unregister (xports[p->fd]);
 	  else
 	    INTUSE(svc_getreq_common) (p->fd);
-
-	  if (++fds_found >= pollretval)
-	    break;
 	}
     }
 }
diff --git a/sunrpc/svc_raw.c b/sunrpc/svc_raw.c
index ff8fa7ccd9..37a027d412 100644
--- a/sunrpc/svc_raw.c
+++ b/sunrpc/svc_raw.c
@@ -66,7 +66,7 @@ static bool_t svcraw_reply (SVCXPRT *, struct rpc_msg *);
 static bool_t svcraw_freeargs (SVCXPRT *, xdrproc_t, caddr_t);
 static void svcraw_destroy (SVCXPRT *);
 
-static const struct xp_ops server_ops =
+static struct xp_ops server_ops =
 {
   svcraw_recv,
   svcraw_stat,
@@ -89,7 +89,7 @@ svcraw_create (void)
     }
   srp->server.xp_sock = 0;
   srp->server.xp_port = 0;
-  srp->server.xp_ops = (struct xp_ops *) &server_ops;
+  srp->server.xp_ops = &server_ops;
   srp->server.xp_verf.oa_base = srp->verf_body;
   INTUSE(xdrmem_create) (&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE,
 			 XDR_FREE);
diff --git a/sunrpc/svc_run.c b/sunrpc/svc_run.c
index d5e24dd0fc..017910b453 100644
--- a/sunrpc/svc_run.c
+++ b/sunrpc/svc_run.c
@@ -60,12 +60,6 @@ svc_run (void)
 	return;
 
       my_pollfd = malloc (sizeof (struct pollfd) * svc_max_pollfd);
-      if (my_pollfd == NULL)
-	{
-	  perror (_("svc_run: - out of memory"));
-	  return;
-	}
-
       for (i = 0; i < svc_max_pollfd; ++i)
 	{
 	  my_pollfd[i].fd = svc_pollfd[i].fd;
diff --git a/sunrpc/svc_simple.c b/sunrpc/svc_simple.c
index 6c1c9c914e..5ac21ffdbd 100644
--- a/sunrpc/svc_simple.c
+++ b/sunrpc/svc_simple.c
@@ -125,7 +125,12 @@ registerrpc (u_long prognum, u_long versnum, u_long procnum,
  err_out:
   if (buf == NULL)
     return -1;
-  (void) __fxprintf (NULL, "%s", buf);
+#ifdef USE_IN_LIBIO
+  if (_IO_fwide (stderr, 0) > 0)
+    (void) __fwprintf (stderr, L"%s", buf);
+  else
+#endif
+    (void) fputs (buf, stderr);
   free (buf);
   return -1;
 }
@@ -184,7 +189,12 @@ universal (struct svc_req *rqstp, SVCXPRT *transp_l)
  err_out2:
   if (buf == NULL)
     exit (1);
-  __fxprintf (NULL, "%s", buf);
+#ifdef USE_IN_LIBIO
+  if (_IO_fwide (stderr, 0) > 0)
+    __fwprintf (stderr, L"%s", buf);
+  else
+#endif
+    fputs (buf, stderr);
   free (buf);
   exit (1);
 }
diff --git a/sunrpc/svc_tcp.c b/sunrpc/svc_tcp.c
index 539a2b8d98..4decfa4fd0 100644
--- a/sunrpc/svc_tcp.c
+++ b/sunrpc/svc_tcp.c
@@ -165,7 +165,7 @@ svctcp_create (int sock, u_int sendsize, u_int recvsize)
       (void) __bind (sock, (struct sockaddr *) &addr, len);
     }
   if ((__getsockname (sock, (struct sockaddr *) &addr, &len) != 0) ||
-      (__listen (sock, SOMAXCONN) != 0))
+      (__listen (sock, 2) != 0))
     {
       perror (_("svc_tcp.c - cannot getsockname or listen"));
       if (madesock)
@@ -176,7 +176,12 @@ svctcp_create (int sock, u_int sendsize, u_int recvsize)
   xprt = (SVCXPRT *) mem_alloc (sizeof (SVCXPRT));
   if (r == NULL || xprt == NULL)
     {
-      (void) __fxprintf (NULL, "%s", _("svctcp_create: out of memory\n"));
+#ifdef USE_IN_LIBIO
+      if (_IO_fwide (stderr, 0) > 0)
+	(void) __fwprintf (stderr, L"%s", _("svctcp_create: out of memory\n"));
+      else
+#endif
+	(void) fputs (_("svctcp_create: out of memory\n"), stderr);
       mem_free (r, sizeof (*r));
       mem_free (xprt, sizeof (SVCXPRT));
       return NULL;
@@ -214,8 +219,13 @@ makefd_xprt (int fd, u_int sendsize, u_int recvsize)
   cd = (struct tcp_conn *) mem_alloc (sizeof (struct tcp_conn));
   if (xprt == (SVCXPRT *) NULL || cd == NULL)
     {
-      (void) __fxprintf (NULL, "%s",
-			 _("svc_tcp: makefd_xprt: out of memory\n"));
+#ifdef USE_IN_LIBIO
+      if (_IO_fwide (stderr, 0) > 0)
+	(void) __fwprintf (stderr, L"%s",
+			   _("svc_tcp: makefd_xprt: out of memory\n"));
+      else
+#endif
+	(void) fputs (_("svc_tcp: makefd_xprt: out of memory\n"), stderr);
       mem_free (xprt, sizeof (SVCXPRT));
       mem_free (cd, sizeof (struct tcp_conn));
       return NULL;
diff --git a/sunrpc/svc_udp.c b/sunrpc/svc_udp.c
index dfeb6de70f..45f99440b2 100644
--- a/sunrpc/svc_udp.c
+++ b/sunrpc/svc_udp.c
@@ -149,7 +149,12 @@ svcudp_bufcreate (sock, sendsz, recvsz)
   buf = mem_alloc (((MAX (sendsz, recvsz) + 3) / 4) * 4);
   if (xprt == NULL || su == NULL || buf == NULL)
     {
-      (void) __fxprintf (NULL, "%s", _("svcudp_create: out of memory\n"));
+#ifdef USE_IN_LIBIO
+      if (_IO_fwide (stderr, 0) > 0)
+	(void) __fwprintf (stderr, L"%s", _("svcudp_create: out of memory\n"));
+      else
+#endif
+	(void) fputs (_("svcudp_create: out of memory\n"), stderr);
       mem_free (xprt, sizeof (SVCXPRT));
       mem_free (su, sizeof (*su));
       mem_free (buf, ((MAX (sendsz, recvsz) + 3) / 4) * 4);
@@ -171,8 +176,14 @@ svcudp_bufcreate (sock, sendsz, recvsz)
        + sizeof(struct cmsghdr) + sizeof (struct in_pktinfo))
       > sizeof (xprt->xp_pad))
     {
-      (void) __fxprintf (NULL,"%s", _("\
-svcudp_create: xp_pad is too small for IP_PKTINFO\n"));
+# ifdef USE_IN_LIBIO
+      if (_IO_fwide (stderr, 0) > 0)
+	(void) __fwprintf (stderr, L"%s",
+			   _("svcudp_create: xp_pad is too small for IP_PKTINFO\n"));
+      else
+# endif
+	(void) fputs (_("svcudp_create: xp_pad is too small for IP_PKTINFO\n"),
+		      stderr);
       return NULL;
     }
   pad = 1;
@@ -400,14 +411,22 @@ svcudp_destroy (xprt)
 
 #define SPARSENESS 4		/* 75% sparse */
 
-#define CACHE_PERROR(msg)	\
-	(void) __fxprintf(NULL, "%s\n", msg)
+#ifdef USE_IN_LIBIO
+# define CACHE_PERROR(msg)	\
+	if (_IO_fwide (stderr, 0) > 0)					      \
+		(void) __fwprintf(stderr, L"%s\n", msg);		      \
+	else								      \
+		(void) fprintf(stderr, "%s\n", msg)
+#else
+# define CACHE_PERROR(msg)	\
+	(void) fprintf(stderr,"%s\n", msg)
+#endif
 
 #define ALLOC(type, size)	\
 	(type *) mem_alloc((unsigned) (sizeof(type) * (size)))
 
-#define CALLOC(type, size)	\
-  (type *) calloc (sizeof (type), size)
+#define BZERO(addr, type, size)	 \
+	__bzero((char *) addr, sizeof(type) * (int) (size))
 
 /*
  * An entry in the cache
@@ -482,21 +501,20 @@ svcudp_enablecache (SVCXPRT *transp, u_long size)
     }
   uc->uc_size = size;
   uc->uc_nextvictim = 0;
-  uc->uc_entries = CALLOC (cache_ptr, size * SPARSENESS);
+  uc->uc_entries = ALLOC (cache_ptr, size * SPARSENESS);
   if (uc->uc_entries == NULL)
     {
-      mem_free (uc, sizeof (struct udp_cache));
       CACHE_PERROR (_("enablecache: could not allocate cache data"));
       return 0;
     }
-  uc->uc_fifo = CALLOC (cache_ptr, size);
+  BZERO (uc->uc_entries, cache_ptr, size * SPARSENESS);
+  uc->uc_fifo = ALLOC (cache_ptr, size);
   if (uc->uc_fifo == NULL)
     {
-      mem_free (uc->uc_entries, size * SPARSENESS);
-      mem_free (uc, sizeof (struct udp_cache));
       CACHE_PERROR (_("enablecache: could not allocate cache fifo"));
       return 0;
     }
+  BZERO (uc->uc_fifo, cache_ptr, size);
   su->su_cache = (char *) uc;
   return 1;
 }
@@ -546,7 +564,6 @@ cache_set (SVCXPRT *xprt, u_long replylen)
       newbuf = mem_alloc (su->su_iosz);
       if (newbuf == NULL)
 	{
-	  mem_free (victim, sizeof (struct cache_node));
 	  CACHE_PERROR (_("cache_set: could not allocate new rpc_buffer"));
 	  return;
 	}
diff --git a/sunrpc/svc_unix.c b/sunrpc/svc_unix.c
index 1b7b1fbd4f..cfbc63866b 100644
--- a/sunrpc/svc_unix.c
+++ b/sunrpc/svc_unix.c
@@ -161,7 +161,7 @@ svcunix_create (int sock, u_int sendsize, u_int recvsize, char *path)
   __bind (sock, (struct sockaddr *) &addr, len);
 
   if (__getsockname (sock, (struct sockaddr *) &addr, &len) != 0
-      || __listen (sock, SOMAXCONN) != 0)
+      || __listen (sock, 2) != 0)
     {
       perror (_("svc_unix.c - cannot getsockname or listen"));
       if (madesock)
@@ -173,7 +173,12 @@ svcunix_create (int sock, u_int sendsize, u_int recvsize, char *path)
   xprt = (SVCXPRT *) mem_alloc (sizeof (SVCXPRT));
   if (r == NULL || xprt == NULL)
     {
-      __fxprintf (NULL, "%s", _("svcunix_create: out of memory\n"));
+#ifdef USE_IN_LIBIO
+      if (_IO_fwide (stderr, 0) > 0)
+	__fwprintf (stderr, L"%s", _("svcunix_create: out of memory\n"));
+      else
+#endif
+	fputs (_("svcunix_create: out of memory\n"), stderr);
       mem_free (r, sizeof (*r));
       mem_free (xprt, sizeof (SVCXPRT));
       return NULL;
@@ -211,8 +216,13 @@ makefd_xprt (int fd, u_int sendsize, u_int recvsize)
   cd = (struct unix_conn *) mem_alloc (sizeof (struct unix_conn));
   if (xprt == (SVCXPRT *) NULL || cd == (struct unix_conn *) NULL)
     {
-      (void) __fxprintf (NULL, "%s",
-			 _("svc_unix: makefd_xprt: out of memory\n"));
+#ifdef USE_IN_LIBIO
+      if (_IO_fwide (stderr, 0) > 0)
+	(void) __fwprintf (stderr, L"%s",
+			   _("svc_unix: makefd_xprt: out of memory\n"));
+      else
+#endif
+	(void) fputs (_("svc_unix: makefd_xprt: out of memory\n"), stderr);
       mem_free (xprt, sizeof (SVCXPRT));
       mem_free (cd, sizeof (struct unix_conn));
       return NULL;
diff --git a/sunrpc/svcauth_des.c b/sunrpc/svcauth_des.c
index 933d001341..07d7bd0122 100644
--- a/sunrpc/svcauth_des.c
+++ b/sunrpc/svcauth_des.c
@@ -315,7 +315,7 @@ _svcauth_des (register struct svc_req *rqst, register struct rpc_msg *msg)
   /*
    * xdr the timestamp before encrypting
    */
-  ixdr = (uint32_t *) cryptbuf;
+  ixdr = (int32_t *) cryptbuf;
   IXDR_PUT_INT32 (ixdr, timestamp.tv_sec - 1);
   IXDR_PUT_INT32 (ixdr, timestamp.tv_usec);
 
@@ -396,9 +396,11 @@ cache_init (void)
   register int i;
 
   authdes_cache = (struct cache_entry *)
-    calloc (sizeof (struct cache_entry) * AUTHDES_CACHESZ, 1);
+    mem_alloc (sizeof (struct cache_entry) * AUTHDES_CACHESZ);
   if (authdes_cache == NULL)
     return;
+  __bzero ((char *) authdes_cache,
+	   sizeof (struct cache_entry) * AUTHDES_CACHESZ);
 
   authdes_lru = (int *) mem_alloc (sizeof (int) * AUTHDES_CACHESZ);
   /*
diff --git a/sunrpc/tst-xdrmem.c b/sunrpc/tst-xdrmem.c
deleted file mode 100644
index 0c9929c6ed..0000000000
--- a/sunrpc/tst-xdrmem.c
+++ /dev/null
@@ -1,205 +0,0 @@
-/* Copyright (C) 2005 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Jakub Jelinek <jakub@redhat.com>, 2005.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
-
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-#include <rpc/rpc.h>
-
-static int
-do_test (void)
-{
-  XDR xdrs;
-  unsigned char buf[8192];
-  int v_int;
-  u_int v_u_int;
-  long v_long;
-  u_long v_u_long;
-  quad_t v_hyper;
-  u_quad_t v_u_hyper;
-  quad_t v_longlong_t;
-  u_quad_t v_u_longlong_t;
-  short v_short;
-  u_short v_u_short;
-  char v_char;
-  u_char v_u_char;
-  bool_t v_bool;
-  enum_t v_enum;
-  char *v_wrapstring;
-
-  xdrmem_create (&xdrs, (char *) buf, sizeof (buf), XDR_ENCODE);
-
-#define TESTS \
-  T(int, 0)				\
-  T(int, CHAR_MAX)			\
-  T(int, CHAR_MIN)			\
-  T(int, SHRT_MAX)			\
-  T(int, SHRT_MIN)			\
-  T(int, INT_MAX)			\
-  T(int, INT_MIN)			\
-  T(int, 0x123)				\
-  T(u_int, 0)				\
-  T(u_int, UCHAR_MAX)			\
-  T(u_int, USHRT_MAX)			\
-  T(u_int, UINT_MAX)			\
-  T(u_int, 0xdeadbeef)			\
-  T(u_int, 0x12345678)			\
-  T(long, 0)				\
-  T(long, 2147483647L)			\
-  T(long, -2147483648L)			\
-  T(long, -305419896L)			\
-  T(long, -305419896L)			\
-  T(u_long, 0)				\
-  T(u_long, 0xffffffffUL)		\
-  T(u_long, 0xdeadbeefUL)		\
-  T(u_long, 0x12345678UL)		\
-  T(hyper, 0)				\
-  T(hyper, CHAR_MAX)			\
-  T(hyper, CHAR_MIN)			\
-  T(hyper, SHRT_MAX)			\
-  T(hyper, SHRT_MIN)			\
-  T(hyper, INT_MAX)			\
-  T(hyper, INT_MIN)			\
-  T(hyper, LONG_MAX)			\
-  T(hyper, LONG_MIN)			\
-  T(hyper, LONG_LONG_MAX)		\
-  T(hyper, LONG_LONG_MIN)		\
-  T(hyper, 0x12312345678LL)		\
-  T(hyper, 0x12387654321LL)		\
-  T(u_hyper, 0)				\
-  T(u_hyper, UCHAR_MAX)			\
-  T(u_hyper, USHRT_MAX)			\
-  T(u_hyper, UINT_MAX)			\
-  T(u_hyper, ULONG_MAX)			\
-  T(u_hyper, ULONG_LONG_MAX)		\
-  T(u_hyper, 0xdeadbeefdeadbeefULL)	\
-  T(u_hyper, 0x12312345678ULL)		\
-  T(u_hyper, 0x12387654321ULL)		\
-  T(longlong_t, 0)			\
-  T(longlong_t, CHAR_MAX)		\
-  T(longlong_t, CHAR_MIN)		\
-  T(longlong_t, SHRT_MAX)		\
-  T(longlong_t, SHRT_MIN)		\
-  T(longlong_t, INT_MAX)		\
-  T(longlong_t, INT_MIN)		\
-  T(longlong_t, LONG_MAX)		\
-  T(longlong_t, LONG_MIN)		\
-  T(longlong_t, LONG_LONG_MAX)		\
-  T(longlong_t, LONG_LONG_MIN)		\
-  T(longlong_t, 0x12312345678LL)	\
-  T(longlong_t, 0x12387654321LL)	\
-  T(u_longlong_t, 0)			\
-  T(u_longlong_t, UCHAR_MAX)		\
-  T(u_longlong_t, USHRT_MAX)		\
-  T(u_longlong_t, UINT_MAX)		\
-  T(u_longlong_t, ULONG_MAX)		\
-  T(u_longlong_t, ULONG_LONG_MAX)	\
-  T(u_longlong_t, 0xdeadbeefdeadbeefULL)\
-  T(u_longlong_t, 0x12312345678ULL)	\
-  T(u_longlong_t, 0x12387654321ULL)	\
-  T(short, CHAR_MAX)			\
-  T(short, CHAR_MIN)			\
-  T(short, SHRT_MAX)			\
-  T(short, SHRT_MIN)			\
-  T(short, 0x123)			\
-  T(u_short, 0)				\
-  T(u_short, UCHAR_MAX)			\
-  T(u_short, USHRT_MAX)			\
-  T(u_short, 0xbeef)			\
-  T(u_short, 0x5678)			\
-  T(char, CHAR_MAX)			\
-  T(char, CHAR_MIN)			\
-  T(char, 0x23)				\
-  T(u_char, 0)				\
-  T(u_char, UCHAR_MAX)			\
-  T(u_char, 0xef)			\
-  T(u_char, 0x78)			\
-  T(bool, 0)				\
-  T(bool, 1)				\
-  T(enum, 0)				\
-  T(enum, CHAR_MAX)			\
-  T(enum, CHAR_MIN)			\
-  T(enum, SHRT_MAX)			\
-  T(enum, SHRT_MIN)			\
-  T(enum, INT_MAX)			\
-  T(enum, INT_MIN)			\
-  T(enum, 0x123)			\
-  S(wrapstring, (char *) "")		\
-  S(wrapstring, (char *) "hello, world")
-
-#define T(type, val) \
-  v_##type = val;			\
-  if (! xdr_##type (&xdrs, &v_##type))	\
-    {					\
-      puts ("encoding of " #type	\
-	    " " #val " failed");	\
-      return 1;				\
-    }
-#define S(type, val) T(type, val)
-
-  TESTS
-#undef T
-#undef S
-
-  xdr_destroy (&xdrs);
-
-  xdrmem_create (&xdrs, (char *) buf, sizeof (buf), XDR_DECODE);
-
-#define T(type, val) \
-  v_##type = 0x15;			\
-  if (! xdr_##type (&xdrs, &v_##type))	\
-    {					\
-      puts ("decoding of " #type	\
-	    " " #val " failed");	\
-      return 1;				\
-    }					\
-  if (v_##type != val)			\
-    {					\
-      puts ("decoded value differs, "	\
-	    "type " #type " " #val);	\
-      return 1;				\
-    }
-#define S(type, val) \
-  v_##type = NULL;			\
-  if (! xdr_##type (&xdrs, &v_##type))	\
-    {					\
-      puts ("decoding of " #type	\
-	    " " #val " failed");	\
-      return 1;				\
-    }					\
-  if (strcmp (v_##type, val))		\
-    {					\
-      puts ("decoded value differs, "	\
-	    "type " #type " " #val);	\
-      return 1;				\
-    }					\
-  free (v_##type);			\
-  v_##type = NULL;
-
-  TESTS
-#undef T
-#undef S
-
-  xdr_destroy (&xdrs);
-
-  return 0;
-}
-
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
diff --git a/sunrpc/tst-xdrmem2.c b/sunrpc/tst-xdrmem2.c
deleted file mode 100644
index eed8ccc072..0000000000
--- a/sunrpc/tst-xdrmem2.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/* Copyright (C) 2006 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
-
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-#include <rpc/rpc.h>
-#include <sys/mman.h>
-#include <unistd.h>
-
-static int
-do_test (void)
-{
-  XDR xdrs;
-  void *buf;
-  size_t ps = sysconf (_SC_PAGESIZE);
-  uintptr_t half = -1;
-  int v_int;
-  u_short v_u_short;
-
-  half = (half >> 1) & ~(uintptr_t) (ps - 1);
-  buf = mmap ((void *) half, 2 * ps, PROT_READ | PROT_WRITE,
-	      MAP_PRIVATE | MAP_ANON, -1, 0);
-  if (buf == MAP_FAILED || buf != (void *) half)
-    {
-      puts ("Couldn't mmap 2 pages in the middle of address space");
-      return 0;
-    }
-
-  xdrmem_create (&xdrs, (char *) buf, 2 * ps, XDR_ENCODE);
-
-#define T(type, val) \
-  v_##type = val;			\
-  if (! xdr_##type (&xdrs, &v_##type))	\
-    {					\
-      puts ("encoding of " #type	\
-	    " " #val " failed");	\
-      return 1;				\
-    }
-
-  T(int, 127)
-
-  u_int pos = xdr_getpos (&xdrs);
-
-  T(u_short, 31)
-
-  if (! xdr_setpos (&xdrs, pos))
-    {
-      puts ("xdr_setpos during encoding failed");
-      return 1;
-    }
-
-  T(u_short, 36)
-
-#undef T
-
-  xdr_destroy (&xdrs);
-
-  xdrmem_create (&xdrs, (char *) buf, 2 * ps, XDR_DECODE);
-
-#define T(type, val) \
-  v_##type = 0x15;			\
-  if (! xdr_##type (&xdrs, &v_##type))	\
-    {					\
-      puts ("decoding of " #type	\
-	    " " #val " failed");	\
-      return 1;				\
-    }					\
-  if (v_##type != val)			\
-    {					\
-      puts ("decoded value differs, "	\
-	    "type " #type " " #val);	\
-      return 1;				\
-    }
-
-  T(int, 127)
-
-  pos = xdr_getpos (&xdrs);
-
-  T(u_short, 36)
-
-  if (! xdr_setpos (&xdrs, pos))
-    {
-      puts ("xdr_setpos during encoding failed");
-      return 1;
-    }
-
-  T(u_short, 36)
-
-#undef T
-
-  xdr_destroy (&xdrs);
-
-  return 0;
-}
-
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
diff --git a/sunrpc/xdr.c b/sunrpc/xdr.c
index 21e339b4ee..d99a9985c4 100644
--- a/sunrpc/xdr.c
+++ b/sunrpc/xdr.c
@@ -131,7 +131,7 @@ bool_t
 xdr_u_int (XDR *xdrs, u_int *up)
 {
 #if UINT_MAX < ULONG_MAX
-  long l;
+  u_long l;
 
   switch (xdrs->x_op)
     {
@@ -144,7 +144,7 @@ xdr_u_int (XDR *xdrs, u_int *up)
 	{
 	  return FALSE;
 	}
-      *up = (u_int) (u_long) l;
+      *up = (u_int) l;
     case XDR_FREE:
       return TRUE;
     }
@@ -225,7 +225,8 @@ INTDEF(xdr_u_long)
 bool_t
 xdr_hyper (XDR *xdrs, quad_t *llp)
 {
-  long int t1, t2;
+  long t1;
+  unsigned long int t2;
 
   if (xdrs->x_op == XDR_ENCODE)
     {
@@ -239,7 +240,7 @@ xdr_hyper (XDR *xdrs, quad_t *llp)
       if (!XDR_GETLONG(xdrs, &t1) || !XDR_GETLONG(xdrs, &t2))
 	return FALSE;
       *llp = ((quad_t) t1) << 32;
-      *llp |= (uint32_t) t2;
+      *llp |= t2;
       return TRUE;
     }
 
@@ -258,7 +259,8 @@ INTDEF(xdr_hyper)
 bool_t
 xdr_u_hyper (XDR *xdrs, u_quad_t *ullp)
 {
-  long int t1, t2;
+  unsigned long t1;
+  unsigned long t2;
 
   if (xdrs->x_op == XDR_ENCODE)
     {
@@ -272,7 +274,7 @@ xdr_u_hyper (XDR *xdrs, u_quad_t *ullp)
       if (!XDR_GETLONG(xdrs, &t1) || !XDR_GETLONG(xdrs, &t2))
 	return FALSE;
       *ullp = ((u_quad_t) t1) << 32;
-      *ullp |= (uint32_t) t2;
+      *ullp |= t2;
       return TRUE;
     }
 
@@ -330,7 +332,7 @@ INTDEF(xdr_short)
 bool_t
 xdr_u_short (XDR *xdrs, u_short *usp)
 {
-  long l;
+  u_long l;
 
   switch (xdrs->x_op)
     {
@@ -343,7 +345,7 @@ xdr_u_short (XDR *xdrs, u_short *usp)
 	{
 	  return FALSE;
 	}
-      *usp = (u_short) (u_long) l;
+      *usp = (u_short) l;
       return TRUE;
 
     case XDR_FREE:
@@ -563,7 +565,12 @@ xdr_bytes (xdrs, cpp, sizep, maxsize)
 	}
       if (sp == NULL)
 	{
-	  (void) __fxprintf (NULL, "%s", _("xdr_bytes: out of memory\n"));
+#ifdef USE_IN_LIBIO
+	  if (_IO_fwide (stderr, 0) > 0)
+	    (void) __fwprintf (stderr, L"%s", _("xdr_bytes: out of memory\n"));
+	  else
+#endif
+	    (void) fputs (_("xdr_bytes: out of memory\n"), stderr);
 	  return FALSE;
 	}
       /* fall into ... */
@@ -715,7 +722,13 @@ xdr_string (xdrs, cpp, maxsize)
 	*cpp = sp = (char *) mem_alloc (nodesize);
       if (sp == NULL)
 	{
-	  (void) __fxprintf (NULL, "%s", _("xdr_string: out of memory\n"));
+#ifdef USE_IN_LIBIO
+	  if (_IO_fwide (stderr, 0) > 0)
+	    (void) __fwprintf (stderr, L"%s",
+			       _("xdr_string: out of memory\n"));
+	  else
+#endif
+	    (void) fputs (_("xdr_string: out of memory\n"), stderr);
 	  return FALSE;
 	}
       sp[size] = 0;
diff --git a/sunrpc/xdr_array.c b/sunrpc/xdr_array.c
index 44abdbcfda..9f67e7fe62 100644
--- a/sunrpc/xdr_array.c
+++ b/sunrpc/xdr_array.c
@@ -74,6 +74,7 @@ xdr_array (xdrs, addrp, sizep, maxsize, elsize, elproc)
   caddr_t target = *addrp;
   u_int c;		/* the actual element count */
   bool_t stat = TRUE;
+  u_int nodesize;
 
   /* like strings, arrays are really counted arrays */
   if (!INTUSE(xdr_u_int) (xdrs, sizep))
@@ -89,6 +90,7 @@ xdr_array (xdrs, addrp, sizep, maxsize, elsize, elproc)
     {
       return FALSE;
     }
+  nodesize = c * elsize;
 
   /*
    * if we are deserializing, we may need to allocate an array.
@@ -100,12 +102,19 @@ xdr_array (xdrs, addrp, sizep, maxsize, elsize, elproc)
       case XDR_DECODE:
 	if (c == 0)
 	  return TRUE;
-	*addrp = target = calloc (c, elsize);
+	*addrp = target = mem_alloc (nodesize);
 	if (target == NULL)
 	  {
-	    (void) __fxprintf (NULL, "%s", _("xdr_array: out of memory\n"));
+#ifdef USE_IN_LIBIO
+	    if (_IO_fwide (stderr, 0) > 0)
+	      (void) __fwprintf (stderr, L"%s",
+				 _("xdr_array: out of memory\n"));
+	    else
+#endif
+	      (void) fputs (_("xdr_array: out of memory\n"), stderr);
 	    return FALSE;
 	  }
+	__bzero (target, nodesize);
 	break;
 
       case XDR_FREE:
@@ -128,7 +137,7 @@ xdr_array (xdrs, addrp, sizep, maxsize, elsize, elproc)
    */
   if (xdrs->x_op == XDR_FREE)
     {
-      mem_free (*addrp, c * elsize);
+      mem_free (*addrp, nodesize);
       *addrp = NULL;
     }
   return stat;
diff --git a/sunrpc/xdr_intXX_t.c b/sunrpc/xdr_intXX_t.c
index 6c1fca2b23..9d2f92e10d 100644
--- a/sunrpc/xdr_intXX_t.c
+++ b/sunrpc/xdr_intXX_t.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1998, 1999, 2000, 2004, 2005 Free Software Foundation, Inc.
+/* Copyright (c) 1998, 1999, 2000, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1998.
 
@@ -31,7 +31,10 @@
 bool_t
 xdr_int64_t (XDR *xdrs, int64_t *ip)
 {
-  int32_t t1, t2;
+  int32_t t1;
+  /* This must be unsigned, otherwise we get problems with sign
+     extension in the DECODE case.  */
+  uint32_t t2;
 
   switch (xdrs->x_op)
     {
@@ -43,7 +46,7 @@ xdr_int64_t (XDR *xdrs, int64_t *ip)
       if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, &t2))
         return FALSE;
       *ip = ((int64_t) t1) << 32;
-      *ip |= (uint32_t) t2;	/* Avoid sign extension.  */
+      *ip |= t2;
       return TRUE;
     case XDR_FREE:
       return TRUE;
diff --git a/sunrpc/xdr_mem.c b/sunrpc/xdr_mem.c
index 7b1261bbae..e3167de040 100644
--- a/sunrpc/xdr_mem.c
+++ b/sunrpc/xdr_mem.c
@@ -177,15 +177,13 @@ xdrmem_setpos (xdrs, pos)
 {
   caddr_t newaddr = xdrs->x_base + pos;
   caddr_t lastaddr = xdrs->x_private + xdrs->x_handy;
-  size_t handy = lastaddr - newaddr;
 
-  if (newaddr > lastaddr
-      || newaddr < xdrs->x_base
-      || handy != (u_int) handy)
+  if ((long) newaddr > (long) lastaddr
+      || (UINT_MAX < LONG_MAX
+	  && (long) UINT_MAX < (long) lastaddr - (long) newaddr))
     return FALSE;
-
   xdrs->x_private = newaddr;
-  xdrs->x_handy = (u_int) handy;
+  xdrs->x_handy = (long) lastaddr - (long) newaddr;
   return TRUE;
 }
 
diff --git a/sunrpc/xdr_rec.c b/sunrpc/xdr_rec.c
index e847e9b47c..5e59c88523 100644
--- a/sunrpc/xdr_rec.c
+++ b/sunrpc/xdr_rec.c
@@ -153,7 +153,12 @@ xdrrec_create (XDR *xdrs, u_int sendsize,
 
   if (rstrm == NULL || buf == NULL)
     {
-      (void) __fxprintf (NULL, "%s", _("xdrrec_create: out of memory\n"));
+#ifdef USE_IN_LIBIO
+      if (_IO_fwide (stderr, 0) > 0)
+	(void) __fwprintf (stderr, L"%s", _("xdrrec_create: out of memory\n"));
+      else
+#endif
+	(void) fputs (_("xdrrec_create: out of memory\n"), stderr);
       mem_free (rstrm, sizeof (RECSTREAM));
       mem_free (buf, sendsize + recvsize + BYTES_PER_XDR_UNIT);
       /*
@@ -176,7 +181,7 @@ xdrrec_create (XDR *xdrs, u_int sendsize,
   /*
    * now the rest ...
    */
-  /* We have to add the cast since the `struct xdr_ops' in `struct XDR'
+  /* We have to add the const since the `struct xdr_ops' in `struct XDR'
      is not `const'.  */
   xdrs->x_ops = (struct xdr_ops *) &xdrrec_ops;
   xdrs->x_private = (caddr_t) rstrm;
diff --git a/sunrpc/xdr_ref.c b/sunrpc/xdr_ref.c
index bc5f72d6a6..ab706d7f84 100644
--- a/sunrpc/xdr_ref.c
+++ b/sunrpc/xdr_ref.c
@@ -79,13 +79,19 @@ xdr_reference (xdrs, pp, size, proc)
 	return TRUE;
 
       case XDR_DECODE:
-	*pp = loc = (caddr_t) calloc (1, size);
+	*pp = loc = (caddr_t) mem_alloc (size);
 	if (loc == NULL)
 	  {
-	    (void) __fxprintf (NULL, "%s",
-			       _("xdr_reference: out of memory\n"));
+#ifdef USE_IN_LIBIO
+	    if (_IO_fwide (stderr, 0) > 0)
+	      (void) __fwprintf (stderr, L"%s",
+				 _("xdr_reference: out of memory\n"));
+	    else
+#endif
+	      (void) fputs (_("xdr_reference: out of memory\n"), stderr);
 	    return FALSE;
 	  }
+	__bzero (loc, (int) size);
 	break;
       default:
 	break;
diff --git a/sunrpc/xdr_stdio.c b/sunrpc/xdr_stdio.c
index e73c5a5202..4daa062c82 100644
--- a/sunrpc/xdr_stdio.c
+++ b/sunrpc/xdr_stdio.c
@@ -108,20 +108,20 @@ xdrstdio_destroy (XDR *xdrs)
 static bool_t
 xdrstdio_getlong (XDR *xdrs, long *lp)
 {
-  u_int32_t mycopy;
+  int32_t mycopy;
 
-  if (fread ((caddr_t) &mycopy, 4, 1, (FILE *) xdrs->x_private) != 1)
+  if (fread ((caddr_t) & mycopy, 4, 1, (FILE *) xdrs->x_private) != 1)
     return FALSE;
-  *lp = (long) ntohl (mycopy);
+  *lp = (int32_t) ntohl (mycopy);
   return TRUE;
 }
 
 static bool_t
 xdrstdio_putlong (XDR *xdrs, const long *lp)
 {
-  int32_t mycopy = htonl ((u_int32_t) *lp);
-
-  if (fwrite ((caddr_t) &mycopy, 4, 1, (FILE *) xdrs->x_private) != 1)
+  long mycopy = htonl (*lp);
+  lp = &mycopy;
+  if (fwrite ((caddr_t) lp, 4, 1, (FILE *) xdrs->x_private) != 1)
     return FALSE;
   return TRUE;
 }