xdr: Fix xdr_string

Forcing maxsize to RPC_MAXDATASIZE breaks code that deliberately uses
XDR with longer strings than permitted by SunRPC.

MFC after:	1 week
Fixes:		6448ec89e7 (" * limit size of buffers to RPC_MAXDATASIZE")
Fixes:		e17d7ab869 ("xdr_string: don't leak strings with xdr_free")
Sponsored by:	Klara, Inc.
Sponsored by:	NetApp, Inc.
Reviewed by:	kevans, brooks
Differential Revision:	https://reviews.freebsd.org/D59994
This commit is contained in:
Dag-Erling Smørgrav committed 2026-09-29 14:12:59 +02:00
1 parent 806adba81f
commit d2018cedb4
2 files changed
+4 -8

No files matched your search

+2 -4
View File
@@ -47,8 +47,6 @@
#include <stdlib.h>
#include <string.h>
#include <rpc/rpc.h>
#include <rpc/rpc_com.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include "un-namespace.h"
@@ -702,7 +700,7 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize)
* be invalid. Otherwise, if it's very small, we might
* fail to free the string.
*/
maxsize = RPC_MAXDATASIZE;
maxsize = ~0U;
/* FALLTHROUGH */
case XDR_ENCODE:
size = strlen(sp);
@@ -764,7 +762,7 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize)
bool_t
xdr_wrapstring(XDR *xdrs, char **cpp)
{
return xdr_string(xdrs, cpp, RPC_MAXDATASIZE);
return (xdr_string(xdrs, cpp, ~0U));
}
/*
+2 -4
View File
@@ -46,8 +46,6 @@
#include <sys/malloc.h>
#include <sys/module.h>
#include <rpc/rpc.h>
#include <rpc/rpc_com.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
@@ -626,7 +624,7 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize)
* be invalid. Otherwise, if it's very small, we might
* fail to free the string.
*/
maxsize = RPC_MAXDATASIZE;
maxsize = ~0U;
/* FALLTHROUGH */
case XDR_ENCODE:
size = strlen(sp);
@@ -687,7 +685,7 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize)
bool_t
xdr_wrapstring(XDR *xdrs, char **cpp)
{
return xdr_string(xdrs, cpp, RPC_MAXDATASIZE);
return (xdr_string(xdrs, cpp, ~0U));
}
/*