Skip to contentSkip to conversation

libtirpc: Use a non-variadic xdrproc_t on Apple platforms

PATCH New Frida Flodin 1 participant 1 message Nov 30

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtirpc: Use a non-variadic xdrproc_t on Apple platforms

xdrproc_t is declared as bool_t (*)(XDR *, ...), but the xdr routines called through it are ordinary non-variadic functions. That does not work on Apple arm64, where variadic arguments are passed on the stack while the xdr routines read their second argument from a register. Every RPC reply goes through such a call in xdr_union(), so an RPC server built on libtirpc cannot send any reply there.

Apple's own rpc/xdr.h in the macOS SDK says about this prototype:

This prototype is incorrect. One may not use a varargs function pointer in place of pointer to a function with positional parameters.

All calls through xdrproc_t in libtirpc pass exactly two arguments, so use a two-argument prototype on Apple platforms. Other platforms are unchanged. The hand-written variadic prototype of svcauth_none_wrap() has to follow.

resultproc_t has the same problem, but its callers pass different numbers of arguments, so it is left alone here.

---
 src/svc_auth_none.c | 2 +-
 tirpc/rpc/xdr.h     | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
src/svc_auth_none.c +1 -1
index 5ca98e9..db67dff 100644
@@ -38,7 +38,7 @@
 #include <rpc/rpc.h>
 
 static bool_t	svcauth_none_destroy(SVCAUTH *);
-static bool_t   svcauth_none_wrap(SVCAUTH *, XDR *, bool_t (*)(XDR *, ...), char *);
+static bool_t   svcauth_none_wrap(SVCAUTH *, XDR *, xdrproc_t, char *);
 
 struct svc_auth_ops svc_auth_none_ops = {
 	svcauth_none_wrap,
tirpc/rpc/xdr.h +3 -0
index 80b35ce..8c8e738 100644
@@ -136,6 +136,9 @@ typedef struct __rpc_xdr {
  */
 #ifdef _KERNEL
 typedef	bool_t (*xdrproc_t)(XDR *, void *, u_int);
+#elif defined(__APPLE__)
+/* See the note on xdrproc_t in Apple's rpc/xdr.h */
+typedef	bool_t (*xdrproc_t)(XDR *, void *);
 #else
 /*
  * XXX can't actually prototype it, because some take three args!!!
Signature · 1 line
2.56.0