This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [PATCH] Fix xdr_long and xdr_u_long


On Wed, Jan 03, Jakub Jelinek wrote:

> Hi!
> 
> xdr_long and xdr_u_long silently discard upper bits on 64bit arches, they
> should fail instead.

I take a look at the changes Sun made to the latest Solaris versions.
Seems they changed it after Solaris 7 and you are right, xdr_long
should fail with to big values. I made a new patch with fixed comments
about the usage of the function.
I'm not sure, but shouldn't the developer get an warning at link time
if he use this functions ? 


2001-01-14  Thorsten Kukuk <kukuk@suse.de>

	* sunrpc/xdr.c (xdr_long, xdr_u_long): Fix comments about this
	functions

2001-01-03  Jakub Jelinek  <jakub@redhat.com>

	* sunrpc/xdr.c (xdr_long, xdr_u_long): Return FALSE if trying to
	encode value which does not fit in the 32bit type.

--- glibc-2.2/sunrpc/xdr.c	Fri Jul 14 13:50:22 2000
+++ glibc-rpc/sunrpc/xdr.c	Sun Jan 14 10:08:31 2001
@@ -153,13 +153,16 @@
 
 /*
  * XDR long integers
- * same as xdr_u_long - open coded to save a proc call!
+ * The definition of xdr_long() is kept for backward
+ * compatibility. Instead xdr_int() should be used.
  */
 bool_t
 xdr_long (XDR *xdrs, long *lp)
 {
 
-  if (xdrs->x_op == XDR_ENCODE)
+  if (xdrs->x_op == XDR_ENCODE
+      && (sizeof (int32_t) == sizeof (long)
+	  || (int32_t) *lp == *lp))
     return XDR_PUTLONG (xdrs, lp);
 
   if (xdrs->x_op == XDR_DECODE)
@@ -173,7 +176,8 @@
 
 /*
  * XDR unsigned long integers
- * same as xdr_long - open coded to save a proc call!
+ * The definition of xdr_u_long() is kept for backward
+ * compatibility. Instead xdr_u_int() should be used.
  */
 bool_t
 xdr_u_long (XDR *xdrs, u_long *ulp)
@@ -192,6 +196,10 @@
       }
 
     case XDR_ENCODE:
+      if (sizeof (uint32_t) != sizeof (u_long)
+	  && (uint32_t) *ulp != *ulp)
+	return FALSE;
+
       return XDR_PUTLONG (xdrs, (long *) ulp);
 
     case XDR_FREE:


-- 
Thorsten Kukuk       http://www.suse.de/~kukuk/       kukuk@suse.de
SuSE GmbH            Schanzaeckerstr. 10            90443 Nuernberg
Linux is like a Vorlon.  It is incredibly powerful, gives terse,
cryptic answers and has a lot of things going on in the background.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]