r5736: fix to avoid endless recursion in ndr_size_*() calculation
authorStefan Metzmacher <metze@samba.org>
Fri, 11 Mar 2005 10:09:16 +0000 (10:09 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:11:00 +0000 (13:11 -0500)
metze
(This used to be commit eaac0f214703f91f186eb54f97e15e56461762bd)

source4/librpc/ndr/libndr.h
source4/librpc/ndr/ndr.c

index e2ac4279f1d71a0d9720ab3c1d3c28ee3f74aef3..19d43566815c4f0a24f87763b268bfccb78777bd 100644 (file)
@@ -132,6 +132,9 @@ struct ndr_print {
 /* set if an object uuid will be present */
 #define LIBNDR_FLAG_OBJECT_PRESENT    (1<<30)
 
+/* set to avoid recursion in ndr_size_*() calculation */
+#define LIBNDR_FLAG_NO_NDR_SIZE                (1<<31)
+
 /* useful macro for debugging */
 #define NDR_PRINT_DEBUG(type, p) ndr_print_debug((ndr_print_fn_t)ndr_print_ ##type, #p, p)
 #define NDR_PRINT_UNION_DEBUG(type, level, p) ndr_print_union_debug((ndr_print_union_fn_t)ndr_print_ ##type, #p, level, p)
index 2e350aa0da7e72a880ecc17c2d63f40fa77d5c3f..f3394d1e442a7595a09a10ff109fac1911b81878 100644 (file)
@@ -789,9 +789,12 @@ size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push)
        NTSTATUS status;
        size_t ret;
 
+       /* avoid recursion */
+       if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
+
        ndr = ndr_push_init_ctx(NULL);
        if (!ndr) return 0;
-       ndr->flags |= flags;
+       ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
        status = push(ndr, NDR_SCALARS|NDR_BUFFERS, discard_const(p));
        if (!NT_STATUS_IS_OK(status)) {
                return 0;
@@ -810,9 +813,12 @@ size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_union_f
        NTSTATUS status;
        size_t ret;
 
+       /* avoid recursion */
+       if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
+
        ndr = ndr_push_init_ctx(NULL);
        if (!ndr) return 0;
-       ndr->flags |= flags;
+       ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
        status = push(ndr, NDR_SCALARS|NDR_BUFFERS, level, discard_const(p));
        if (!NT_STATUS_IS_OK(status)) {
                return 0;