Text   |  XML   |  ReML   |   Visible Warnings:

Cast Alters Value  at packet-ldap.c:3535

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

dissect_ldap_pdu

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-ldap.c)expand/collapse
Show more  
 3347  dissect_ldap_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean is_mscldap)
 3348  {
 3349    int offset = 0;
 3350    conversation_t *conversation;
 3351    gboolean doing_sasl_security = FALSE;
 3352    guint length_remaining;
 3353    ldap_conv_info_t *ldap_info = NULL;
 3354    proto_item *ldap_item = NULL;
 3355    proto_tree *ldap_tree = NULL;
 3356   
 3357    ldm_tree = NULL;
 3358   
 3359    /*
 3360     * Do we have a conversation for this connection?
 3361     */
 3362    conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
 3363                                     pinfo->ptype, pinfo->srcport,
 3364                                     pinfo->destport, 0);
 3365    if (conversation == NULL) {
 3366      /* We don't yet have a conversation, so create one. */
 3367      conversation = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst,
 3368                                      pinfo->ptype, pinfo->srcport,
 3369                                      pinfo->destport, 0);
 3370   
 3371    }
 3372   
 3373    /*
 3374     * Do we already have a type and mechanism?
 3375     */
 3376[+]   ldap_info = conversation_get_proto_data(conversation, proto_ldap);
 3377    if (ldap_info == NULL) {
 3378      /* No.  Attach that information to the conversation, and add
 3379       * it to the list of information structures.
 3380       */
 3381      ldap_info = g_malloc(sizeof(ldap_conv_info_t));
 3382      ldap_info->auth_type = 0;
 3383      ldap_info->auth_mech = 0;
 3384      ldap_info->first_auth_frame = 0;
 3385      ldap_info->matched=g_hash_table_new(ldap_info_hash_matched, ldap_info_equal_matched);
 3386      ldap_info->unmatched=g_hash_table_new(ldap_info_hash_unmatched, ldap_info_equal_unmatched);
 3387      ldap_info->num_results = 0;
 3388      ldap_info->start_tls_frame = 0;
 3389      ldap_info->start_tls_pending = FALSE;
 3390   
 3391      conversation_add_proto_data(conversation, proto_ldap, ldap_info);
 3392   
 3393      ldap_info->next = ldap_info_items;
 3394      ldap_info_items = ldap_info;
 3395   
 3396    }
 3397     
 3398    switch (ldap_info->auth_type) {
 3399      case LDAP_AUTH_SASL:
 3400      /*
 3401       * It's SASL; are we using a security layer?
 3402       */
 3403      if (ldap_info->first_auth_frame != 0 &&
 3404         pinfo->fd->num >= ldap_info->first_auth_frame) {
 3405          doing_sasl_security = TRUE;     /* yes */
 3406      }
 3407    }
 3408   
 3409[+]     length_remaining = tvb_ensure_length_remaining(tvb, offset);
 3410   
 3411      /* It might still be a packet containing a SASL security layer 
 3412       * but its just that we never saw the BIND packet.
 3413       * check if it looks like it could be a SASL blob here
 3414       * and in that case just assume it is GSS-SPNEGO
 3415       */
 3416      if(!doing_sasl_security && (tvb_bytes_exist(tvb, offset, 5))
 3417        &&(tvb_get_ntohl(tvb, offset)<=(guint)(tvb_reported_length_remaining(tvb, offset)-4))
 3418        &&(tvb_get_guint8(tvb, offset+4)==0x60) ){
 3419          ldap_info->auth_type=LDAP_AUTH_SASL;
 3420          ldap_info->first_auth_frame=pinfo->fd->num;
 3421          ldap_info->auth_mech=g_strdup("GSS-SPNEGO");
 3422          doing_sasl_security=TRUE;
 3423      }
 3424   
 3425      /*
 3426       * This is the first PDU, set the Protocol column and clear the 
 3427       * Info column.
 3428       */
 3429      if (check_col(pinfo->cinfo, COL_PROTOCOL)) col_set_str(pinfo->cinfo, COL_PROTOCOL, pinfo->current_proto);
 3430   
 3431      if(last_frame_seen == pinfo->fd->num) {
 3432        /* we have already dissected an ldap PDU in this frame - add a separator and set a fence */
 3433[+]       if (check_col(pinfo->cinfo, COL_INFO)) {
 3434          col_append_str(pinfo->cinfo, COL_INFO, "| ");
 3435          col_set_fence(pinfo->cinfo, COL_INFO);
 3436        }
 3437      } else 
 3438        if (check_col(pinfo->cinfo, COL_INFO)) col_clear(pinfo->cinfo, COL_INFO);
 3439   
 3440      last_frame_seen = pinfo->fd->num;
 3441   
 3442      ldap_item = proto_tree_add_item(tree, is_mscldap?proto_cldap:proto_ldap, tvb, 0, -1, FALSE);
 3443[+]     ldap_tree = proto_item_add_subtree(ldap_item, ett_ldap);
 3444   
 3445      /*
 3446       * Might we be doing a SASL security layer and, if so, *are* we doing
 3447       * one?
 3448       *
 3449       * Just because we've seen a bind reply for SASL, that doesn't mean 
 3450       * that we're using a SASL security layer; I've seen captures in 
 3451       * which some SASL negotiations lead to a security layer being used 
 3452       * and other negotiations don't, and it's not obvious what's different 
 3453       * in the two negotiations.  Therefore, we assume that if the first
 3454       * byte is 0, it's a length for a SASL security layer (that way, we 
 3455       * never reassemble more than 16 megabytes, protecting us from 
 3456       * chewing up *too* much memory), and otherwise that it's an LDAP
 3457       * message (actually, if it's an LDAP message it should begin with 0x30,
 3458       * but we want to parse garbage as LDAP messages rather than really
 3459       * huge lengths).
 3460       */
 3461   
 3462[+]     if (doing_sasl_security && tvb_get_guint8(tvb, offset) == 0) {
 3463        proto_item *sasl_item = NULL;
 3464        proto_tree *sasl_tree = NULL;
 3465        tvbuff_t *sasl_tvb;
 3466        guint sasl_len, sasl_msg_len, length;
 3467        /*
 3468         * Yes.  The frame begins with a 4-byte big-endian length.
 3469         * And we know we have at least 6 bytes 
 3470         */
 3471   
 3472        /*
 3473         * Get the SASL length, which is the length of data in the buffer 
 3474         * following the length (i.e., it's 4 less than the total length).
 3475         *
 3476         * XXX - do we need to reassemble buffers?  For now, we 
 3477         * assume that each LDAP message is entirely contained within 
 3478         * a buffer.
 3479         */
 3480[+]       sasl_len = tvb_get_ntohl(tvb, offset);
 3481        sasl_msg_len = sasl_len + 4;
 3482        if (sasl_msg_len < 4) {
 3483          /*
 3484           * The message length was probably so large that the total length 
 3485           * overflowed.
 3486           *
 3487           * Report this as an error.
 3488           */
 3489          show_reported_bounds_error(tvb, pinfo, tree);
 3490          return;
 3491        }
 3492   
 3493        /*
 3494         * Construct a tvbuff containing the amount of the payload we have 
 3495         * available.  Make its reported length the amount of data in the PDU.
 3496         *
 3497         * XXX - if reassembly isn't enabled. the subdissector will throw a 
 3498         * BoundsError exception, rather than a ReportedBoundsError exception.
 3499         * We really want a tvbuff where the length is "length", the reported
 3500         * length is "plen", and the "if the snapshot length were infinite"
 3501         * length is the minimum of the reported length of the tvbuff handed
 3502         * to us and "plen", with a new type of exception thrown if the offset
 3503         * is within the reported length but beyond that third length, with 
 3504         * that exception getting the "Unreassembled Packet" error.
 3505         */
 3506        length = length_remaining;
 3507        if (length > sasl_msg_len) length = sasl_msg_len;
 3508        sasl_tvb = tvb_new_subset(tvb, offset, length, sasl_msg_len);
 3509   
 3510        if (ldap_tree) {
 3511          proto_tree_add_uint(ldap_tree, hf_ldap_sasl_buffer_length, sasl_tvb, 0, 4,
 3512                              sasl_len);
 3513   
 3514          sasl_item = proto_tree_add_text(ldap_tree, sasl_tvb, 0,  sasl_msg_len, "SASL Buffer");
 3515          sasl_tree = proto_item_add_subtree(sasl_item, ett_ldap_sasl_blob);
 3516        }
 3517   
 3518        if (ldap_info->auth_mech != NULL &&
 3519            ((strcmp(ldap_info->auth_mech, "GSS-SPNEGO") == 0) ||
 3520             /* auth_mech may have been set from the bind */
 3521             (strcmp(ldap_info->auth_mech, "GSSAPI") == 0))) {
 3522            tvbuff_t *gssapi_tvb, *plain_tvb = NULL, *decr_tvb= NULL;
 3523            int ver_len;
 3524            int length;
 3525   
 3526            /*
 3527             * This is GSS-API (using SPNEGO, but we should be done with
 3528             * the negotiation by now).
 3529             *
 3530             * Dissect the GSS_Wrap() token; it'll return the length of
 3531             * the token, from which we compute the offset in the tvbuff at
 3532             * which the plaintext data, i.e. the LDAP message, begins.
 3533             */
 3534[+]           length = tvb_length_remaining(sasl_tvb, 4);
 3535            if ((guint)length > sasl_len)
Show more  




Change Warning 1291.35221 : Cast Alters Value

Priority:
State:
Finding:
Owner:
Note: