Skip to content

Commit e5cff48

Browse files
chuckleverJ. Bruce Fields
authored andcommitted
SUNRPC: Use unsigned string lengths in xdr_decode_string_inplace
XDR strings, opaques, and net objects should all use unsigned lengths. To wit, RFC 4506 says: 4.2. Unsigned Integer An XDR unsigned integer is a 32-bit datum that encodes a non-negative integer in the range [0,4294967295]. ... 4.11. String The standard defines a string of n (numbered 0 through n-1) ASCII bytes to be the number n encoded as an unsigned integer (as described above), and followed by the n bytes of the string. After this patch, xdr_decode_string_inplace now matches the other XDR string and array helpers that take a string length argument. See: xdr_encode_opaque_fixed, xdr_encode_opaque, xdr_encode_array Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Acked-By: NeilBrown <neilb@suse.de> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
1 parent 01b2969 commit e5cff48

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

‎include/linux/sunrpc/xdr.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ struct xdr_buf {
112112
__be32 *xdr_encode_opaque_fixed(__be32 *p, const void *ptr, unsigned int len);
113113
__be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int len);
114114
__be32 *xdr_encode_string(__be32 *p, const char *s);
115-
__be32 *xdr_decode_string_inplace(__be32 *p, char **sp, int *lenp, int maxlen);
115+
__be32 *xdr_decode_string_inplace(__be32 *p, char **sp, unsigned int *lenp,
116+
unsigned int maxlen);
116117
__be32 *xdr_encode_netobj(__be32 *p, const struct xdr_netobj *);
117118
__be32 *xdr_decode_netobj(__be32 *p, struct xdr_netobj *);
118119

‎net/sunrpc/xdr.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,13 @@ xdr_encode_string(__be32 *p, const char *string)
9696
EXPORT_SYMBOL(xdr_encode_string);
9797

9898
__be32 *
99-
xdr_decode_string_inplace(__be32 *p, char **sp, int *lenp, int maxlen)
99+
xdr_decode_string_inplace(__be32 *p, char **sp,
100+
unsigned int *lenp, unsigned int maxlen)
100101
{
101-
unsigned int len;
102+
u32 len;
102103

103-
if ((len = ntohl(*p++)) > maxlen)
104+
len = ntohl(*p++);
105+
if (len > maxlen)
104106
return NULL;
105107
*lenp = len;
106108
*sp = (char *) p;

0 commit comments

Comments
 (0)