Ignore:
Timestamp:
Jun 9, 2016, 2:17:22 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: apply latest security patches to vendor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/librpc/ndr/ndr.c

    r917 r919  
    7878}
    7979
     80_PUBLIC_ enum ndr_err_code ndr_pull_append(struct ndr_pull *ndr, DATA_BLOB *blob)
     81{
     82        enum ndr_err_code ndr_err;
     83        DATA_BLOB b;
     84        uint32_t append = 0;
     85        bool ok;
     86
     87        if (blob->length == 0) {
     88                return NDR_ERR_SUCCESS;
     89        }
     90
     91        ndr_err = ndr_token_retrieve(&ndr->array_size_list, ndr, &append);
     92        if (ndr_err == NDR_ERR_TOKEN) {
     93                append = 0;
     94                ndr_err = NDR_ERR_SUCCESS;
     95        }
     96        NDR_CHECK(ndr_err);
     97
     98        if (ndr->data_size == 0) {
     99                ndr->data = NULL;
     100                append = UINT32_MAX;
     101        }
     102
     103        if (append == UINT32_MAX) {
     104                /*
     105                 * append == UINT32_MAX means that
     106                 * ndr->data is either NULL or a valid
     107                 * talloc child of ndr, which means
     108                 * we can use data_blob_append() without
     109                 * data_blob_talloc() of the existing callers data
     110                 */
     111                b = data_blob_const(ndr->data, ndr->data_size);
     112        } else {
     113                b = data_blob_talloc(ndr, ndr->data, ndr->data_size);
     114                if (b.data == NULL) {
     115                        return ndr_pull_error(ndr, NDR_ERR_ALLOC, "%s", __location__);
     116                }
     117        }
     118
     119        ok = data_blob_append(ndr, &b, blob->data, blob->length);
     120        if (!ok) {
     121                return ndr_pull_error(ndr, NDR_ERR_ALLOC, "%s", __location__);
     122        }
     123
     124        ndr->data = b.data;
     125        ndr->data_size = b.length;
     126
     127        return ndr_token_store(ndr, &ndr->array_size_list, ndr, UINT32_MAX);
     128}
     129
     130_PUBLIC_ enum ndr_err_code ndr_pull_pop(struct ndr_pull *ndr)
     131{
     132        uint32_t skip = 0;
     133        uint32_t append = 0;
     134
     135        if (ndr->relative_base_offset != 0) {
     136                return ndr_pull_error(ndr, NDR_ERR_RELATIVE,
     137                                      "%s", __location__);
     138        }
     139        if (ndr->relative_highest_offset != 0) {
     140                return ndr_pull_error(ndr, NDR_ERR_RELATIVE,
     141                                      "%s", __location__);
     142        }
     143        if (ndr->relative_list != NULL) {
     144                return ndr_pull_error(ndr, NDR_ERR_RELATIVE,
     145                                      "%s", __location__);
     146        }
     147        if (ndr->relative_base_list != NULL) {
     148                return ndr_pull_error(ndr, NDR_ERR_RELATIVE,
     149                                      "%s", __location__);
     150        }
     151
     152        /*
     153         * we need to keep up to 7 bytes
     154         * in order to get the aligment right.
     155         */
     156        skip = ndr->offset & 0xFFFFFFF8;
     157
     158        if (skip == 0) {
     159                return NDR_ERR_SUCCESS;
     160        }
     161
     162        ndr->offset -= skip;
     163        ndr->data_size -= skip;
     164
     165        append = ndr_token_peek(&ndr->array_size_list, ndr);
     166        if (append != UINT32_MAX) {
     167                /*
     168                 * here we assume, that ndr->data is not a
     169                 * talloc child of ndr.
     170                 */
     171                ndr->data += skip;
     172                return NDR_ERR_SUCCESS;
     173        }
     174
     175        memmove(ndr->data, ndr->data + skip, ndr->data_size);
     176
     177        ndr->data = talloc_realloc(ndr, ndr->data, uint8_t, ndr->data_size);
     178        if (ndr->data_size != 0 && ndr->data == NULL) {
     179                return ndr_pull_error(ndr, NDR_ERR_ALLOC, "%s", __location__);
     180        }
     181
     182        return NDR_ERR_SUCCESS;
     183}
     184
    80185/*
    81186  advance by 'size' bytes
     
    166271
    167272        return NDR_ERR_SUCCESS;
     273}
     274
     275_PUBLIC_ void ndr_print_debugc_helper(struct ndr_print *ndr, const char *format, ...)
     276{
     277        va_list ap;
     278        char *s = NULL;
     279        uint32_t i;
     280        int ret;
     281        int dbgc_class;
     282
     283        va_start(ap, format);
     284        ret = vasprintf(&s, format, ap);
     285        va_end(ap);
     286
     287        if (ret == -1) {
     288                return;
     289        }
     290
     291        dbgc_class = *(int *)ndr->private_data;
     292
     293        if (ndr->no_newline) {
     294                DEBUGADDC(dbgc_class, 1,("%s", s));
     295                free(s);
     296                return;
     297        }
     298
     299        for (i=0;i<ndr->depth;i++) {
     300                DEBUGADDC(dbgc_class, 1,("    "));
     301        }
     302
     303        DEBUGADDC(dbgc_class, 1,("%s\n", s));
     304        free(s);
    168305}
    169306
     
    236373                                                                  "\n");
    237374        }
     375}
     376
     377/*
     378  a useful helper function for printing idl structures via DEBUGC()
     379*/
     380_PUBLIC_ void ndr_print_debugc(int dbgc_class, ndr_print_fn_t fn, const char *name, void *ptr)
     381{
     382        struct ndr_print *ndr;
     383
     384        DEBUGC(dbgc_class, 1,(" "));
     385
     386        ndr = talloc_zero(NULL, struct ndr_print);
     387        if (!ndr) return;
     388        ndr->private_data = &dbgc_class;
     389        ndr->print = ndr_print_debugc_helper;
     390        ndr->depth = 1;
     391        ndr->flags = 0;
     392        fn(ndr, name, ptr);
     393        talloc_free(ndr);
    238394}
    239395
     
    403559        va_list ap;
    404560        int ret;
     561
     562        if (ndr->flags & LIBNDR_FLAG_INCOMPLETE_BUFFER) {
     563                switch (ndr_err) {
     564                case NDR_ERR_BUFSIZE:
     565                        return NDR_ERR_INCOMPLETE_BUFFER;
     566                default:
     567                        break;
     568                }
     569        }
    405570
    406571        va_start(ap, format);
     
    558723                break;
    559724        }
     725        case 0xFFFFFFFF:
     726                /*
     727                 * a shallow copy like subcontext
     728                 * useful for DCERPC pipe chunks.
     729                 */
     730                subndr = talloc_zero(ndr, struct ndr_pull);
     731                NDR_ERR_HAVE_NO_MEMORY(subndr);
     732
     733                subndr->flags           = ndr->flags;
     734                subndr->current_mem_ctx = ndr->current_mem_ctx;
     735                subndr->data            = ndr->data;
     736                subndr->offset          = ndr->offset;
     737                subndr->data_size       = ndr->data_size;
     738
     739                *_subndr = subndr;
     740                return NDR_ERR_SUCCESS;
     741
    560742        default:
    561743                return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) header_size %d",
     
    590772{
    591773        uint32_t advance;
    592         if (size_is >= 0) {
     774        uint32_t highest_ofs;
     775
     776        if (header_size == 0xFFFFFFFF) {
     777                advance = subndr->offset - ndr->offset;
     778        } else if (size_is >= 0) {
    593779                advance = size_is;
    594780        } else if (header_size > 0) {
     
    597783                advance = subndr->offset;
    598784        }
     785
     786        if (subndr->offset > ndr->relative_highest_offset) {
     787                highest_ofs = subndr->offset;
     788        } else {
     789                highest_ofs = subndr->relative_highest_offset;
     790        }
     791        if (!(subndr->flags & LIBNDR_FLAG_SUBCONTEXT_NO_UNREAD_BYTES)) {
     792                /*
     793                 * avoid an error unless SUBCONTEXT_NO_UNREAD_BYTES is specified
     794                 */
     795                highest_ofs = advance;
     796        }
     797        if (highest_ofs < advance) {
     798                return ndr_pull_error(subndr, NDR_ERR_UNREAD_BYTES,
     799                                      "not all bytes consumed ofs[%u] advance[%u]",
     800                                      highest_ofs, advance);
     801        }
     802
    599803        NDR_CHECK(ndr_pull_advance(ndr, advance));
    600804        return NDR_ERR_SUCCESS;
     
    14411645        { NDR_ERR_UNREAD_BYTES, "Unread Bytes" },
    14421646        { NDR_ERR_NDR64, "NDR64 assertion error" },
     1647        { NDR_ERR_INCOMPLETE_BUFFER, "Incomplete Buffer" },
    14431648        { 0, NULL }
    14441649};
Note: See TracChangeset for help on using the changeset viewer.