]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
srvsvc: Add a central return point to init_srv_share_info_ctr()
authorVolker Lendecke <vl@samba.org>
Wed, 18 May 2022 13:39:23 +0000 (15:39 +0200)
committerJeremy Allison <jra@samba.org>
Wed, 18 May 2022 16:50:34 +0000 (16:50 +0000)
Soon there will be cleanup work to do.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=15062

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/rpc_server/srvsvc/srv_srvsvc_nt.c

index e863bdf3dabb2f92e5b377bd61bd257258c9118b..a0e4d125a83bdf71b31ff6141c97a82b3e534335 100644 (file)
@@ -622,6 +622,7 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
        bool *allowed = 0;
        union srvsvc_NetShareCtr ctr;
        uint32_t resume_handle = resume_handle_p ? *resume_handle_p : 0;
+       WERROR ret = WERR_OK;
 
        DEBUG(5,("init_srv_share_info_ctr\n"));
 
@@ -634,7 +635,9 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
        unbecome_root();
 
         allowed = talloc_zero_array(ctx, bool, num_services);
-        W_ERROR_HAVE_NO_MEMORY(allowed);
+       if (allowed == NULL) {
+               goto nomem;
+       }
 
         /* Count the number of entries. */
         for (snum = 0; snum < num_services; snum++) {
@@ -652,7 +655,7 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
         }
 
        if (!num_entries || (resume_handle >= num_entries)) {
-               return WERR_OK;
+               goto done;
        }
 
        /* Calculate alloc entries. */
@@ -660,11 +663,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
        switch (info_ctr->level) {
        case 0:
                ctr.ctr0 = talloc_zero(ctx, struct srvsvc_NetShareCtr0);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr0);
+               if (ctr.ctr0 == NULL) {
+                       goto nomem;
+               }
 
                ctr.ctr0->count = alloc_entries;
                ctr.ctr0->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo0, alloc_entries);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr0->array);
+               if (ctr.ctr0->array == NULL) {
+                       goto nomem;
+               }
 
                for (snum = 0; snum < num_services; snum++) {
                        if (allowed[snum] &&
@@ -677,11 +684,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
        case 1:
                ctr.ctr1 = talloc_zero(ctx, struct srvsvc_NetShareCtr1);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr1);
+               if (ctr.ctr1 == NULL) {
+                       goto nomem;
+               }
 
                ctr.ctr1->count = alloc_entries;
                ctr.ctr1->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo1, alloc_entries);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr1->array);
+               if (ctr.ctr1->array == NULL) {
+                       goto nomem;
+               }
 
                for (snum = 0; snum < num_services; snum++) {
                        if (allowed[snum] &&
@@ -694,11 +705,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
        case 2:
                ctr.ctr2 = talloc_zero(ctx, struct srvsvc_NetShareCtr2);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr2);
+               if (ctr.ctr2 == NULL) {
+                       goto nomem;
+               }
 
                ctr.ctr2->count = alloc_entries;
                ctr.ctr2->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo2, alloc_entries);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr2->array);
+               if (ctr.ctr2->array == NULL) {
+                       goto nomem;
+               }
 
                for (snum = 0; snum < num_services; snum++) {
                        if (allowed[snum] &&
@@ -712,11 +727,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
        case 501:
                ctr.ctr501 = talloc_zero(ctx, struct srvsvc_NetShareCtr501);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr501);
+               if (ctr.ctr501 == NULL) {
+                       goto nomem;
+               }
 
                ctr.ctr501->count = alloc_entries;
                ctr.ctr501->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo501, alloc_entries);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr501->array);
+               if (ctr.ctr501->array == NULL) {
+                       goto nomem;
+               }
 
                for (snum = 0; snum < num_services; snum++) {
                        if (allowed[snum] &&
@@ -729,11 +748,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
        case 502:
                ctr.ctr502 = talloc_zero(ctx, struct srvsvc_NetShareCtr502);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr502);
+               if (ctr.ctr502 == NULL) {
+                       goto nomem;
+               }
 
                ctr.ctr502->count = alloc_entries;
                ctr.ctr502->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo502, alloc_entries);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr502->array);
+               if (ctr.ctr502->array == NULL) {
+                       goto nomem;
+               }
 
                for (snum = 0; snum < num_services; snum++) {
                        if (allowed[snum] &&
@@ -746,11 +769,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
        case 1004:
                ctr.ctr1004 = talloc_zero(ctx, struct srvsvc_NetShareCtr1004);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr1004);
+               if (ctr.ctr1004 == NULL) {
+                       goto nomem;
+               }
 
                ctr.ctr1004->count = alloc_entries;
                ctr.ctr1004->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo1004, alloc_entries);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr1004->array);
+               if (ctr.ctr1004->array == NULL) {
+                       goto nomem;
+               }
 
                for (snum = 0; snum < num_services; snum++) {
                        if (allowed[snum] &&
@@ -763,11 +790,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
        case 1005:
                ctr.ctr1005 = talloc_zero(ctx, struct srvsvc_NetShareCtr1005);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr1005);
+               if (ctr.ctr1005 == NULL) {
+                       goto nomem;
+               }
 
                ctr.ctr1005->count = alloc_entries;
                ctr.ctr1005->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo1005, alloc_entries);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr1005->array);
+               if (ctr.ctr1005->array == NULL) {
+                       goto nomem;
+               }
 
                for (snum = 0; snum < num_services; snum++) {
                        if (allowed[snum] &&
@@ -780,11 +811,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
        case 1006:
                ctr.ctr1006 = talloc_zero(ctx, struct srvsvc_NetShareCtr1006);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr1006);
+               if (ctr.ctr1006 == NULL) {
+                       goto nomem;
+               }
 
                ctr.ctr1006->count = alloc_entries;
                ctr.ctr1006->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo1006, alloc_entries);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr1006->array);
+               if (ctr.ctr1006->array == NULL) {
+                       goto nomem;
+               }
 
                for (snum = 0; snum < num_services; snum++) {
                        if (allowed[snum] &&
@@ -797,11 +832,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
        case 1007:
                ctr.ctr1007 = talloc_zero(ctx, struct srvsvc_NetShareCtr1007);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr1007);
+               if (ctr.ctr1007 == NULL) {
+                       goto nomem;
+               }
 
                ctr.ctr1007->count = alloc_entries;
                ctr.ctr1007->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo1007, alloc_entries);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr1007->array);
+               if (ctr.ctr1007->array == NULL) {
+                       goto nomem;
+               }
 
                for (snum = 0; snum < num_services; snum++) {
                        if (allowed[snum] &&
@@ -814,11 +853,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
        case 1501:
                ctr.ctr1501 = talloc_zero(ctx, struct srvsvc_NetShareCtr1501);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr1501);
+               if (ctr.ctr1501 == NULL) {
+                       goto nomem;
+               }
 
                ctr.ctr1501->count = alloc_entries;
                ctr.ctr1501->array = talloc_zero_array(ctx, struct sec_desc_buf, alloc_entries);
-               W_ERROR_HAVE_NO_MEMORY(ctr.ctr1501->array);
+               if (ctr.ctr1501->array == NULL) {
+                       goto nomem;
+               }
 
                for (snum = 0; snum < num_services; snum++) {
                        if (allowed[snum] &&
@@ -834,7 +877,8 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
        default:
                DEBUG(5,("init_srv_share_info_ctr: unsupported switch value %d\n",
                        info_ctr->level));
-               return WERR_INVALID_LEVEL;
+               ret = WERR_INVALID_LEVEL;
+               goto done;
        }
 
        *total_entries = alloc_entries;
@@ -847,8 +891,12 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
        }
 
        info_ctr->ctr = ctr;
-
-       return WERR_OK;
+       ret = WERR_OK;
+       goto done;
+nomem:
+       ret = WERR_NOT_ENOUGH_MEMORY;
+done:
+       return ret;
 }
 
 /*******************************************************************