summaryrefslogtreecommitdiff
path: root/libc/inet/rpc/xdr_mem.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2006-01-23 23:22:10 +0000
committerMike Frysinger <vapier@gentoo.org>2006-01-23 23:22:10 +0000
commitcc479c5abf86e0014cf6bc3492bbf53a47f503fc (patch)
treef6d242ea42993b010612c28cfcbc5228cee94549 /libc/inet/rpc/xdr_mem.c
parenta1d98e054e1d2a3481f897fb40f98972a57c74d9 (diff)
sync with glibc
Diffstat (limited to 'libc/inet/rpc/xdr_mem.c')
-rw-r--r--libc/inet/rpc/xdr_mem.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/libc/inet/rpc/xdr_mem.c b/libc/inet/rpc/xdr_mem.c
index 191672ec4..7613ffc2f 100644
--- a/libc/inet/rpc/xdr_mem.c
+++ b/libc/inet/rpc/xdr_mem.c
@@ -38,11 +38,9 @@
*
*/
-#define __FORCE_GLIBC
#include <features.h>
-
-
#include <string.h>
+#include <limits.h>
#include <rpc/rpc.h>
libc_hidden_proto(memcpy)
@@ -53,7 +51,7 @@ 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 *);
@@ -107,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;
@@ -122,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;
@@ -138,8 +138,9 @@ 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;
+ xdrs->x_handy -= len;
memcpy (addr, xdrs->x_private, len);
xdrs->x_private += len;
return TRUE;
@@ -152,8 +153,9 @@ 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;
+ xdrs->x_handy -= len;
memcpy (xdrs->x_private, addr, len);
xdrs->x_private += len;
return TRUE;
@@ -180,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;
@@ -191,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;
@@ -212,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;
@@ -227,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;