From 65ebff40bad065cba7ef5daf1c3c241e91d349af Mon Sep 17 00:00:00 2001 From: zrj Date: Tue, 30 Jan 2018 09:02:49 +0200 Subject: [PATCH] rpc: Fix xdr_* macros and limit buffer sizes. While there, constify few things. Taken-from: FreeBSD --- include/rpc/rpcent.h | 2 +- include/rpc/xdr.h | 16 ++++++---------- lib/libc/rpc/clnt_simple.c | 21 +++++++++++---------- lib/libc/rpc/getrpcent.3 | 5 ++--- lib/libc/rpc/getrpcent.c | 2 +- lib/libc/rpc/rpc_callmsg.c | 9 ++++----- lib/libc/rpc/rpc_prot.c | 13 ++++++------- lib/libc/rpc/rpcb_prot.c | 31 ++++++++++++++++--------------- lib/libc/rpc/rpcb_st_xdr.c | 31 ++++++++++++++++--------------- usr.sbin/rpcbind/rpcb_svc_com.c | 10 ++++++---- 10 files changed, 69 insertions(+), 71 deletions(-) diff --git a/include/rpc/rpcent.h b/include/rpc/rpcent.h index 9967b41d4b..ef48e04221 100644 --- a/include/rpc/rpcent.h +++ b/include/rpc/rpcent.h @@ -55,7 +55,7 @@ __BEGIN_DECLS * These interfaces are currently implemented through nsswitch and are * MT-safe. */ -extern struct rpcent *getrpcbyname(char *); +extern struct rpcent *getrpcbyname(const char *); extern struct rpcent *getrpcbynumber(int); extern struct rpcent *getrpcent(void); extern void setrpcent(int); diff --git a/include/rpc/xdr.h b/include/rpc/xdr.h index 2f8af6e22a..5a2eeeba93 100644 --- a/include/rpc/xdr.h +++ b/include/rpc/xdr.h @@ -218,15 +218,11 @@ xdr_putint32(XDR *xdrs, int32_t *ip) (*(xdrs)->x_ops->x_control)(xdrs, req, op) #define xdr_control(xdrs, req, op) XDR_CONTROL(xdrs, req, op) -/* - * Solaris strips the '_t' from these types -- not sure why. - * But, let's be compatible. - */ -#define xdr_rpcvers(xdrs, versp) xdr_u_int32(xdrs, versp) -#define xdr_rpcprog(xdrs, progp) xdr_u_int32(xdrs, progp) -#define xdr_rpcproc(xdrs, procp) xdr_u_int32(xdrs, procp) -#define xdr_rpcprot(xdrs, protp) xdr_u_int32(xdrs, protp) -#define xdr_rpcport(xdrs, portp) xdr_u_int32(xdrs, portp) +#define xdr_rpcvers(xdrs, versp) xdr_u_int32_t(xdrs, versp) +#define xdr_rpcprog(xdrs, progp) xdr_u_int32_t(xdrs, progp) +#define xdr_rpcproc(xdrs, procp) xdr_u_int32_t(xdrs, procp) +#define xdr_rpcprot(xdrs, protp) xdr_u_int32_t(xdrs, protp) +#define xdr_rpcport(xdrs, portp) xdr_u_int32_t(xdrs, portp) /* * Support struct for discriminated unions. @@ -319,7 +315,7 @@ extern bool_t xdr_hyper(XDR *, quad_t *); extern bool_t xdr_u_hyper(XDR *, u_quad_t *); extern bool_t xdr_longlong_t(XDR *, quad_t *); extern bool_t xdr_u_longlong_t(XDR *, u_quad_t *); -extern unsigned long xdr_sizeof(xdrproc_t, void *); +extern unsigned long xdr_sizeof(xdrproc_t, void *); __END_DECLS /* diff --git a/lib/libc/rpc/clnt_simple.c b/lib/libc/rpc/clnt_simple.c index f4896dd76e..bb388f1bc9 100644 --- a/lib/libc/rpc/clnt_simple.c +++ b/lib/libc/rpc/clnt_simple.c @@ -29,7 +29,6 @@ * @(#)clnt_simple.c 2.2 88/08/01 4.0 RPCSRC * $NetBSD: clnt_simple.c,v 1.21 2000/07/06 03:10:34 christos Exp $ * $FreeBSD: src/lib/libc/rpc/clnt_simple.c,v 1.20 2006/02/27 22:10:59 deischen Exp $ - * $DragonFly: src/lib/libc/rpc/clnt_simple.c,v 1.5 2005/11/13 12:27:04 swildner Exp $ */ /* * Copyright (c) 1986-1991 by Sun Microsystems Inc. @@ -93,17 +92,19 @@ rpc_call_destroy(void *vp) * the future calls to same prog, vers, host and nettype combination. * * The total time available is 25 seconds. + * + * host - host name + * prognum - program number + * versnum - version number + * procnum - procedure number + * inproc, outproc - in/out XDR procedures + * in, out - recv/send data + * nettype - nettype */ enum clnt_stat -rpc_call(const char *host, /* host name */ - rpcprog_t prognum, /* program number */ - rpcvers_t versnum, /* version number */ - rpcproc_t procnum, /* procedure number */ - xdrproc_t inproc, - const char *in, - xdrproc_t outproc, /* in/out XDR procedures */ - char *out, /* recv/send data */ - const char *nettype) /* nettype */ +rpc_call(const char *host, const rpcprog_t prognum, const rpcvers_t versnum, + const rpcproc_t procnum, const xdrproc_t inproc, const char *in, + const xdrproc_t outproc, char *out, const char *nettype) { struct rpc_call_private *rcp = NULL; enum clnt_stat clnt_stat; diff --git a/lib/libc/rpc/getrpcent.3 b/lib/libc/rpc/getrpcent.3 index 35107861c2..ff8630b3a3 100644 --- a/lib/libc/rpc/getrpcent.3 +++ b/lib/libc/rpc/getrpcent.3 @@ -1,9 +1,8 @@ .\" @(#)getrpcent.3n 2.2 88/08/02 4.0 RPCSRC; from 1.11 88/03/14 SMI .\" $NetBSD: getrpcent.3,v 1.6 1998/02/05 18:49:06 perry Exp $ .\" $FreeBSD: src/lib/libc/rpc/getrpcent.3,v 1.18 2005/01/20 09:17:04 ru Exp $ -.\" $DragonFly: src/lib/libc/rpc/getrpcent.3,v 1.4 2007/08/18 20:48:47 swildner Exp $ .\" -.Dd December 14, 1987 +.Dd February 2, 2018 .Dt GETRPCENT 3 .Os .Sh NAME @@ -20,7 +19,7 @@ .Ft struct rpcent * .Fn getrpcent void .Ft struct rpcent * -.Fn getrpcbyname "char *name" +.Fn getrpcbyname "const char *name" .Ft struct rpcent * .Fn getrpcbynumber "int number" .Ft void diff --git a/lib/libc/rpc/getrpcent.c b/lib/libc/rpc/getrpcent.c index c258abaac1..26ae879781 100644 --- a/lib/libc/rpc/getrpcent.c +++ b/lib/libc/rpc/getrpcent.c @@ -965,7 +965,7 @@ getrpc(int (*fn)(union key, struct rpcent *, char *, size_t, struct rpcent **), } struct rpcent * -getrpcbyname(char *name) +getrpcbyname(const char *name) { union key key; diff --git a/lib/libc/rpc/rpc_callmsg.c b/lib/libc/rpc/rpc_callmsg.c index 89d6e9785a..0e9f4536ef 100644 --- a/lib/libc/rpc/rpc_callmsg.c +++ b/lib/libc/rpc/rpc_callmsg.c @@ -29,7 +29,6 @@ * @(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC * $NetBSD: rpc_callmsg.c,v 1.16 2000/07/14 08:40:42 fvdl Exp $ * $FreeBSD: src/lib/libc/rpc/rpc_callmsg.c,v 1.13 2007/11/20 01:51:20 jb Exp $ - * $DragonFly: src/lib/libc/rpc/rpc_callmsg.c,v 1.4 2005/11/13 12:27:04 swildner Exp $ */ /* @@ -190,11 +189,11 @@ xdr_callmsg(XDR *xdrs, struct rpc_msg *cmsg) xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) && xdr_enum(xdrs, (enum_t *) prm_direction) && (cmsg->rm_direction == CALL) && - xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) && + xdr_rpcvers(xdrs, &(cmsg->rm_call.cb_rpcvers)) && (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) && - xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) && - xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) && - xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) && + xdr_rpcprog(xdrs, &(cmsg->rm_call.cb_prog)) && + xdr_rpcvers(xdrs, &(cmsg->rm_call.cb_vers)) && + xdr_rpcproc(xdrs, &(cmsg->rm_call.cb_proc)) && xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) ) return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf))); return (FALSE); diff --git a/lib/libc/rpc/rpc_prot.c b/lib/libc/rpc/rpc_prot.c index 8904385fbe..be9ef5e610 100644 --- a/lib/libc/rpc/rpc_prot.c +++ b/lib/libc/rpc/rpc_prot.c @@ -29,7 +29,6 @@ * @(#)rpc_prot.c 2.3 88/08/07 4.0 RPCSRC * $NetBSD: rpc_prot.c,v 1.16 2000/06/02 23:11:13 fvdl Exp $ * $FreeBSD: src/lib/libc/rpc/rpc_prot.c,v 1.13 2007/11/20 01:51:20 jb Exp $ - * $DragonFly: src/lib/libc/rpc/rpc_prot.c,v 1.4 2005/11/13 12:27:04 swildner Exp $ */ /* @@ -116,9 +115,9 @@ xdr_accepted_reply(XDR *xdrs, struct accepted_reply *ar) return ((*(ar->ar_results.proc))(xdrs, ar->ar_results.where)); case PROG_MISMATCH: - if (! xdr_u_int32_t(xdrs, &(ar->ar_vers.low))) + if (!xdr_rpcvers(xdrs, &(ar->ar_vers.low))) return (FALSE); - return (xdr_u_int32_t(xdrs, &(ar->ar_vers.high))); + return (xdr_rpcvers(xdrs, &(ar->ar_vers.high))); case GARBAGE_ARGS: case SYSTEM_ERR: @@ -149,9 +148,9 @@ xdr_rejected_reply(XDR *xdrs, struct rejected_reply *rr) switch (rr->rj_stat) { case RPC_MISMATCH: - if (! xdr_u_int32_t(xdrs, &(rr->rj_vers.low))) + if (! xdr_rpcvers(xdrs, &(rr->rj_vers.low))) return (FALSE); - return (xdr_u_int32_t(xdrs, &(rr->rj_vers.high))); + return (xdr_rpcvers(xdrs, &(rr->rj_vers.high))); case AUTH_ERROR: prj_why = &rr->rj_why; @@ -214,8 +213,8 @@ xdr_callhdr(XDR *xdrs, struct rpc_msg *cmsg) (xdrs->x_op == XDR_ENCODE) && xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) && xdr_enum(xdrs, (enum_t *) prm_direction) && - xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) && - xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) ) + xdr_rpcvers(xdrs, &(cmsg->rm_call.cb_rpcvers)) && + xdr_rpcprog(xdrs, &(cmsg->rm_call.cb_prog)) ) return (xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers))); return (FALSE); } diff --git a/lib/libc/rpc/rpcb_prot.c b/lib/libc/rpc/rpcb_prot.c index 11769d500f..0e92ebda69 100644 --- a/lib/libc/rpc/rpcb_prot.c +++ b/lib/libc/rpc/rpcb_prot.c @@ -45,24 +45,25 @@ #include #include #include +#include #include "un-namespace.h" bool_t xdr_rpcb(XDR *xdrs, RPCB *objp) { - if (!xdr_u_int32_t(xdrs, &objp->r_prog)) { + if (!xdr_rpcprog(xdrs, &objp->r_prog)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->r_vers)) { + if (!xdr_rpcvers(xdrs, &objp->r_vers)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->r_netid, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->r_netid, RPC_MAXDATASIZE)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->r_addr, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->r_addr, RPC_MAXDATASIZE)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->r_owner, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->r_owner, RPC_MAXDATASIZE)) { return (FALSE); } return (TRUE); @@ -156,19 +157,19 @@ xdr_rpcblist(XDR *xdrs, RPCBLIST **rp) bool_t xdr_rpcb_entry(XDR *xdrs, rpcb_entry *objp) { - if (!xdr_string(xdrs, &objp->r_maddr, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->r_maddr, RPC_MAXDATASIZE)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->r_nc_netid, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->r_nc_netid, RPC_MAXDATASIZE)) { return (FALSE); } if (!xdr_u_int32_t(xdrs, &objp->r_nc_semantics)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->r_nc_protofmly, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->r_nc_protofmly, RPC_MAXDATASIZE)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->r_nc_proto, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->r_nc_proto, RPC_MAXDATASIZE)) { return (FALSE); } return (TRUE); @@ -201,14 +202,14 @@ xdr_rpcb_entry_list_ptr(XDR *xdrs, rpcb_entry_list_ptr *rp) * the case of freeing we must remember the next object * before we free the current object ... */ - if (freeing) + if (freeing && *rp) next = (*rp)->rpcb_entry_next; if (! xdr_reference(xdrs, (caddr_t *)rp, (u_int)sizeof (rpcb_entry_list), (xdrproc_t)xdr_rpcb_entry)) { return (FALSE); } - if (freeing && *rp) { + if (freeing) { next_copy = next; rp = &next_copy; /* @@ -237,13 +238,13 @@ xdr_rpcb_rmtcallargs(XDR *xdrs, struct rpcb_rmtcallargs *p) buf = XDR_INLINE(xdrs, 3 * BYTES_PER_XDR_UNIT); if (buf == NULL) { - if (!xdr_u_int32_t(xdrs, &objp->prog)) { + if (!xdr_rpcprog(xdrs, &objp->prog)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->vers)) { + if (!xdr_rpcvers(xdrs, &objp->vers)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->proc)) { + if (!xdr_rpcproc(xdrs, &objp->proc)) { return (FALSE); } } else { @@ -283,7 +284,7 @@ xdr_rpcb_rmtcallres(XDR *xdrs, struct rpcb_rmtcallres *p) bool_t dummy; struct r_rpcb_rmtcallres *objp = (struct r_rpcb_rmtcallres *)(void *)p; - if (!xdr_string(xdrs, &objp->addr, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->addr, RPC_MAXDATASIZE)) { return (FALSE); } if (!xdr_u_int(xdrs, &objp->results.results_len)) { diff --git a/lib/libc/rpc/rpcb_st_xdr.c b/lib/libc/rpc/rpcb_st_xdr.c index 92d01a91cd..9058c44769 100644 --- a/lib/libc/rpc/rpcb_st_xdr.c +++ b/lib/libc/rpc/rpcb_st_xdr.c @@ -40,6 +40,7 @@ #include "namespace.h" #include +#include #include "un-namespace.h" /* Link list of all the stats about getport and getaddr */ @@ -49,10 +50,10 @@ xdr_rpcbs_addrlist(XDR *xdrs, rpcbs_addrlist *objp) { struct rpcbs_addrlist **pnext; - if (!xdr_u_int32_t(xdrs, &objp->prog)) { + if (!xdr_rpcprog(xdrs, &objp->prog)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->vers)) { + if (!xdr_rpcvers(xdrs, &objp->vers)) { return (FALSE); } if (!xdr_int(xdrs, &objp->success)) { @@ -61,7 +62,7 @@ xdr_rpcbs_addrlist(XDR *xdrs, rpcbs_addrlist *objp) if (!xdr_int(xdrs, &objp->failure)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) { return (FALSE); } @@ -86,13 +87,13 @@ xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp) if (xdrs->x_op == XDR_ENCODE) { buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT); if (buf == NULL) { - if (!xdr_u_int32_t(xdrs, &objp->prog)) { + if (!xdr_rpcvers(xdrs, &objp->prog)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->vers)) { + if (!xdr_rpcvers(xdrs, &objp->vers)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->proc)) { + if (!xdr_rpcproc(xdrs, &objp->proc)) { return (FALSE); } if (!xdr_int(xdrs, &objp->success)) { @@ -112,7 +113,7 @@ xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp) IXDR_PUT_INT32(buf, objp->failure); IXDR_PUT_INT32(buf, objp->indirect); } - if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) { return (FALSE); } if (!xdr_pointer(xdrs, (char **)&objp->next, @@ -124,13 +125,13 @@ xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp) } else if (xdrs->x_op == XDR_DECODE) { buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT); if (buf == NULL) { - if (!xdr_u_int32_t(xdrs, &objp->prog)) { + if (!xdr_rpcprog(xdrs, &objp->prog)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->vers)) { + if (!xdr_rpcvers(xdrs, &objp->vers)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->proc)) { + if (!xdr_rpcproc(xdrs, &objp->proc)) { return (FALSE); } if (!xdr_int(xdrs, &objp->success)) { @@ -150,7 +151,7 @@ xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp) objp->failure = (int)IXDR_GET_INT32(buf); objp->indirect = (int)IXDR_GET_INT32(buf); } - if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) { return (FALSE); } if (!xdr_pointer(xdrs, (char **)&objp->next, @@ -160,13 +161,13 @@ xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp) } return (TRUE); } - if (!xdr_u_int32_t(xdrs, &objp->prog)) { + if (!xdr_rpcprog(xdrs, &objp->prog)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->vers)) { + if (!xdr_rpcvers(xdrs, &objp->vers)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->proc)) { + if (!xdr_rpcproc(xdrs, &objp->proc)) { return (FALSE); } if (!xdr_int(xdrs, &objp->success)) { @@ -178,7 +179,7 @@ xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp) if (!xdr_int(xdrs, &objp->indirect)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) { return (FALSE); } if (!xdr_pointer(xdrs, (char **)&objp->next, diff --git a/usr.sbin/rpcbind/rpcb_svc_com.c b/usr.sbin/rpcbind/rpcb_svc_com.c index 353a900ffb..d12c20bb90 100644 --- a/usr.sbin/rpcbind/rpcb_svc_com.c +++ b/usr.sbin/rpcbind/rpcb_svc_com.c @@ -54,6 +54,7 @@ #include #ifdef PORTMAP #include +#include #include #endif /* PORTMAP */ #include @@ -419,7 +420,8 @@ rpcbproc_taddr2uaddr_com(void *arg, struct svc_req *rqstp __unused, static bool_t xdr_encap_parms(XDR *xdrs, struct encap_parms *epp) { - return (xdr_bytes(xdrs, &(epp->args), (u_int *) &(epp->arglen), ~0)); + return (xdr_bytes(xdrs, &(epp->args), (u_int *) &(epp->arglen), + RPC_MAXDATASIZE)); } /* @@ -430,9 +432,9 @@ static bool_t xdr_rmtcall_args(XDR *xdrs, struct r_rmtcall_args *cap) { /* does not get the address or the arguments */ - if (xdr_u_int32_t(xdrs, &(cap->rmt_prog)) && - xdr_u_int32_t(xdrs, &(cap->rmt_vers)) && - xdr_u_int32_t(xdrs, &(cap->rmt_proc))) { + if (xdr_rpcprog(xdrs, &(cap->rmt_prog)) && + xdr_rpcvers(xdrs, &(cap->rmt_vers)) && + xdr_rpcproc(xdrs, &(cap->rmt_proc))) { return (xdr_encap_parms(xdrs, &(cap->rmt_args))); } return (FALSE); -- 2.11.4.GIT