]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
librpc/ndr: avoid alignment allocation in ndr_push_DATA_BLOB()
authorStefan Metzmacher <metze@samba.org>
Thu, 29 Aug 2024 11:26:04 +0000 (13:26 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 29 Aug 2024 18:25:28 +0000 (18:25 +0000)
Pair-Programmed-With: Volker Lendecke <vl@samba.org>

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
librpc/ndr/ndr_basic.c

index 5fd15730a74cee7f5156a78bdd8c6449896bb530..8b4b85b9c8191c9f1eb09b7c31ac7c62316371b9 100644 (file)
@@ -1404,18 +1404,23 @@ _PUBLIC_ void ndr_print_DATA_BLOB(struct ndr_print *ndr, const char *name, DATA_
  */
 _PUBLIC_ enum ndr_err_code ndr_push_DATA_BLOB(struct ndr_push *ndr, ndr_flags_type ndr_flags, DATA_BLOB blob)
 {
+       static const uint8_t padding[8] = { 0, };
+
        if (ndr->flags & LIBNDR_FLAG_REMAINING) {
                /* nothing to do */
        } else if (ndr->flags & (LIBNDR_ALIGN_FLAGS & ~LIBNDR_FLAG_NOALIGN)) {
+               blob.data = discard_const_p(uint8_t, padding);
                if (ndr->flags & LIBNDR_FLAG_ALIGN2) {
                        blob.length = NDR_ALIGN(ndr, 2);
                } else if (ndr->flags & LIBNDR_FLAG_ALIGN4) {
                        blob.length = NDR_ALIGN(ndr, 4);
                } else if (ndr->flags & LIBNDR_FLAG_ALIGN8) {
                        blob.length = NDR_ALIGN(ndr, 8);
+               } else {
+                       return ndr_push_error(ndr,
+                                             NDR_ERR_LENGTH,
+                                             "Invalid align flags");
                }
-               NDR_PUSH_ALLOC_SIZE(ndr, blob.data, blob.length);
-               data_blob_clear(&blob);
        } else {
                NDR_CHECK(ndr_push_uint3264(ndr, NDR_SCALARS, blob.length));
        }