summaryrefslogtreecommitdiffstats
path: root/libc/inet/rpc/xdr_mem.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/inet/rpc/xdr_mem.c')
-rw-r--r--libc/inet/rpc/xdr_mem.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/libc/inet/rpc/xdr_mem.c b/libc/inet/rpc/xdr_mem.c
index 4b6a4817e..7613ffc2f 100644
--- a/libc/inet/rpc/xdr_mem.c
+++ b/libc/inet/rpc/xdr_mem.c
@@ -38,21 +38,20 @@
*
*/
-#define __FORCE_GLIBC
-#define _GNU_SOURCE
#include <features.h>
-
-
#include <string.h>
+#include <limits.h>
#include <rpc/rpc.h>
+libc_hidden_proto(memcpy)
+
static bool_t xdrmem_getlong (XDR *, long *);
static bool_t xdrmem_putlong (XDR *, const long *);
static bool_t xdrmem_getbytes (XDR *, caddr_t, u_int);
static bool_t xdrmem_putbytes (XDR *, const char *, u_int);
static u_int xdrmem_getpos (const XDR *);
static bool_t xdrmem_setpos (XDR *, u_int);
-static int32_t *xdrmem_inline (XDR *, int);
+static int32_t *xdrmem_inline (XDR *, u_int);
static void xdrmem_destroy (XDR *);
static bool_t xdrmem_getint32 (XDR *, int32_t *);
static bool_t xdrmem_putint32 (XDR *, const int32_t *);
@@ -75,8 +74,9 @@ static const struct xdr_ops xdrmem_ops =
* The procedure xdrmem_create initializes a stream descriptor for a
* memory buffer.
*/
-void attribute_hidden
-__xdrmem_create (XDR *xdrs, const caddr_t addr, u_int size, enum xdr_op op)
+libc_hidden_proto(xdrmem_create)
+void
+xdrmem_create (XDR *xdrs, const caddr_t addr, u_int size, enum xdr_op op)
{
xdrs->x_op = op;
/* We have to add the const since the `struct xdr_ops' in `struct XDR'
@@ -85,7 +85,7 @@ __xdrmem_create (XDR *xdrs, const caddr_t addr, u_int size, enum xdr_op op)
xdrs->x_private = xdrs->x_base = addr;
xdrs->x_handy = size;
}
-strong_alias(__xdrmem_create,xdrmem_create)
+libc_hidden_def(xdrmem_create)
/*
* Nothing needs to be done for the memory case. The argument is clearly
@@ -105,8 +105,9 @@ xdrmem_destroy (XDR *xdrs attribute_unused)
static bool_t
xdrmem_getlong (XDR *xdrs, long *lp)
{
- if ((xdrs->x_handy -= 4) < 0)
+ if (xdrs->x_handy < 4)
return FALSE;
+ xdrs->x_handy -= 4;
*lp = (int32_t) ntohl ((*((int32_t *) (xdrs->x_private))));
xdrs->x_private += 4;
return TRUE;
@@ -120,8 +121,9 @@ xdrmem_getlong (XDR *xdrs, long *lp)
static bool_t
xdrmem_putlong (XDR *xdrs, const long *lp)
{
- if ((xdrs->x_handy -= 4) < 0)
+ if (xdrs->x_handy < 4)
return FALSE;
+ xdrs->x_handy -= 4;
*(int32_t *) xdrs->x_private = htonl (*lp);
xdrs->x_private += 4;
return TRUE;
@@ -136,9 +138,10 @@ xdrmem_putlong (XDR *xdrs, const long *lp)
static bool_t
xdrmem_getbytes (XDR *xdrs, caddr_t addr, u_int len)
{
- if ((xdrs->x_handy -= len) < 0)
+ if (xdrs->x_handy < len)
return FALSE;
- __memcpy (addr, xdrs->x_private, len);
+ xdrs->x_handy -= len;
+ memcpy (addr, xdrs->x_private, len);
xdrs->x_private += len;
return TRUE;
}
@@ -150,9 +153,10 @@ xdrmem_getbytes (XDR *xdrs, caddr_t addr, u_int len)
static bool_t
xdrmem_putbytes (XDR *xdrs, const char *addr, u_int len)
{
- if ((xdrs->x_handy -= len) < 0)
+ if (xdrs->x_handy < len)
return FALSE;
- __memcpy (xdrs->x_private, addr, len);
+ xdrs->x_handy -= len;
+ memcpy (xdrs->x_private, addr, len);
xdrs->x_private += len;
return TRUE;
}
@@ -178,7 +182,9 @@ xdrmem_setpos (xdrs, pos)
caddr_t newaddr = xdrs->x_base + pos;
caddr_t lastaddr = xdrs->x_private + xdrs->x_handy;
- if ((long) newaddr > (long) lastaddr)
+ 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 = (long) lastaddr - (long) newaddr;
@@ -189,7 +195,7 @@ xdrmem_setpos (xdrs, pos)
* xdrs modified
*/
static int32_t *
-xdrmem_inline (XDR *xdrs, int len)
+xdrmem_inline (XDR *xdrs, u_int len)
{
int32_t *buf = 0;
@@ -210,8 +216,9 @@ xdrmem_inline (XDR *xdrs, int len)
static bool_t
xdrmem_getint32 (XDR *xdrs, int32_t *ip)
{
- if ((xdrs->x_handy -= 4) < 0)
+ if (xdrs->x_handy < 4)
return FALSE;
+ xdrs->x_handy -= 4;
*ip = ntohl ((*((int32_t *) (xdrs->x_private))));
xdrs->x_private += 4;
return TRUE;
@@ -225,8 +232,9 @@ xdrmem_getint32 (XDR *xdrs, int32_t *ip)
static bool_t
xdrmem_putint32 (XDR *xdrs, const int32_t *ip)
{
- if ((xdrs->x_handy -= 4) < 0)
+ if (xdrs->x_handy < 4)
return FALSE;
+ xdrs->x_handy -= 4;
*(int32_t *) xdrs->x_private = htonl (*ip);
xdrs->x_private += 4;
return TRUE;