s3-dcerpc: Rearrange api_pipe_bind_req() to do checks before allocating memory
authorSimo Sorce <idra@samba.org>
Sun, 11 Jul 2010 14:47:32 +0000 (10:47 -0400)
committerGünther Deschner <gd@samba.org>
Tue, 13 Jul 2010 12:44:11 +0000 (14:44 +0200)
Signed-off-by: Günther Deschner <gd@samba.org>
source3/rpc_server/srv_pipe.c

index dbaaea61b92b5f232a7fca400f3a4a8b42d2e113..16e1a540aa6288fa6da37796913bf707ee30bf29 100644 (file)
@@ -1530,32 +1530,6 @@ bool api_pipe_bind_req(pipes_struct *p, struct ncacn_packet *pkt)
                return setup_bind_nak(p, pkt);
        }
 
-       prs_init_empty(&p->out_data.frag, p->mem_ctx, MARSHALL);
-
-       /* 
-        * Marshall directly into the outgoing PDU space. We
-        * must do this as we need to set to the bind response
-        * header and are never sending more than one PDU here.
-        */
-
-       /*
-        * Setup the memory to marshall the ba header, and the
-        * auth footers.
-        */
-
-       if(!prs_init(&out_hdr_ba, 1024, p->mem_ctx, MARSHALL)) {
-               DEBUG(0,("api_pipe_bind_req: malloc out_hdr_ba failed.\n"));
-               prs_mem_free(&p->out_data.frag);
-               return False;
-       }
-
-       if(!prs_init(&out_auth, 1024, p->mem_ctx, MARSHALL)) {
-               DEBUG(0,("api_pipe_bind_req: malloc out_auth failed.\n"));
-               prs_mem_free(&p->out_data.frag);
-               prs_mem_free(&out_hdr_ba);
-               return False;
-       }
-
        if (pkt->u.bind.num_contexts == 0) {
                DEBUG(0, ("api_pipe_bind_req: no rpc contexts around\n"));
                goto err_exit;
@@ -1581,9 +1555,6 @@ bool api_pipe_bind_req(pipes_struct *p, struct ncacn_packet *pkt)
                                 get_pipe_name_from_syntax(
                                        talloc_tos(),
                                        &pkt->u.bind.ctx_list[0].abstract_syntax)));
-                       prs_mem_free(&p->out_data.frag);
-                       prs_mem_free(&out_hdr_ba);
-                       prs_mem_free(&out_auth);
 
                        return setup_bind_nak(p, pkt);
                }
@@ -1602,7 +1573,7 @@ bool api_pipe_bind_req(pipes_struct *p, struct ncacn_packet *pkt)
                                                            &p->syntax),
                                  get_pipe_name_from_syntax(talloc_tos(),
                                                            &p->syntax)));
-                       goto err_exit;
+                       return setup_bind_nak(p, pkt);
                }
        }
 
@@ -1618,6 +1589,32 @@ bool api_pipe_bind_req(pipes_struct *p, struct ncacn_packet *pkt)
                assoc_gid = 0x53f0;
        }
 
+       /*
+        * Marshall directly into the outgoing PDU space. We
+        * must do this as we need to set to the bind response
+        * header and are never sending more than one PDU here.
+        */
+
+       prs_init_empty(&p->out_data.frag, p->mem_ctx, MARSHALL);
+
+       /*
+        * Setup the memory to marshall the ba header, and the
+        * auth footers.
+        */
+
+       if(!prs_init(&out_hdr_ba, 1024, p->mem_ctx, MARSHALL)) {
+               DEBUG(0,("api_pipe_bind_req: malloc out_hdr_ba failed.\n"));
+               prs_mem_free(&p->out_data.frag);
+               return False;
+       }
+
+       if(!prs_init(&out_auth, 1024, p->mem_ctx, MARSHALL)) {
+               DEBUG(0,("api_pipe_bind_req: malloc out_auth failed.\n"));
+               prs_mem_free(&p->out_data.frag);
+               prs_mem_free(&out_hdr_ba);
+               return False;
+       }
+
 
        /*
         * Create the bind response struct.