]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - package/rpcbind/0005-rpcbproc_callit_com-Stop-freeing-a-static-pointer.patch
rpcbind: Backport fixes to memory leak security fix
[coffee/buildroot.git] / package / rpcbind / 0005-rpcbproc_callit_com-Stop-freeing-a-static-pointer.patch
1 From 4e201b75928ff7d4894cd30ab0f5f67b9cd95f5c Mon Sep 17 00:00:00 2001
2 From: Steve Dickson <steved@redhat.com>
3 Date: Thu, 18 Jan 2018 17:33:56 +0000
4 Subject: [PATCH] rpcbproc_callit_com: Stop freeing a static pointer
5
6 commit 7ea36ee introduced a svc_freeargs() call
7 that ended up freeing static pointer.
8
9 It turns out the allocations for the rmt_args
10 is not necessary . The xdr routines (xdr_bytes) will
11 handle the memory management and the largest
12 possible message size is UDPMSGSIZE (due to UDP only)
13 which is smaller than RPC_BUF_MAX
14
15 Signed-off-by: Steve Dickson <steved@redhat.com>
16 (cherry picked from commit 7c7590ad536c0e24bef790cb1e65702fc54db566)
17 Signed-off-by: Ed Blake <ed.blake@sondrel.com>
18 ---
19  src/rpcb_svc_com.c | 39 ++++++---------------------------------
20  1 file changed, 6 insertions(+), 33 deletions(-)
21
22 diff --git a/src/rpcb_svc_com.c b/src/rpcb_svc_com.c
23 index 0432b6f..64f1104 100644
24 --- a/src/rpcb_svc_com.c
25 +++ b/src/rpcb_svc_com.c
26 @@ -616,9 +616,9 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
27         struct netconfig *nconf;
28         struct netbuf *caller;
29         struct r_rmtcall_args a;
30 -       char *buf_alloc = NULL, *outbufp;
31 +       char *outbufp;
32         char *outbuf_alloc = NULL;
33 -       char buf[RPC_BUF_MAX], outbuf[RPC_BUF_MAX];
34 +       char  outbuf[RPC_BUF_MAX];
35         struct netbuf *na = (struct netbuf *) NULL;
36         struct rpc_msg call_msg;
37         int outlen;
38 @@ -639,36 +639,10 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
39         }
40         if (si.si_socktype != SOCK_DGRAM)
41                 return; /* Only datagram type accepted */
42 -       sendsz = __rpc_get_t_size(si.si_af, si.si_proto, UDPMSGSIZE);
43 -       if (sendsz == 0) {      /* data transfer not supported */
44 -               if (reply_type == RPCBPROC_INDIRECT)
45 -                       svcerr_systemerr(transp);
46 -               return;
47 -       }
48 -       /*
49 -        * Should be multiple of 4 for XDR.
50 -        */
51 -       sendsz = ((sendsz + 3) / 4) * 4;
52 -       if (sendsz > RPC_BUF_MAX) {
53 -#ifdef notyet
54 -               buf_alloc = alloca(sendsz);             /* not in IDR2? */
55 -#else
56 -               buf_alloc = malloc(sendsz);
57 -#endif /* notyet */
58 -               if (buf_alloc == NULL) {
59 -                       if (debugging)
60 -                               xlog(LOG_DEBUG,
61 -                                       "rpcbproc_callit_com:  No Memory!\n");
62 -                       if (reply_type == RPCBPROC_INDIRECT)
63 -                               svcerr_systemerr(transp);
64 -                       return;
65 -               }
66 -               a.rmt_args.args = buf_alloc;
67 -       } else {
68 -               a.rmt_args.args = buf;
69 -       }
70 +       sendsz = UDPMSGSIZE;
71  
72         call_msg.rm_xid = 0;    /* For error checking purposes */
73 +       memset(&a, 0, sizeof(a)); /* Zero out the input buffer */
74         if (!svc_getargs(transp, (xdrproc_t) xdr_rmtcall_args, (char *) &a)) {
75                 if (reply_type == RPCBPROC_INDIRECT)
76                         svcerr_decode(transp);
77 @@ -708,7 +682,8 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
78         if (rbl == (rpcblist_ptr)NULL) {
79  #ifdef RPCBIND_DEBUG
80                 if (debugging)
81 -                       xlog(LOG_DEBUG, "not found\n");
82 +                       xlog(LOG_DEBUG, "prog %lu vers %lu: not found\n", 
83 +                               a.rmt_prog, a.rmt_vers);
84  #endif
85                 if (reply_type == RPCBPROC_INDIRECT)
86                         svcerr_noprog(transp);
87 @@ -941,8 +916,6 @@ out:
88         }
89         if (local_uaddr)
90                 free(local_uaddr);
91 -       if (buf_alloc)
92 -               free(buf_alloc);
93         if (outbuf_alloc)
94                 free(outbuf_alloc);
95         if (na) {
96 -- 
97 2.11.0
98