Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

Location:
vendor/current/libcli/ldap
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/libcli/ldap/ldap_message.c

    r740 r988  
    230230        case LDB_OP_AND:
    231231        case LDB_OP_OR:
    232                 asn1_push_tag(data, ASN1_CONTEXT(tree->operation==LDB_OP_AND?0:1));
     232                if (!asn1_push_tag(data, ASN1_CONTEXT(tree->operation==LDB_OP_AND?0:1))) return false;
    233233                for (i=0; i<tree->u.list.num_elements; i++) {
    234234                        if (!ldap_push_filter(data, tree->u.list.elements[i])) {
     
    236236                        }
    237237                }
    238                 asn1_pop_tag(data);
     238                if (!asn1_pop_tag(data)) return false;
    239239                break;
    240240
    241241        case LDB_OP_NOT:
    242                 asn1_push_tag(data, ASN1_CONTEXT(2));
     242                if (!asn1_push_tag(data, ASN1_CONTEXT(2))) return false;
    243243                if (!ldap_push_filter(data, tree->u.isnot.child)) {
    244244                        return false;
    245245                }
    246                 asn1_pop_tag(data);
     246                if (!asn1_pop_tag(data)) return false;
    247247                break;
    248248
    249249        case LDB_OP_EQUALITY:
    250250                /* equality test */
    251                 asn1_push_tag(data, ASN1_CONTEXT(3));
    252                 asn1_write_OctetString(data, tree->u.equality.attr,
    253                                       strlen(tree->u.equality.attr));
    254                 asn1_write_OctetString(data, tree->u.equality.value.data,
    255                                       tree->u.equality.value.length);
    256                 asn1_pop_tag(data);
     251                if (!asn1_push_tag(data, ASN1_CONTEXT(3))) return false;
     252                if (!asn1_write_OctetString(data, tree->u.equality.attr,
     253                                      strlen(tree->u.equality.attr))) return false;
     254                if (!asn1_write_OctetString(data, tree->u.equality.value.data,
     255                                      tree->u.equality.value.length)) return false;
     256                if (!asn1_pop_tag(data)) return false;
    257257                break;
    258258
     
    267267                                  final   [2] LDAPString } }
    268268                */
    269                 asn1_push_tag(data, ASN1_CONTEXT(4));
    270                 asn1_write_OctetString(data, tree->u.substring.attr, strlen(tree->u.substring.attr));
    271                 asn1_push_tag(data, ASN1_SEQUENCE(0));
    272                 i = 0;
    273                 if ( ! tree->u.substring.start_with_wildcard) {
    274                         asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(0));
    275                         asn1_write_DATA_BLOB_LDAPString(data, tree->u.substring.chunks[i]);
    276                         asn1_pop_tag(data);
    277                         i++;
    278                 }
    279                 while (tree->u.substring.chunks[i]) {
    280                         int ctx;
    281 
    282                         if (( ! tree->u.substring.chunks[i + 1]) &&
    283                             (tree->u.substring.end_with_wildcard == 0)) {
    284                                 ctx = 2;
    285                         } else {
    286                                 ctx = 1;
    287                         }
    288                         asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(ctx));
    289                         asn1_write_DATA_BLOB_LDAPString(data, tree->u.substring.chunks[i]);
    290                         asn1_pop_tag(data);
    291                         i++;
    292                 }
    293                 asn1_pop_tag(data);
    294                 asn1_pop_tag(data);
     269                if (!asn1_push_tag(data, ASN1_CONTEXT(4))) return false;
     270                if (!asn1_write_OctetString(data, tree->u.substring.attr, strlen(tree->u.substring.attr))) return false;
     271                if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) return false;
     272
     273                if (tree->u.substring.chunks && tree->u.substring.chunks[0]) {
     274                        i = 0;
     275                        if (!tree->u.substring.start_with_wildcard) {
     276                                if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(0))) return false;
     277                                if (!asn1_write_DATA_BLOB_LDAPString(data, tree->u.substring.chunks[i])) return false;
     278                                if (!asn1_pop_tag(data)) return false;
     279                                i++;
     280                        }
     281                        while (tree->u.substring.chunks[i]) {
     282                                int ctx;
     283
     284                                if (( ! tree->u.substring.chunks[i + 1]) &&
     285                                    (tree->u.substring.end_with_wildcard == 0)) {
     286                                        ctx = 2;
     287                                } else {
     288                                        ctx = 1;
     289                                }
     290                                if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(ctx))) return false;
     291                                if (!asn1_write_DATA_BLOB_LDAPString(data, tree->u.substring.chunks[i])) return false;
     292                                if (!asn1_pop_tag(data)) return false;
     293                                i++;
     294                        }
     295                }
     296                if (!asn1_pop_tag(data)) return false;
     297                if (!asn1_pop_tag(data)) return false;
    295298                break;
    296299
    297300        case LDB_OP_GREATER:
    298301                /* greaterOrEqual test */
    299                 asn1_push_tag(data, ASN1_CONTEXT(5));
    300                 asn1_write_OctetString(data, tree->u.comparison.attr,
    301                                       strlen(tree->u.comparison.attr));
    302                 asn1_write_OctetString(data, tree->u.comparison.value.data,
    303                                       tree->u.comparison.value.length);
    304                 asn1_pop_tag(data);
     302                if (!asn1_push_tag(data, ASN1_CONTEXT(5))) return false;
     303                if (!asn1_write_OctetString(data, tree->u.comparison.attr,
     304                                      strlen(tree->u.comparison.attr))) return false;
     305                if (!asn1_write_OctetString(data, tree->u.comparison.value.data,
     306                                      tree->u.comparison.value.length)) return false;
     307                if (!asn1_pop_tag(data)) return false;
    305308                break;
    306309
    307310        case LDB_OP_LESS:
    308311                /* lessOrEqual test */
    309                 asn1_push_tag(data, ASN1_CONTEXT(6));
    310                 asn1_write_OctetString(data, tree->u.comparison.attr,
    311                                       strlen(tree->u.comparison.attr));
    312                 asn1_write_OctetString(data, tree->u.comparison.value.data,
    313                                       tree->u.comparison.value.length);
    314                 asn1_pop_tag(data);
     312                if (!asn1_push_tag(data, ASN1_CONTEXT(6))) return false;
     313                if (!asn1_write_OctetString(data, tree->u.comparison.attr,
     314                                      strlen(tree->u.comparison.attr))) return false;
     315                if (!asn1_write_OctetString(data, tree->u.comparison.value.data,
     316                                      tree->u.comparison.value.length)) return false;
     317                if (!asn1_pop_tag(data)) return false;
    315318                break;
    316319
    317320        case LDB_OP_PRESENT:
    318321                /* present test */
    319                 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(7));
    320                 asn1_write_LDAPString(data, tree->u.present.attr);
    321                 asn1_pop_tag(data);
    322                 return !data->has_error;
     322                if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(7))) return false;
     323                if (!asn1_write_LDAPString(data, tree->u.present.attr)) return false;
     324                if (!asn1_pop_tag(data)) return false;
     325                return !asn1_has_error(data);
    323326
    324327        case LDB_OP_APPROX:
    325328                /* approx test */
    326                 asn1_push_tag(data, ASN1_CONTEXT(8));
    327                 asn1_write_OctetString(data, tree->u.comparison.attr,
    328                                       strlen(tree->u.comparison.attr));
    329                 asn1_write_OctetString(data, tree->u.comparison.value.data,
    330                                       tree->u.comparison.value.length);
    331                 asn1_pop_tag(data);
     329                if (!asn1_push_tag(data, ASN1_CONTEXT(8))) return false;
     330                if (!asn1_write_OctetString(data, tree->u.comparison.attr,
     331                                      strlen(tree->u.comparison.attr))) return false;
     332                if (!asn1_write_OctetString(data, tree->u.comparison.value.data,
     333                                      tree->u.comparison.value.length)) return false;
     334                if (!asn1_pop_tag(data)) return false;
    332335                break;
    333336
     
    341344                  }
    342345                */
    343                 asn1_push_tag(data, ASN1_CONTEXT(9));
     346                if (!asn1_push_tag(data, ASN1_CONTEXT(9))) return false;
    344347                if (tree->u.extended.rule_id) {
    345                         asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(1));
    346                         asn1_write_LDAPString(data, tree->u.extended.rule_id);
    347                         asn1_pop_tag(data);
     348                        if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(1))) return false;
     349                        if (!asn1_write_LDAPString(data, tree->u.extended.rule_id)) return false;
     350                        if (!asn1_pop_tag(data)) return false;
    348351                }
    349352                if (tree->u.extended.attr) {
    350                         asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(2));
    351                         asn1_write_LDAPString(data, tree->u.extended.attr);
    352                         asn1_pop_tag(data);
    353                 }
    354                 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(3));
    355                 asn1_write_DATA_BLOB_LDAPString(data, &tree->u.extended.value);
    356                 asn1_pop_tag(data);
    357                 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(4));
    358                 asn1_write_uint8(data, tree->u.extended.dnAttributes);
    359                 asn1_pop_tag(data);
    360                 asn1_pop_tag(data);
     353                        if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(2))) return false;
     354                        if (!asn1_write_LDAPString(data, tree->u.extended.attr)) return false;
     355                        if (!asn1_pop_tag(data)) return false;
     356                }
     357                if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(3))) return false;
     358                if (!asn1_write_DATA_BLOB_LDAPString(data, &tree->u.extended.value)) return false;
     359                if (!asn1_pop_tag(data)) return false;
     360                if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(4))) return false;
     361                if (!asn1_write_uint8(data, tree->u.extended.dnAttributes)) return false;
     362                if (!asn1_pop_tag(data)) return false;
     363                if (!asn1_pop_tag(data)) return false;
    361364                break;
    362365
     
    364367                return false;
    365368        }
    366         return !data->has_error;
    367 }
    368 
    369 static void ldap_encode_response(struct asn1_data *data, struct ldap_Result *result)
    370 {
    371         asn1_write_enumerated(data, result->resultcode);
    372         asn1_write_OctetString(data, result->dn,
    373                                (result->dn) ? strlen(result->dn) : 0);
    374         asn1_write_OctetString(data, result->errormessage,
     369        return !asn1_has_error(data);
     370}
     371
     372static bool ldap_encode_response(struct asn1_data *data, struct ldap_Result *result)
     373{
     374        if (!asn1_write_enumerated(data, result->resultcode)) return false;
     375        if (!asn1_write_OctetString(data, result->dn,
     376                               (result->dn) ? strlen(result->dn) : 0)) return false;
     377        if (!asn1_write_OctetString(data, result->errormessage,
    375378                               (result->errormessage) ?
    376                                strlen(result->errormessage) : 0);
     379                               strlen(result->errormessage) : 0)) return false;
    377380        if (result->referral) {
    378                 asn1_push_tag(data, ASN1_CONTEXT(3));
    379                 asn1_write_OctetString(data, result->referral,
    380                                        strlen(result->referral));
    381                 asn1_pop_tag(data);
    382         }
     381                if (!asn1_push_tag(data, ASN1_CONTEXT(3))) return false;
     382                if (!asn1_write_OctetString(data, result->referral,
     383                                       strlen(result->referral))) return false;
     384                if (!asn1_pop_tag(data)) return false;
     385        }
     386        return true;
    383387}
    384388
     
    392396        if (!data) return false;
    393397
    394         asn1_push_tag(data, ASN1_SEQUENCE(0));
    395         asn1_write_Integer(data, msg->messageid);
     398        if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) goto err;
     399        if (!asn1_write_Integer(data, msg->messageid)) goto err;
    396400
    397401        switch (msg->type) {
    398402        case LDAP_TAG_BindRequest: {
    399403                struct ldap_BindRequest *r = &msg->r.BindRequest;
    400                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    401                 asn1_write_Integer(data, r->version);
    402                 asn1_write_OctetString(data, r->dn,
    403                                        (r->dn != NULL) ? strlen(r->dn) : 0);
     404                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     405                if (!asn1_write_Integer(data, r->version)) goto err;
     406                if (!asn1_write_OctetString(data, r->dn,
     407                                       (r->dn != NULL) ? strlen(r->dn) : 0)) goto err;
    404408
    405409                switch (r->mechanism) {
    406410                case LDAP_AUTH_MECH_SIMPLE:
    407411                        /* context, primitive */
    408                         asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(0));
    409                         asn1_write(data, r->creds.password,
    410                                    strlen(r->creds.password));
    411                         asn1_pop_tag(data);
     412                        if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(0))) goto err;
     413                        if (!asn1_write(data, r->creds.password,
     414                                   strlen(r->creds.password))) goto err;
     415                        if (!asn1_pop_tag(data)) goto err;
    412416                        break;
    413417                case LDAP_AUTH_MECH_SASL:
    414418                        /* context, constructed */
    415                         asn1_push_tag(data, ASN1_CONTEXT(3));
    416                         asn1_write_OctetString(data, r->creds.SASL.mechanism,
    417                                                strlen(r->creds.SASL.mechanism));
     419                        if (!asn1_push_tag(data, ASN1_CONTEXT(3))) goto err;
     420                        if (!asn1_write_OctetString(data, r->creds.SASL.mechanism,
     421                                               strlen(r->creds.SASL.mechanism))) goto err;
    418422                        if (r->creds.SASL.secblob) {
    419                                 asn1_write_OctetString(data, r->creds.SASL.secblob->data,
    420                                                        r->creds.SASL.secblob->length);
    421                         }
    422                         asn1_pop_tag(data);
     423                                if (!asn1_write_OctetString(data, r->creds.SASL.secblob->data,
     424                                                       r->creds.SASL.secblob->length)) goto err;
     425                        }
     426                        if (!asn1_pop_tag(data)) goto err;
    423427                        break;
    424428                default:
    425                         return false;
    426                 }
    427 
    428                 asn1_pop_tag(data);
     429                        goto err;
     430                }
     431
     432                if (!asn1_pop_tag(data)) goto err;
    429433                break;
    430434        }
    431435        case LDAP_TAG_BindResponse: {
    432436                struct ldap_BindResponse *r = &msg->r.BindResponse;
    433                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    434                 ldap_encode_response(data, &r->response);
     437                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     438                if (!ldap_encode_response(data, &r->response)) goto err;
    435439                if (r->SASL.secblob) {
    436                         asn1_write_ContextSimple(data, 7, r->SASL.secblob);
    437                 }
    438                 asn1_pop_tag(data);
     440                        if (!asn1_write_ContextSimple(data, 7, r->SASL.secblob)) goto err;
     441                }
     442                if (!asn1_pop_tag(data)) goto err;
    439443                break;
    440444        }
    441445        case LDAP_TAG_UnbindRequest: {
    442446/*              struct ldap_UnbindRequest *r = &msg->r.UnbindRequest; */
    443                 asn1_push_tag(data, ASN1_APPLICATION_SIMPLE(msg->type));
    444                 asn1_pop_tag(data);
     447                if (!asn1_push_tag(data, ASN1_APPLICATION_SIMPLE(msg->type))) goto err;
     448                if (!asn1_pop_tag(data)) goto err;
    445449                break;
    446450        }
    447451        case LDAP_TAG_SearchRequest: {
    448452                struct ldap_SearchRequest *r = &msg->r.SearchRequest;
    449                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    450                 asn1_write_OctetString(data, r->basedn, strlen(r->basedn));
    451                 asn1_write_enumerated(data, r->scope);
    452                 asn1_write_enumerated(data, r->deref);
    453                 asn1_write_Integer(data, r->sizelimit);
    454                 asn1_write_Integer(data, r->timelimit);
    455                 asn1_write_BOOLEAN(data, r->attributesonly);
     453                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     454                if (!asn1_write_OctetString(data, r->basedn, strlen(r->basedn))) goto err;
     455                if (!asn1_write_enumerated(data, r->scope)) goto err;
     456                if (!asn1_write_enumerated(data, r->deref)) goto err;
     457                if (!asn1_write_Integer(data, r->sizelimit)) goto err;
     458                if (!asn1_write_Integer(data, r->timelimit)) goto err;
     459                if (!asn1_write_BOOLEAN(data, r->attributesonly)) goto err;
    456460
    457461                if (!ldap_push_filter(data, r->tree)) {
    458                         return false;
    459                 }
    460 
    461                 asn1_push_tag(data, ASN1_SEQUENCE(0));
     462                        goto err;
     463                }
     464
     465                if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) goto err;
    462466                for (i=0; i<r->num_attributes; i++) {
    463                         asn1_write_OctetString(data, r->attributes[i],
    464                                                strlen(r->attributes[i]));
    465                 }
    466                 asn1_pop_tag(data);
    467                 asn1_pop_tag(data);
     467                        if (!asn1_write_OctetString(data, r->attributes[i],
     468                                               strlen(r->attributes[i]))) goto err;
     469                }
     470                if (!asn1_pop_tag(data)) goto err;
     471                if (!asn1_pop_tag(data)) goto err;
    468472                break;
    469473        }
    470474        case LDAP_TAG_SearchResultEntry: {
    471475                struct ldap_SearchResEntry *r = &msg->r.SearchResultEntry;
    472                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    473                 asn1_write_OctetString(data, r->dn, strlen(r->dn));
    474                 asn1_push_tag(data, ASN1_SEQUENCE(0));
     476                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     477                if (!asn1_write_OctetString(data, r->dn, strlen(r->dn))) goto err;
     478                if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) goto err;
    475479                for (i=0; i<r->num_attributes; i++) {
    476480                        struct ldb_message_element *attr = &r->attributes[i];
    477                         asn1_push_tag(data, ASN1_SEQUENCE(0));
    478                         asn1_write_OctetString(data, attr->name,
    479                                                strlen(attr->name));
    480                         asn1_push_tag(data, ASN1_SEQUENCE(1));
     481                        if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) goto err;
     482                        if (!asn1_write_OctetString(data, attr->name,
     483                                               strlen(attr->name))) goto err;
     484                        if (!asn1_push_tag(data, ASN1_SEQUENCE(1))) goto err;
    481485                        for (j=0; j<attr->num_values; j++) {
    482                                 asn1_write_OctetString(data,
     486                                if (!asn1_write_OctetString(data,
    483487                                                       attr->values[j].data,
    484                                                        attr->values[j].length);
    485                         }
    486                         asn1_pop_tag(data);
    487                         asn1_pop_tag(data);
    488                 }
    489                 asn1_pop_tag(data);
    490                 asn1_pop_tag(data);
     488                                                       attr->values[j].length)) goto err;
     489                        }
     490                        if (!asn1_pop_tag(data)) goto err;
     491                        if (!asn1_pop_tag(data)) goto err;
     492                }
     493                if (!asn1_pop_tag(data)) goto err;
     494                if (!asn1_pop_tag(data)) goto err;
    491495                break;
    492496        }
    493497        case LDAP_TAG_SearchResultDone: {
    494498                struct ldap_Result *r = &msg->r.SearchResultDone;
    495                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    496                 ldap_encode_response(data, r);
    497                 asn1_pop_tag(data);
     499                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     500                if (!ldap_encode_response(data, r)) goto err;
     501                if (!asn1_pop_tag(data)) goto err;
    498502                break;
    499503        }
    500504        case LDAP_TAG_ModifyRequest: {
    501505                struct ldap_ModifyRequest *r = &msg->r.ModifyRequest;
    502                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    503                 asn1_write_OctetString(data, r->dn, strlen(r->dn));
    504                 asn1_push_tag(data, ASN1_SEQUENCE(0));
     506                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     507                if (!asn1_write_OctetString(data, r->dn, strlen(r->dn))) goto err;
     508                if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) goto err;
    505509
    506510                for (i=0; i<r->num_mods; i++) {
    507511                        struct ldb_message_element *attrib = &r->mods[i].attrib;
    508                         asn1_push_tag(data, ASN1_SEQUENCE(0));
    509                         asn1_write_enumerated(data, r->mods[i].type);
    510                         asn1_push_tag(data, ASN1_SEQUENCE(0));
    511                         asn1_write_OctetString(data, attrib->name,
    512                                                strlen(attrib->name));
    513                         asn1_push_tag(data, ASN1_SET);
     512                        if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) goto err;
     513                        if (!asn1_write_enumerated(data, r->mods[i].type)) goto err;
     514                        if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) goto err;
     515                        if (!asn1_write_OctetString(data, attrib->name,
     516                                               strlen(attrib->name))) goto err;
     517                        if (!asn1_push_tag(data, ASN1_SET)) goto err;
    514518                        for (j=0; j<attrib->num_values; j++) {
    515                                 asn1_write_OctetString(data,
     519                                if (!asn1_write_OctetString(data,
    516520                                                       attrib->values[j].data,
    517                                                        attrib->values[j].length);
     521                                                       attrib->values[j].length)) goto err;
    518522       
    519523                        }
    520                         asn1_pop_tag(data);
    521                         asn1_pop_tag(data);
    522                         asn1_pop_tag(data);
     524                        if (!asn1_pop_tag(data)) goto err;
     525                        if (!asn1_pop_tag(data)) goto err;
     526                        if (!asn1_pop_tag(data)) goto err;
    523527                }
    524528               
    525                 asn1_pop_tag(data);
    526                 asn1_pop_tag(data);
     529                if (!asn1_pop_tag(data)) goto err;
     530                if (!asn1_pop_tag(data)) goto err;
    527531                break;
    528532        }
    529533        case LDAP_TAG_ModifyResponse: {
    530534                struct ldap_Result *r = &msg->r.ModifyResponse;
    531                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    532                 ldap_encode_response(data, r);
    533                 asn1_pop_tag(data);
     535                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     536                if (!ldap_encode_response(data, r)) goto err;
     537                if (!asn1_pop_tag(data)) goto err;
    534538                break;
    535539        }
    536540        case LDAP_TAG_AddRequest: {
    537541                struct ldap_AddRequest *r = &msg->r.AddRequest;
    538                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    539                 asn1_write_OctetString(data, r->dn, strlen(r->dn));
    540                 asn1_push_tag(data, ASN1_SEQUENCE(0));
     542                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     543                if (!asn1_write_OctetString(data, r->dn, strlen(r->dn))) goto err;
     544                if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) goto err;
    541545
    542546                for (i=0; i<r->num_attributes; i++) {
    543547                        struct ldb_message_element *attrib = &r->attributes[i];
    544                         asn1_push_tag(data, ASN1_SEQUENCE(0));
    545                         asn1_write_OctetString(data, attrib->name,
    546                                                strlen(attrib->name));
    547                         asn1_push_tag(data, ASN1_SET);
     548                        if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) goto err;
     549                        if (!asn1_write_OctetString(data, attrib->name,
     550                                               strlen(attrib->name))) goto err;
     551                        if (!asn1_push_tag(data, ASN1_SET)) goto err;
    548552                        for (j=0; j<r->attributes[i].num_values; j++) {
    549                                 asn1_write_OctetString(data,
     553                                if (!asn1_write_OctetString(data,
    550554                                                       attrib->values[j].data,
    551                                                        attrib->values[j].length);
    552                         }
    553                         asn1_pop_tag(data);
    554                         asn1_pop_tag(data);
    555                 }
    556                 asn1_pop_tag(data);
    557                 asn1_pop_tag(data);
     555                                                       attrib->values[j].length)) goto err;
     556                        }
     557                        if (!asn1_pop_tag(data)) goto err;
     558                        if (!asn1_pop_tag(data)) goto err;
     559                }
     560                if (!asn1_pop_tag(data)) goto err;
     561                if (!asn1_pop_tag(data)) goto err;
    558562                break;
    559563        }
    560564        case LDAP_TAG_AddResponse: {
    561565                struct ldap_Result *r = &msg->r.AddResponse;
    562                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    563                 ldap_encode_response(data, r);
    564                 asn1_pop_tag(data);
     566                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     567                if (!ldap_encode_response(data, r)) goto err;
     568                if (!asn1_pop_tag(data)) goto err;
    565569                break;
    566570        }
    567571        case LDAP_TAG_DelRequest: {
    568572                struct ldap_DelRequest *r = &msg->r.DelRequest;
    569                 asn1_push_tag(data, ASN1_APPLICATION_SIMPLE(msg->type));
    570                 asn1_write(data, r->dn, strlen(r->dn));
    571                 asn1_pop_tag(data);
     573                if (!asn1_push_tag(data, ASN1_APPLICATION_SIMPLE(msg->type))) goto err;
     574                if (!asn1_write(data, r->dn, strlen(r->dn))) goto err;
     575                if (!asn1_pop_tag(data)) goto err;
    572576                break;
    573577        }
    574578        case LDAP_TAG_DelResponse: {
    575579                struct ldap_Result *r = &msg->r.DelResponse;
    576                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    577                 ldap_encode_response(data, r);
    578                 asn1_pop_tag(data);
     580                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     581                if (!ldap_encode_response(data, r)) goto err;
     582                if (!asn1_pop_tag(data)) goto err;
    579583                break;
    580584        }
    581585        case LDAP_TAG_ModifyDNRequest: {
    582586                struct ldap_ModifyDNRequest *r = &msg->r.ModifyDNRequest;
    583                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    584                 asn1_write_OctetString(data, r->dn, strlen(r->dn));
    585                 asn1_write_OctetString(data, r->newrdn, strlen(r->newrdn));
    586                 asn1_write_BOOLEAN(data, r->deleteolddn);
     587                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     588                if (!asn1_write_OctetString(data, r->dn, strlen(r->dn))) goto err;
     589                if (!asn1_write_OctetString(data, r->newrdn, strlen(r->newrdn))) goto err;
     590                if (!asn1_write_BOOLEAN(data, r->deleteolddn)) goto err;
    587591                if (r->newsuperior) {
    588                         asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(0));
    589                         asn1_write(data, r->newsuperior,
    590                                    strlen(r->newsuperior));
    591                         asn1_pop_tag(data);
    592                 }
    593                 asn1_pop_tag(data);
     592                        if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(0))) goto err;
     593                        if (!asn1_write(data, r->newsuperior,
     594                                   strlen(r->newsuperior))) goto err;
     595                        if (!asn1_pop_tag(data)) goto err;
     596                }
     597                if (!asn1_pop_tag(data)) goto err;
    594598                break;
    595599        }
    596600        case LDAP_TAG_ModifyDNResponse: {
    597601                struct ldap_Result *r = &msg->r.ModifyDNResponse;
    598                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    599                 ldap_encode_response(data, r);
    600                 asn1_pop_tag(data);
     602                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     603                if (!ldap_encode_response(data, r)) goto err;
     604                if (!asn1_pop_tag(data)) goto err;
    601605                break;
    602606        }
    603607        case LDAP_TAG_CompareRequest: {
    604608                struct ldap_CompareRequest *r = &msg->r.CompareRequest;
    605                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    606                 asn1_write_OctetString(data, r->dn, strlen(r->dn));
    607                 asn1_push_tag(data, ASN1_SEQUENCE(0));
    608                 asn1_write_OctetString(data, r->attribute,
    609                                        strlen(r->attribute));
    610                 asn1_write_OctetString(data, r->value.data,
    611                                        r->value.length);
    612                 asn1_pop_tag(data);
    613                 asn1_pop_tag(data);
     609                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     610                if (!asn1_write_OctetString(data, r->dn, strlen(r->dn))) goto err;
     611                if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) goto err;
     612                if (!asn1_write_OctetString(data, r->attribute,
     613                                       strlen(r->attribute))) goto err;
     614                if (!asn1_write_OctetString(data, r->value.data,
     615                                       r->value.length)) goto err;
     616                if (!asn1_pop_tag(data)) goto err;
     617                if (!asn1_pop_tag(data)) goto err;
    614618                break;
    615619        }
    616620        case LDAP_TAG_CompareResponse: {
    617621                struct ldap_Result *r = &msg->r.ModifyDNResponse;
    618                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    619                 ldap_encode_response(data, r);
    620                 asn1_pop_tag(data);
     622                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     623                if (!ldap_encode_response(data, r)) goto err;
     624                if (!asn1_pop_tag(data)) goto err;
    621625                break;
    622626        }
    623627        case LDAP_TAG_AbandonRequest: {
    624628                struct ldap_AbandonRequest *r = &msg->r.AbandonRequest;
    625                 asn1_push_tag(data, ASN1_APPLICATION_SIMPLE(msg->type));
    626                 asn1_write_implicit_Integer(data, r->messageid);
    627                 asn1_pop_tag(data);
     629                if (!asn1_push_tag(data, ASN1_APPLICATION_SIMPLE(msg->type))) goto err;
     630                if (!asn1_write_implicit_Integer(data, r->messageid)) goto err;
     631                if (!asn1_pop_tag(data)) goto err;
    628632                break;
    629633        }
    630634        case LDAP_TAG_SearchResultReference: {
    631635                struct ldap_SearchResRef *r = &msg->r.SearchResultReference;
    632                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    633                 asn1_write_OctetString(data, r->referral, strlen(r->referral));
    634                 asn1_pop_tag(data);
     636                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     637                if (!asn1_write_OctetString(data, r->referral, strlen(r->referral))) goto err;
     638                if (!asn1_pop_tag(data)) goto err;
    635639                break;
    636640        }
    637641        case LDAP_TAG_ExtendedRequest: {
    638642                struct ldap_ExtendedRequest *r = &msg->r.ExtendedRequest;
    639                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    640                 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(0));
    641                 asn1_write(data, r->oid, strlen(r->oid));
    642                 asn1_pop_tag(data);
     643                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     644                if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(0))) goto err;
     645                if (!asn1_write(data, r->oid, strlen(r->oid))) goto err;
     646                if (!asn1_pop_tag(data)) goto err;
    643647                if (r->value) {
    644                         asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(1));
    645                         asn1_write(data, r->value->data, r->value->length);
    646                         asn1_pop_tag(data);
    647                 }
    648                 asn1_pop_tag(data);
     648                        if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(1))) goto err;
     649                        if (!asn1_write(data, r->value->data, r->value->length)) goto err;
     650                        if (!asn1_pop_tag(data)) goto err;
     651                }
     652                if (!asn1_pop_tag(data)) goto err;
    649653                break;
    650654        }
    651655        case LDAP_TAG_ExtendedResponse: {
    652656                struct ldap_ExtendedResponse *r = &msg->r.ExtendedResponse;
    653                 asn1_push_tag(data, ASN1_APPLICATION(msg->type));
    654                 ldap_encode_response(data, &r->response);
     657                if (!asn1_push_tag(data, ASN1_APPLICATION(msg->type))) goto err;
     658                if (!ldap_encode_response(data, &r->response)) goto err;
    655659                if (r->oid) {
    656                         asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(10));
    657                         asn1_write(data, r->oid, strlen(r->oid));
    658                         asn1_pop_tag(data);
     660                        if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(10))) goto err;
     661                        if (!asn1_write(data, r->oid, strlen(r->oid))) goto err;
     662                        if (!asn1_pop_tag(data)) goto err;
    659663                }
    660664                if (r->value) {
    661                         asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(11));
    662                         asn1_write(data, r->value->data, r->value->length);
    663                         asn1_pop_tag(data);
    664                 }
    665                 asn1_pop_tag(data);
     665                        if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(11))) goto err;
     666                        if (!asn1_write(data, r->value->data, r->value->length)) goto err;
     667                        if (!asn1_pop_tag(data)) goto err;
     668                }
     669                if (!asn1_pop_tag(data)) goto err;
    666670                break;
    667671        }
    668672        default:
    669                 return false;
     673                goto err;
    670674        }
    671675
    672676        if (msg->controls != NULL) {
    673                 asn1_push_tag(data, ASN1_CONTEXT(0));
     677                if (!asn1_push_tag(data, ASN1_CONTEXT(0))) goto err;
    674678               
    675679                for (i = 0; msg->controls[i] != NULL; i++) {
     
    677681                                                 control_handlers,
    678682                                                 msg->controls[i])) {
    679                                 DEBUG(1,("Unable to encode control %s\n",
     683                                DEBUG(0,("Unable to encode control %s\n",
    680684                                         msg->controls[i]->oid));
    681                                 return false;
    682                         }
    683                 }
    684 
    685                 asn1_pop_tag(data);
    686         }
    687 
    688         asn1_pop_tag(data);
    689 
    690         if (data->has_error) {
    691                 asn1_free(data);
    692                 return false;
    693         }
    694 
    695         *result = data_blob_talloc(mem_ctx, data->data, data->length);
     685                                goto err;
     686                        }
     687                }
     688
     689                if (!asn1_pop_tag(data)) goto err;
     690        }
     691
     692        if (!asn1_pop_tag(data)) goto err;
     693
     694        if (!asn1_extract_blob(data, mem_ctx, result)) {
     695                goto err;
     696        }
     697
    696698        asn1_free(data);
     699
    697700        return true;
     701
     702  err:
     703
     704        asn1_free(data);
     705        return false;
    698706}
    699707
     
    702710{
    703711        char *result = talloc_array(mem_ctx, char, blob.length+1);
     712        if (result == NULL) {
     713                return NULL;
     714        }
    704715        memcpy(result, blob.data, blob.length);
    705716        result[blob.length] = '\0';
     
    716727        *result = blob2string_talloc(mem_ctx, string);
    717728        data_blob_free(&string);
    718         return true;
    719 }
    720 
    721 static void ldap_decode_response(TALLOC_CTX *mem_ctx,
     729        return *result ? true : false;
     730}
     731
     732static bool ldap_decode_response(TALLOC_CTX *mem_ctx,
    722733                                 struct asn1_data *data,
    723734                                 struct ldap_Result *result)
    724735{
    725         asn1_read_enumerated(data, &result->resultcode);
    726         asn1_read_OctetString_talloc(mem_ctx, data, &result->dn);
    727         asn1_read_OctetString_talloc(mem_ctx, data, &result->errormessage);
     736        if (!asn1_read_enumerated(data, &result->resultcode)) return false;
     737        if (!asn1_read_OctetString_talloc(mem_ctx, data, &result->dn)) return false;
     738        if (!asn1_read_OctetString_talloc(mem_ctx, data, &result->errormessage)) return false;
    728739        if (asn1_peek_tag(data, ASN1_CONTEXT(3))) {
    729                 asn1_start_tag(data, ASN1_CONTEXT(3));
    730                 asn1_read_OctetString_talloc(mem_ctx, data, &result->referral);
    731                 asn1_end_tag(data);
     740                if (!asn1_start_tag(data, ASN1_CONTEXT(3))) return false;
     741                if (!asn1_read_OctetString_talloc(mem_ctx, data, &result->referral)) return false;
     742                if (!asn1_end_tag(data)) return false;
    732743        } else {
    733744                result->referral = NULL;
    734745        }
     746        return true;
    735747}
    736748
     
    754766        chunks[chunk_num]->length = strlen(value);
    755767
    756         chunks[chunk_num + 1] = '\0';
     768        chunks[chunk_num + 1] = NULL;
    757769
    758770        return chunks;
     
    833845                DATA_BLOB value;
    834846
    835                 asn1_start_tag(data, ASN1_CONTEXT(filter_tag));
    836                 asn1_read_OctetString_talloc(mem_ctx, data, &attrib);
    837                 asn1_read_OctetString(data, mem_ctx, &value);
    838                 asn1_end_tag(data);
    839                 if ((data->has_error) || (attrib == NULL) || (value.data == NULL)) {
     847                if (!asn1_start_tag(data, ASN1_CONTEXT(filter_tag))) goto failed;
     848                if (!asn1_read_OctetString_talloc(mem_ctx, data, &attrib)) goto failed;
     849                if (!asn1_read_OctetString(data, mem_ctx, &value)) goto failed;
     850                if (!asn1_end_tag(data)) goto failed;
     851                if (asn1_has_error(data) || (attrib == NULL) ||
     852                    (value.data == NULL)) {
    840853                        goto failed;
    841854                }
     
    863876                ret->operation = LDB_OP_SUBSTRING;
    864877                ret->u.substring.attr = talloc_strndup(ret, (char *)attr.data, attr.length);
     878                if (ret->u.substring.attr == NULL) {
     879                        goto failed;
     880                }
    865881                ret->u.substring.chunks = NULL;
    866882                ret->u.substring.start_with_wildcard = 1;
     
    872888
    873889                while (asn1_tag_remaining(data)) {
    874                         asn1_peek_uint8(data, &subs_tag);
     890                        if (!asn1_peek_uint8(data, &subs_tag)) goto failed;
    875891                        subs_tag &= 0x1f;       /* strip off the asn1 stuff */
    876892                        if (subs_tag > 2) goto failed;
    877893
    878                         asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(subs_tag));
    879                         asn1_read_LDAPString(data, mem_ctx, &value);
    880                         asn1_end_tag(data);
     894                        if (!asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(subs_tag))) goto failed;
     895                        if (!asn1_read_LDAPString(data, mem_ctx, &value)) goto failed;
     896                        if (!asn1_end_tag(data)) goto failed;
    881897
    882898                        switch (subs_tag) {
     
    945961                DATA_BLOB value;
    946962
    947                 asn1_start_tag(data, ASN1_CONTEXT(filter_tag));
    948                 asn1_read_OctetString_talloc(mem_ctx, data, &attrib);
    949                 asn1_read_OctetString(data, mem_ctx, &value);
    950                 asn1_end_tag(data);
    951                 if ((data->has_error) || (attrib == NULL) || (value.data == NULL)) {
     963                if (!asn1_start_tag(data, ASN1_CONTEXT(filter_tag))) goto failed;
     964                if (!asn1_read_OctetString_talloc(mem_ctx, data, &attrib)) goto failed;
     965                if (!asn1_read_OctetString(data, mem_ctx, &value)) goto failed;
     966                if (!asn1_end_tag(data)) goto failed;
     967                if (asn1_has_error(data) || (attrib == NULL) ||
     968                    (value.data == NULL)) {
    952969                        goto failed;
    953970                }
     
    964981                DATA_BLOB value;
    965982
    966                 asn1_start_tag(data, ASN1_CONTEXT(filter_tag));
    967                 asn1_read_OctetString_talloc(mem_ctx, data, &attrib);
    968                 asn1_read_OctetString(data, mem_ctx, &value);
    969                 asn1_end_tag(data);
    970                 if ((data->has_error) || (attrib == NULL) || (value.data == NULL)) {
     983                if (!asn1_start_tag(data, ASN1_CONTEXT(filter_tag))) goto failed;
     984                if (!asn1_read_OctetString_talloc(mem_ctx, data, &attrib)) goto failed;
     985                if (!asn1_read_OctetString(data, mem_ctx, &value)) goto failed;
     986                if (!asn1_end_tag(data)) goto failed;
     987                if (asn1_has_error(data) || (attrib == NULL) ||
     988                    (value.data == NULL)) {
    971989                        goto failed;
    972990                }
     
    10021020                DATA_BLOB value;
    10031021
    1004                 asn1_start_tag(data, ASN1_CONTEXT(filter_tag));
    1005                 asn1_read_OctetString_talloc(mem_ctx, data, &attrib);
    1006                 asn1_read_OctetString(data, mem_ctx, &value);
    1007                 asn1_end_tag(data);
    1008                 if ((data->has_error) || (attrib == NULL) || (value.data == NULL)) {
     1022                if (!asn1_start_tag(data, ASN1_CONTEXT(filter_tag))) goto failed;
     1023                if (!asn1_read_OctetString_talloc(mem_ctx, data, &attrib)) goto failed;
     1024                if (!asn1_read_OctetString(data, mem_ctx, &value)) goto failed;
     1025                if (!asn1_end_tag(data)) goto failed;
     1026                if (asn1_has_error(data) || (attrib == NULL) ||
     1027                    (value.data == NULL)) {
    10091028                        goto failed;
    10101029                }
     
    10281047                /* either oid or type must be defined */
    10291048                if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(1))) { /* optional */
    1030                         asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(1));
    1031                         asn1_read_LDAPString(data, ret, &oid);
    1032                         asn1_end_tag(data);
     1049                        if (!asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(1))) goto failed;
     1050                        if (!asn1_read_LDAPString(data, ret, &oid)) goto failed;
     1051                        if (!asn1_end_tag(data)) goto failed;
    10331052                }
    10341053                if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(2))) {      /* optional  */
    1035                         asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(2));
    1036                         asn1_read_LDAPString(data, ret, &attr);
    1037                         asn1_end_tag(data);
    1038                 }
    1039                 asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(3));
    1040                 asn1_read_LDAPString(data, ret, &value);
    1041                 asn1_end_tag(data);
     1054                        if (!asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(2))) goto failed;
     1055                        if (!asn1_read_LDAPString(data, ret, &attr)) goto failed;
     1056                        if (!asn1_end_tag(data)) goto failed;
     1057                }
     1058                if (!asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(3))) goto failed;
     1059                if (!asn1_read_LDAPString(data, ret, &value)) goto failed;
     1060                if (!asn1_end_tag(data)) goto failed;
    10421061                /* dnAttributes is marked as BOOLEAN DEFAULT FALSE
    10431062                   it is not marked as OPTIONAL but openldap tools
     
    10471066                   boolean value to be set */
    10481067                if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(4))) {
    1049                         asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(4));
    1050                         asn1_read_uint8(data, &dnAttributes);
    1051                         asn1_end_tag(data);
     1068                        if (!asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(4))) goto failed;
     1069                        if (!asn1_read_uint8(data, &dnAttributes)) goto failed;
     1070                        if (!asn1_end_tag(data)) goto failed;
    10521071                } else {
    10531072                        dnAttributes = 0;
     
    10681087                        } else {
    10691088                                ret->u.extended.attr = talloc_strdup(ret, "*");
     1089                                if (ret->u.extended.attr == NULL) {
     1090                                        goto failed;
     1091                                }
    10701092                        }
    10711093                        ret->u.extended.rule_id      = talloc_steal(ret, oid);
     
    10971119
    10981120/* Decode a single LDAP attribute, possibly containing multiple values */
    1099 static void ldap_decode_attrib(TALLOC_CTX *mem_ctx, struct asn1_data *data,
     1121static bool ldap_decode_attrib(TALLOC_CTX *mem_ctx, struct asn1_data *data,
    11001122                               struct ldb_message_element *attrib)
    11011123{
    1102         asn1_start_tag(data, ASN1_SEQUENCE(0));
    1103         asn1_read_OctetString_talloc(mem_ctx, data, &attrib->name);
    1104         asn1_start_tag(data, ASN1_SET);
     1124        if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) return false;
     1125        if (!asn1_read_OctetString_talloc(mem_ctx, data, &attrib->name)) return false;
     1126        if (!asn1_start_tag(data, ASN1_SET)) return false;
    11051127        while (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
    11061128                DATA_BLOB blob;
    1107                 asn1_read_OctetString(data, mem_ctx, &blob);
     1129                if (!asn1_read_OctetString(data, mem_ctx, &blob)) return false;
    11081130                add_value_to_attrib(mem_ctx, &blob, attrib);
    11091131        }
    1110         asn1_end_tag(data);
    1111         asn1_end_tag(data);
    1112        
     1132        if (!asn1_end_tag(data)) return false;
     1133        return asn1_end_tag(data);
    11131134}
    11141135
    11151136/* Decode a set of LDAP attributes, as found in the dereference control */
    1116 void ldap_decode_attribs_bare(TALLOC_CTX *mem_ctx, struct asn1_data *data,
     1137bool ldap_decode_attribs_bare(TALLOC_CTX *mem_ctx, struct asn1_data *data,
    11171138                              struct ldb_message_element **attributes,
    11181139                              int *num_attributes)
     
    11211142                struct ldb_message_element attrib;
    11221143                ZERO_STRUCT(attrib);
    1123                 ldap_decode_attrib(mem_ctx, data, &attrib);
     1144                if (!ldap_decode_attrib(mem_ctx, data, &attrib)) return false;
    11241145                add_attrib_to_array_talloc(mem_ctx, &attrib,
    11251146                                           attributes, num_attributes);
    11261147        }
     1148        return true;
    11271149}
    11281150
    11291151/* Decode a set of LDAP attributes, as found in a search entry */
    1130 static void ldap_decode_attribs(TALLOC_CTX *mem_ctx, struct asn1_data *data,
     1152static bool ldap_decode_attribs(TALLOC_CTX *mem_ctx, struct asn1_data *data,
    11311153                                struct ldb_message_element **attributes,
    11321154                                int *num_attributes)
    11331155{
    1134         asn1_start_tag(data, ASN1_SEQUENCE(0));
    1135         ldap_decode_attribs_bare(mem_ctx, data,
    1136                                  attributes, num_attributes);
    1137         asn1_end_tag(data);
     1156        if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) return false;
     1157        if (!ldap_decode_attribs_bare(mem_ctx, data,
     1158                                 attributes, num_attributes)) return false;
     1159        return asn1_end_tag(data);
    11381160}
    11391161
     
    11461168        uint8_t tag;
    11471169
    1148         asn1_start_tag(data, ASN1_SEQUENCE(0));
    1149         asn1_read_Integer(data, &msg->messageid);
    1150 
    1151         if (!asn1_peek_uint8(data, &tag))
    1152                 return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
     1170        if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) goto prot_err;
     1171        if (!asn1_read_Integer(data, &msg->messageid)) goto prot_err;
     1172
     1173        if (!asn1_peek_uint8(data, &tag)) goto prot_err;
    11531174
    11541175        switch(tag) {
     
    11571178                struct ldap_BindRequest *r = &msg->r.BindRequest;
    11581179                msg->type = LDAP_TAG_BindRequest;
    1159                 asn1_start_tag(data, tag);
    1160                 asn1_read_Integer(data, &r->version);
    1161                 asn1_read_OctetString_talloc(msg, data, &r->dn);
     1180                if (!asn1_start_tag(data, tag)) goto prot_err;
     1181                if (!asn1_read_Integer(data, &r->version)) goto prot_err;
     1182                if (!asn1_read_OctetString_talloc(msg, data, &r->dn)) goto prot_err;
    11621183                if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(0))) {
    11631184                        int pwlen;
    11641185                        r->creds.password = "";
    11651186                        r->mechanism = LDAP_AUTH_MECH_SIMPLE;
    1166                         asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(0));
     1187                        if (!asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(0))) goto prot_err;
    11671188                        pwlen = asn1_tag_remaining(data);
    11681189                        if (pwlen == -1) {
    1169                                 return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
     1190                                goto prot_err;
    11701191                        }
    11711192                        if (pwlen != 0) {
     
    11741195                                        return NT_STATUS_LDAP(LDAP_OPERATIONS_ERROR);
    11751196                                }
    1176                                 asn1_read(data, pw, pwlen);
     1197                                if (!asn1_read(data, pw, pwlen)) goto prot_err;
    11771198                                pw[pwlen] = '\0';
    11781199                                r->creds.password = pw;
    11791200                        }
    1180                         asn1_end_tag(data);
     1201                        if (!asn1_end_tag(data)) goto prot_err;
    11811202                } else if (asn1_peek_tag(data, ASN1_CONTEXT(3))){
    1182                         asn1_start_tag(data, ASN1_CONTEXT(3));
     1203                        if (!asn1_start_tag(data, ASN1_CONTEXT(3))) goto prot_err;
    11831204                        r->mechanism = LDAP_AUTH_MECH_SASL;
    1184                         asn1_read_OctetString_talloc(msg, data, &r->creds.SASL.mechanism);
     1205                        if (!asn1_read_OctetString_talloc(msg, data, &r->creds.SASL.mechanism)) goto prot_err;
    11851206                        if (asn1_peek_tag(data, ASN1_OCTET_STRING)) { /* optional */
    11861207                                DATA_BLOB tmp_blob = data_blob(NULL, 0);
    1187                                 asn1_read_OctetString(data, msg, &tmp_blob);
     1208                                if (!asn1_read_OctetString(data, msg, &tmp_blob)) goto prot_err;
    11881209                                r->creds.SASL.secblob = talloc(msg, DATA_BLOB);
    11891210                                if (!r->creds.SASL.secblob) {
     
    11961217                                r->creds.SASL.secblob = NULL;
    11971218                        }
    1198                         asn1_end_tag(data);
     1219                        if (!asn1_end_tag(data)) goto prot_err;
    11991220                } else {
    12001221                        /* Neither Simple nor SASL bind */
    1201                         return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
    1202                 }
    1203                 asn1_end_tag(data);
     1222                        goto prot_err;
     1223                }
     1224                if (!asn1_end_tag(data)) goto prot_err;
    12041225                break;
    12051226        }
     
    12081229                struct ldap_BindResponse *r = &msg->r.BindResponse;
    12091230                msg->type = LDAP_TAG_BindResponse;
    1210                 asn1_start_tag(data, tag);
    1211                 ldap_decode_response(msg, data, &r->response);
     1231                if (!asn1_start_tag(data, tag)) goto prot_err;
     1232                if (!ldap_decode_response(msg, data, &r->response)) goto prot_err;
    12121233                if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(7))) {
    12131234                        DATA_BLOB tmp_blob = data_blob(NULL, 0);
    1214                         asn1_read_ContextSimple(data, 7, &tmp_blob);
     1235                        if (!asn1_read_ContextSimple(data, 7, &tmp_blob)) goto prot_err;
    12151236                        r->SASL.secblob = talloc(msg, DATA_BLOB);
    12161237                        if (!r->SASL.secblob) {
     
    12231244                        r->SASL.secblob = NULL;
    12241245                }
    1225                 asn1_end_tag(data);
     1246                if (!asn1_end_tag(data)) goto prot_err;
    12261247                break;
    12271248        }
     
    12291250        case ASN1_APPLICATION_SIMPLE(LDAP_TAG_UnbindRequest): {
    12301251                msg->type = LDAP_TAG_UnbindRequest;
    1231                 asn1_start_tag(data, tag);
    1232                 asn1_end_tag(data);
     1252                if (!asn1_start_tag(data, tag)) goto prot_err;
     1253                if (!asn1_end_tag(data)) goto prot_err;
    12331254                break;
    12341255        }
     
    12391260                const char **attrs = NULL;
    12401261                msg->type = LDAP_TAG_SearchRequest;
    1241                 asn1_start_tag(data, tag);
    1242                 asn1_read_OctetString_talloc(msg, data, &r->basedn);
    1243                 asn1_read_enumerated(data, (int *)(void *)&(r->scope));
    1244                 asn1_read_enumerated(data, (int *)(void *)&(r->deref));
    1245                 asn1_read_Integer(data, &sizelimit);
     1262                if (!asn1_start_tag(data, tag)) goto prot_err;
     1263                if (!asn1_read_OctetString_talloc(msg, data, &r->basedn)) goto prot_err;
     1264                if (!asn1_read_enumerated(data, (int *)(void *)&(r->scope))) goto prot_err;
     1265                if (!asn1_read_enumerated(data, (int *)(void *)&(r->deref))) goto prot_err;
     1266                if (!asn1_read_Integer(data, &sizelimit)) goto prot_err;
    12461267                r->sizelimit = sizelimit;
    1247                 asn1_read_Integer(data, &timelimit);
     1268                if (!asn1_read_Integer(data, &timelimit)) goto prot_err;
    12481269                r->timelimit = timelimit;
    1249                 asn1_read_BOOLEAN(data, &r->attributesonly);
     1270                if (!asn1_read_BOOLEAN(data, &r->attributesonly)) goto prot_err;
    12501271
    12511272                r->tree = ldap_decode_filter_tree(msg, data);
    12521273                if (r->tree == NULL) {
    1253                         return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
    1254                 }
    1255 
    1256                 asn1_start_tag(data, ASN1_SEQUENCE(0));
     1274                        goto prot_err;
     1275                }
     1276
     1277                if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) goto prot_err;
    12571278
    12581279                r->num_attributes = 0;
    12591280                r->attributes = NULL;
    12601281
    1261                 while (asn1_tag_remaining(data) > 0) {                                 
     1282                while (asn1_tag_remaining(data) > 0) {
    12621283
    12631284                        const char *attr;
    12641285                        if (!asn1_read_OctetString_talloc(msg, data,
    12651286                                                          &attr))
    1266                                 return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
     1287                                goto prot_err;
    12671288                        if (!add_string_to_array(msg, attr,
    12681289                                                 &attrs,
    12691290                                                 &r->num_attributes))
    1270                                 return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
     1291                                goto prot_err;
    12711292                }
    12721293                r->attributes = attrs;
    12731294
    1274                 asn1_end_tag(data);
    1275                 asn1_end_tag(data);
     1295                if (!asn1_end_tag(data)) goto prot_err;
     1296                if (!asn1_end_tag(data)) goto prot_err;
    12761297                break;
    12771298        }
     
    12821303                r->attributes = NULL;
    12831304                r->num_attributes = 0;
    1284                 asn1_start_tag(data, tag);
    1285                 asn1_read_OctetString_talloc(msg, data, &r->dn);
    1286                 ldap_decode_attribs(msg, data, &r->attributes,
    1287                                     &r->num_attributes);
    1288                 asn1_end_tag(data);
     1305                if (!asn1_start_tag(data, tag)) goto prot_err;
     1306                if (!asn1_read_OctetString_talloc(msg, data, &r->dn)) goto prot_err;
     1307                if (!ldap_decode_attribs(msg, data, &r->attributes,
     1308                                    &r->num_attributes)) goto prot_err;
     1309                if (!asn1_end_tag(data)) goto prot_err;
    12891310                break;
    12901311        }
     
    12931314                struct ldap_Result *r = &msg->r.SearchResultDone;
    12941315                msg->type = LDAP_TAG_SearchResultDone;
    1295                 asn1_start_tag(data, tag);
    1296                 ldap_decode_response(msg, data, r);
    1297                 asn1_end_tag(data);
     1316                if (!asn1_start_tag(data, tag)) goto prot_err;
     1317                if (!ldap_decode_response(msg, data, r)) goto prot_err;
     1318                if (!asn1_end_tag(data)) goto prot_err;
    12981319                break;
    12991320        }
     
    13021323                struct ldap_SearchResRef *r = &msg->r.SearchResultReference;
    13031324                msg->type = LDAP_TAG_SearchResultReference;
    1304                 asn1_start_tag(data, tag);
    1305                 asn1_read_OctetString_talloc(msg, data, &r->referral);
    1306                 asn1_end_tag(data);
     1325                if (!asn1_start_tag(data, tag)) goto prot_err;
     1326                if (!asn1_read_OctetString_talloc(msg, data, &r->referral)) goto prot_err;
     1327                if (!asn1_end_tag(data)) goto prot_err;
    13071328                break;
    13081329        }
     
    13111332                struct ldap_ModifyRequest *r = &msg->r.ModifyRequest;
    13121333                msg->type = LDAP_TAG_ModifyRequest;
    1313                 asn1_start_tag(data, ASN1_APPLICATION(LDAP_TAG_ModifyRequest));
    1314                 asn1_read_OctetString_talloc(msg, data, &r->dn);
    1315                 asn1_start_tag(data, ASN1_SEQUENCE(0));
     1334                if (!asn1_start_tag(data, ASN1_APPLICATION(LDAP_TAG_ModifyRequest))) goto prot_err;
     1335                if (!asn1_read_OctetString_talloc(msg, data, &r->dn)) goto prot_err;
     1336                if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) goto prot_err;
    13161337
    13171338                r->num_mods = 0;
     
    13221343                        int v;
    13231344                        ZERO_STRUCT(mod);
    1324                         asn1_start_tag(data, ASN1_SEQUENCE(0));
    1325                         asn1_read_enumerated(data, &v);
     1345                        if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) goto prot_err;
     1346                        if (!asn1_read_enumerated(data, &v)) goto prot_err;
    13261347                        mod.type = v;
    1327                         ldap_decode_attrib(msg, data, &mod.attrib);
    1328                         asn1_end_tag(data);
     1348                        if (!ldap_decode_attrib(msg, data, &mod.attrib)) goto prot_err;
     1349                        if (!asn1_end_tag(data)) goto prot_err;
    13291350                        if (!add_mod_to_array_talloc(msg, &mod,
    13301351                                                     &r->mods, &r->num_mods)) {
     
    13331354                }
    13341355
    1335                 asn1_end_tag(data);
    1336                 asn1_end_tag(data);
     1356                if (!asn1_end_tag(data)) goto prot_err;
     1357                if (!asn1_end_tag(data)) goto prot_err;
    13371358                break;
    13381359        }
     
    13411362                struct ldap_Result *r = &msg->r.ModifyResponse;
    13421363                msg->type = LDAP_TAG_ModifyResponse;
    1343                 asn1_start_tag(data, tag);
    1344                 ldap_decode_response(msg, data, r);
    1345                 asn1_end_tag(data);
     1364                if (!asn1_start_tag(data, tag)) goto prot_err;
     1365                if (!ldap_decode_response(msg, data, r)) goto prot_err;
     1366                if (!asn1_end_tag(data)) goto prot_err;
    13461367                break;
    13471368        }
     
    13501371                struct ldap_AddRequest *r = &msg->r.AddRequest;
    13511372                msg->type = LDAP_TAG_AddRequest;
    1352                 asn1_start_tag(data, tag);
    1353                 asn1_read_OctetString_talloc(msg, data, &r->dn);
     1373                if (!asn1_start_tag(data, tag)) goto prot_err;
     1374                if (!asn1_read_OctetString_talloc(msg, data, &r->dn)) goto prot_err;
    13541375
    13551376                r->attributes = NULL;
    13561377                r->num_attributes = 0;
    1357                 ldap_decode_attribs(msg, data, &r->attributes,
    1358                                     &r->num_attributes);
    1359 
    1360                 asn1_end_tag(data);
     1378                if (!ldap_decode_attribs(msg, data, &r->attributes,
     1379                                    &r->num_attributes)) goto prot_err;
     1380
     1381                if (!asn1_end_tag(data)) goto prot_err;
    13611382                break;
    13621383        }
     
    13651386                struct ldap_Result *r = &msg->r.AddResponse;
    13661387                msg->type = LDAP_TAG_AddResponse;
    1367                 asn1_start_tag(data, tag);
    1368                 ldap_decode_response(msg, data, r);
    1369                 asn1_end_tag(data);
     1388                if (!asn1_start_tag(data, tag)) goto prot_err;
     1389                if (!ldap_decode_response(msg, data, r)) goto prot_err;
     1390                if (!asn1_end_tag(data)) goto prot_err;
    13701391                break;
    13711392        }
     
    13761397                char *dn;
    13771398                msg->type = LDAP_TAG_DelRequest;
    1378                 asn1_start_tag(data,
    1379                                ASN1_APPLICATION_SIMPLE(LDAP_TAG_DelRequest));
     1399                if (!asn1_start_tag(data,
     1400                               ASN1_APPLICATION_SIMPLE(LDAP_TAG_DelRequest))) goto prot_err;
    13801401                len = asn1_tag_remaining(data);
    13811402                if (len == -1) {
    1382                         return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
     1403                        goto prot_err;
    13831404                }
    13841405                dn = talloc_array(msg, char, len+1);
    13851406                if (dn == NULL)
    13861407                        break;
    1387                 asn1_read(data, dn, len);
     1408                if (!asn1_read(data, dn, len)) goto prot_err;
    13881409                dn[len] = '\0';
    13891410                r->dn = dn;
    1390                 asn1_end_tag(data);
     1411                if (!asn1_end_tag(data)) goto prot_err;
    13911412                break;
    13921413        }
     
    13951416                struct ldap_Result *r = &msg->r.DelResponse;
    13961417                msg->type = LDAP_TAG_DelResponse;
    1397                 asn1_start_tag(data, tag);
    1398                 ldap_decode_response(msg, data, r);
    1399                 asn1_end_tag(data);
     1418                if (!asn1_start_tag(data, tag)) goto prot_err;
     1419                if (!ldap_decode_response(msg, data, r)) goto prot_err;
     1420                if (!asn1_end_tag(data)) goto prot_err;
    14001421                break;
    14011422        }
     
    14041425                struct ldap_ModifyDNRequest *r = &msg->r.ModifyDNRequest;
    14051426                msg->type = LDAP_TAG_ModifyDNRequest;
    1406                 asn1_start_tag(data,
    1407                                ASN1_APPLICATION(LDAP_TAG_ModifyDNRequest));
    1408                 asn1_read_OctetString_talloc(msg, data, &r->dn);
    1409                 asn1_read_OctetString_talloc(msg, data, &r->newrdn);
    1410                 asn1_read_BOOLEAN(data, &r->deleteolddn);
     1427                if (!asn1_start_tag(data,
     1428                               ASN1_APPLICATION(LDAP_TAG_ModifyDNRequest))) goto prot_err;
     1429                if (!asn1_read_OctetString_talloc(msg, data, &r->dn)) goto prot_err;
     1430                if (!asn1_read_OctetString_talloc(msg, data, &r->newrdn)) goto prot_err;
     1431                if (!asn1_read_BOOLEAN(data, &r->deleteolddn)) goto prot_err;
    14111432                r->newsuperior = NULL;
    14121433                if (asn1_tag_remaining(data) > 0) {
    14131434                        int len;
    14141435                        char *newsup;
    1415                         asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(0));
     1436                        if (!asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(0))) goto prot_err;
    14161437                        len = asn1_tag_remaining(data);
    14171438                        if (len == -1) {
    1418                                 return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
     1439                                goto prot_err;
    14191440                        }
    14201441                        newsup = talloc_array(msg, char, len+1);
     
    14221443                                return NT_STATUS_LDAP(LDAP_OPERATIONS_ERROR);
    14231444                        }
    1424                         asn1_read(data, newsup, len);
     1445                        if (!asn1_read(data, newsup, len)) goto prot_err;
    14251446                        newsup[len] = '\0';
    14261447                        r->newsuperior = newsup;
    1427                         asn1_end_tag(data);
    1428                 }
    1429                 asn1_end_tag(data);
     1448                        if (!asn1_end_tag(data)) goto prot_err;
     1449                }
     1450                if (!asn1_end_tag(data)) goto prot_err;
    14301451                break;
    14311452        }
     
    14341455                struct ldap_Result *r = &msg->r.ModifyDNResponse;
    14351456                msg->type = LDAP_TAG_ModifyDNResponse;
    1436                 asn1_start_tag(data, tag);
    1437                 ldap_decode_response(msg, data, r);
    1438                 asn1_end_tag(data);
     1457                if (!asn1_start_tag(data, tag)) goto prot_err;
     1458                if (!ldap_decode_response(msg, data, r)) goto prot_err;
     1459                if (!asn1_end_tag(data)) goto prot_err;
    14391460                break;
    14401461        }
     
    14431464                struct ldap_CompareRequest *r = &msg->r.CompareRequest;
    14441465                msg->type = LDAP_TAG_CompareRequest;
    1445                 asn1_start_tag(data,
    1446                                ASN1_APPLICATION(LDAP_TAG_CompareRequest));
    1447                 asn1_read_OctetString_talloc(msg, data, &r->dn);
    1448                 asn1_start_tag(data, ASN1_SEQUENCE(0));
    1449                 asn1_read_OctetString_talloc(msg, data, &r->attribute);
    1450                 asn1_read_OctetString(data, msg, &r->value);
     1466                if (!asn1_start_tag(data,
     1467                               ASN1_APPLICATION(LDAP_TAG_CompareRequest))) goto prot_err;
     1468                if (!asn1_read_OctetString_talloc(msg, data, &r->dn)) goto prot_err;
     1469                if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) goto prot_err;
     1470                if (!asn1_read_OctetString_talloc(msg, data, &r->attribute)) goto prot_err;
     1471                if (!asn1_read_OctetString(data, msg, &r->value)) goto prot_err;
    14511472                if (r->value.data) {
    14521473                        talloc_steal(msg, r->value.data);
    14531474                }
    1454                 asn1_end_tag(data);
    1455                 asn1_end_tag(data);
     1475                if (!asn1_end_tag(data)) goto prot_err;
     1476                if (!asn1_end_tag(data)) goto prot_err;
    14561477                break;
    14571478        }
     
    14601481                struct ldap_Result *r = &msg->r.CompareResponse;
    14611482                msg->type = LDAP_TAG_CompareResponse;
    1462                 asn1_start_tag(data, tag);
    1463                 ldap_decode_response(msg, data, r);
    1464                 asn1_end_tag(data);
     1483                if (!asn1_start_tag(data, tag)) goto prot_err;
     1484                if (!ldap_decode_response(msg, data, r)) goto prot_err;
     1485                if (!asn1_end_tag(data)) goto prot_err;
    14651486                break;
    14661487        }
     
    14691490                struct ldap_AbandonRequest *r = &msg->r.AbandonRequest;
    14701491                msg->type = LDAP_TAG_AbandonRequest;
    1471                 asn1_start_tag(data, tag);
    1472                 asn1_read_implicit_Integer(data, &r->messageid);
    1473                 asn1_end_tag(data);
     1492                if (!asn1_start_tag(data, tag)) goto prot_err;
     1493                if (!asn1_read_implicit_Integer(data, &r->messageid)) goto prot_err;
     1494                if (!asn1_end_tag(data)) goto prot_err;
    14741495                break;
    14751496        }
     
    14801501
    14811502                msg->type = LDAP_TAG_ExtendedRequest;
    1482                 asn1_start_tag(data,tag);
     1503                if (!asn1_start_tag(data,tag)) goto prot_err;
    14831504                if (!asn1_read_ContextSimple(data, 0, &tmp_blob)) {
    1484                         return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
     1505                        goto prot_err;
    14851506                }
    14861507                r->oid = blob2string_talloc(msg, tmp_blob);
     
    14911512
    14921513                if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(1))) {
    1493                         asn1_read_ContextSimple(data, 1, &tmp_blob);
     1514                        if (!asn1_read_ContextSimple(data, 1, &tmp_blob)) goto prot_err;
    14941515                        r->value = talloc(msg, DATA_BLOB);
    14951516                        if (!r->value) {
     
    15021523                }
    15031524
    1504                 asn1_end_tag(data);
     1525                if (!asn1_end_tag(data)) goto prot_err;
    15051526                break;
    15061527        }
     
    15111532
    15121533                msg->type = LDAP_TAG_ExtendedResponse;
    1513                 asn1_start_tag(data, tag);             
    1514                 ldap_decode_response(msg, data, &r->response);
     1534                if (!asn1_start_tag(data, tag)) goto prot_err;
     1535                if (!ldap_decode_response(msg, data, &r->response)) goto prot_err;
    15151536
    15161537                if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(10))) {
    1517                         asn1_read_ContextSimple(data, 1, &tmp_blob);
     1538                        if (!asn1_read_ContextSimple(data, 1, &tmp_blob)) goto prot_err;
    15181539                        r->oid = blob2string_talloc(msg, tmp_blob);
    15191540                        data_blob_free(&tmp_blob);
     
    15261547
    15271548                if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(11))) {
    1528                         asn1_read_ContextSimple(data, 1, &tmp_blob);
     1549                        if (!asn1_read_ContextSimple(data, 1, &tmp_blob)) goto prot_err;
    15291550                        r->value = talloc(msg, DATA_BLOB);
    15301551                        if (!r->value) {
     
    15371558                }
    15381559
    1539                 asn1_end_tag(data);
    1540                 break;
    1541         }
    1542         default: 
    1543                 return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
     1560                if (!asn1_end_tag(data)) goto prot_err;
     1561                break;
     1562        }
     1563        default:
     1564                goto prot_err;
    15441565        }
    15451566
     
    15521573                bool *decoded = NULL;
    15531574
    1554                 asn1_start_tag(data, ASN1_CONTEXT(0));
     1575                if (!asn1_start_tag(data, ASN1_CONTEXT(0))) goto prot_err;
    15551576
    15561577                while (asn1_peek_tag(data, ASN1_SEQUENCE(0))) {
     
    15731594                        }
    15741595
    1575                         if (!ldap_decode_control_wrapper(ctrl, data, ctrl[i], &value)) {
    1576                                 return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
    1577                         }
    1578                        
    1579                         if (!ldap_decode_control_value(ctrl, value,
     1596                        if (!ldap_decode_control_wrapper(ctrl[i], data, ctrl[i], &value)) {
     1597                                goto prot_err;
     1598                        }
     1599
     1600                        if (!ldap_decode_control_value(ctrl[i], value,
    15801601                                                       control_handlers,
    15811602                                                       ctrl[i])) {
     
    16011622                msg->controls_decoded = decoded;
    16021623
    1603                 asn1_end_tag(data);
    1604         }
    1605 
    1606         asn1_end_tag(data);
    1607         if ((data->has_error) || (data->nesting != NULL)) {
     1624                if (!asn1_end_tag(data)) goto prot_err;
     1625        }
     1626
     1627        if (!asn1_end_tag(data)) goto prot_err;
     1628        if (asn1_has_error(data) || asn1_has_nesting(data)) {
    16081629                return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
    16091630        }
    16101631        return NT_STATUS_OK;
     1632
     1633  prot_err:
     1634
     1635        return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
    16111636}
    16121637
     
    16181643NTSTATUS ldap_full_packet(void *private_data, DATA_BLOB blob, size_t *packet_size)
    16191644{
     1645        int ret;
     1646
    16201647        if (blob.length < 6) {
    16211648                /*
     
    16251652                return STATUS_MORE_ENTRIES;
    16261653        }
    1627         return asn1_peek_full_tag(blob, ASN1_SEQUENCE(0), packet_size);
    1628 }
     1654
     1655        ret = asn1_peek_full_tag(blob, ASN1_SEQUENCE(0), packet_size);
     1656        if (ret != 0) {
     1657                return map_nt_error_from_unix_common(ret);
     1658        }
     1659        return NT_STATUS_OK;
     1660}
  • vendor/current/libcli/ldap/ldap_message.h

    r740 r988  
    2323
    2424#include "../libcli/ldap/ldap_errors.h"
    25 #if _SAMBA_BUILD_ == 3
    26 #include "lib/ldb_compat.h"
    27 #else
    2825#include <ldb.h>
    29 #endif
    3026
    3127enum ldap_request_tag {
     
    109105        bool attributesonly;
    110106        struct ldb_parse_tree *tree;
    111         int num_attributes;
     107        size_t num_attributes;
    112108        const char * const *attributes;
    113109};
     
    233229                                  const char **result);
    234230
    235 void ldap_decode_attribs_bare(TALLOC_CTX *mem_ctx, struct asn1_data *data,
     231bool ldap_decode_attribs_bare(TALLOC_CTX *mem_ctx, struct asn1_data *data,
    236232                              struct ldb_message_element **attributes,
    237233                              int *num_attributes);
  • vendor/current/libcli/ldap/ldap_ndr.c

    r740 r988  
    2222
    2323#include "includes.h"
    24 #if _SAMBA_BUILD_ == 3
    25 #include "lib/ldb_compat.h"
    26 #else
    2724#include <ldb.h>
    28 #endif
    2925#include "librpc/gen_ndr/ndr_security.h"
    3026#include "librpc/gen_ndr/ndr_misc.h"
  • vendor/current/libcli/ldap/wscript_build

    r740 r988  
    11#!/usr/bin/env python
    22
    3 bld.SAMBA_SUBSYSTEM('LIBCLI_LDAP_MESSAGE',
    4         source='ldap_message.c',
    5         public_deps='errors talloc ldb',
    6         public_headers='ldap_message.h ldap_errors.h',
    7         deps='samba-util ASN1_UTIL'
    8         )
    9 
    10 
    11 bld.SAMBA_SUBSYSTEM('LIBCLI_LDAP_NDR',
    12         source='ldap_ndr.c',
    13         public_deps='errors talloc',
    14         public_headers='ldap_ndr.h',
    15         deps='samba-util ldb NDR_SECURITY tevent'
    16         )
    17 
     3bld.SAMBA_LIBRARY('cli-ldap-common',
     4                  source='ldap_message.c ldap_ndr.c',
     5                  public_deps='samba-errors talloc ldb',
     6                  private_headers='ldap_message.h ldap_errors.h ldap_ndr.h',
     7                  deps='samba-util asn1util NDR_SECURITY tevent',
     8                  private_library=True)
Note: See TracChangeset for help on using the changeset viewer.