librpc/rpc: apply some code cleanup and error checks to dcesrv_mgmt.c
authorStefan Metzmacher <metze@samba.org>
Wed, 9 Aug 2023 10:42:43 +0000 (12:42 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 17 Oct 2023 19:20:38 +0000 (19:20 +0000)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
librpc/rpc/dcesrv_mgmt.c

index d75f08b56e6108f8d9513ee32091fd17f0e6a756..5e52a4a1217b3b6e8ec06c680e7643160b9bf61c 100644 (file)
@@ -49,17 +49,27 @@ static WERROR dcesrv_mgmt_inq_if_ids(struct dcesrv_call_state *dce_call, TALLOC_
                       struct mgmt_inq_if_ids *r)
 {
        const struct dcesrv_endpoint *ep = dce_call->conn->endpoint;
-       struct dcesrv_if_list *l;
-       struct rpc_if_id_vector_t *vector;
+       struct dcesrv_if_list *l = NULL;
+       struct rpc_if_id_vector_t *vector = NULL;
+
+       vector = talloc(mem_ctx, struct rpc_if_id_vector_t);
+       if (vector == NULL) {
+               return WERR_NOT_ENOUGH_MEMORY;
+       }
 
-       vector = *r->out.if_id_vector = talloc(mem_ctx, struct rpc_if_id_vector_t);
        vector->count = 0;
        vector->if_id = NULL;
+
        for (l = ep->interface_list; l; l = l->next) {
                vector->count++;
-               vector->if_id = talloc_realloc(mem_ctx, vector->if_id, struct ndr_syntax_id_p, vector->count);
+               vector->if_id = talloc_realloc(vector, vector->if_id, struct ndr_syntax_id_p, vector->count);
+               if (vector->if_id == NULL) {
+                       return WERR_NOT_ENOUGH_MEMORY;
+               }
                vector->if_id[vector->count-1].id = &l->iface->syntax_id;
        }
+
+       *r->out.if_id_vector = vector;
        return WERR_OK;
 }
 
@@ -73,8 +83,13 @@ static WERROR dcesrv_mgmt_inq_stats(struct dcesrv_call_state *dce_call, TALLOC_C
        if (r->in.max_count != MGMT_STATS_ARRAY_MAX_SIZE)
                return WERR_NOT_SUPPORTED;
 
+       r->out.statistics->statistics = talloc_zero_array(mem_ctx,
+                                                         uint32_t,
+                                                         r->in.max_count);
+       if (r->out.statistics->statistics == NULL) {
+               return WERR_NOT_ENOUGH_MEMORY;
+       }
        r->out.statistics->count = r->in.max_count;
-       r->out.statistics->statistics = talloc_array(mem_ctx, uint32_t, r->in.max_count);
        /* FIXME */
        r->out.statistics->statistics[MGMT_STATS_CALLS_IN] = 0;
        r->out.statistics->statistics[MGMT_STATS_CALLS_OUT] = 0;