]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libndr: Simplify data flow in ndr_push_relative_ptr2
authorVolker Lendecke <vl@samba.org>
Mon, 30 Sep 2024 10:07:30 +0000 (12:07 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 12 Nov 2024 12:09:34 +0000 (12:09 +0000)
Consolidate saving/replacing ndr->offset right around the push_uint32

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
librpc/ndr/ndr.c

index e552ccba20f80463352046148d56c5ef6b8953a2..e96f50a3f2a9611e298014b118eee9203488536b 100644 (file)
@@ -1726,19 +1726,23 @@ static enum ndr_err_code ndr_push_relative_ptr2(struct ndr_push *ndr, const void
        if (p == NULL) {
                return NDR_ERR_SUCCESS;
        }
-       save_offset = ndr->offset;
+       if (ndr->offset < ndr->relative_base_offset) {
+               return ndr_push_error(
+                       ndr,
+                       NDR_ERR_BUFSIZE,
+                       "ndr_push_relative_ptr2 ndr->offset(%" PRIu32 ") "
+                       "< ndr->relative_base_offset(%" PRIu32 ")",
+                       ndr->offset,
+                       ndr->relative_base_offset);
+       }
        NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &ptr_offset));
        if (ptr_offset > ndr->offset) {
                return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
                                      "ndr_push_relative_ptr2 ptr_offset(%"PRIu32") > ndr->offset(%"PRIu32")",
                                      ptr_offset, ndr->offset);
        }
+       save_offset = ndr->offset;
        ndr->offset = ptr_offset;
-       if (save_offset < ndr->relative_base_offset) {
-               return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
-                                     "ndr_push_relative_ptr2 save_offset(%"PRIu32") < ndr->relative_base_offset(%"PRIu32")",
-                                     save_offset, ndr->relative_base_offset);
-       }
        NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, save_offset - ndr->relative_base_offset));
        ndr->offset = save_offset;
        return NDR_ERR_SUCCESS;