Text   |  XML   |  ReML   |   Visible Warnings:

Null Test After Dereference  at packet-dtls.c:809

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

dissect_dtls_record

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-dtls.c)expand/collapse
Show more  
 541  dissect_dtls_record(tvbuff_t *tvb, packet_info *pinfo,
 542                      proto_tree *tree, guint32 offset,
 543                      guint *conv_version,
 544                      SslDecryptSession* ssl)
 545  {
 546   
 547    /*
 548     *    struct {
 549     *        uint8 major, minor;
 550     *    } ProtocolVersion;
 551     *
 552     *
 553     *    enum {
 554     *        change_cipher_spec(20), alert(21), handshake(22),
 555
568
Show [ Lines 555 to 568 omitted. ]
 569    guint16 epoch;
 570    gdouble sequence_number;
 571    gint64 sequence_number_temp;
 572    guint8 content_type;
 573    guint8 next_byte;
 574    proto_tree *ti;
 575    proto_tree *dtls_record_tree;
 576    guint32 available_bytes;
 577    SslAssociation* association;
 578    SslDataInfo *appl_data;
 579    ti              = NULL;
 580    dtls_record_tree = NULL;
 581    available_bytes = tvb_length_remaining(tvb, offset);
 582   
 583    /*
 584     * Get the record layer fields of interest 
 585     */
 586    content_type  = tvb_get_guint8(tvb, offset);
 587    version       = tvb_get_ntohs(tvb, offset + 1);
 588    epoch       = tvb_get_ntohs(tvb, offset + 3);
 589    sequence_number  = tvb_get_ntohl(tvb, offset + 7);
 590    sequence_number_temp=tvb_get_ntohs(tvb, offset + 5);
 591    sequence_number_temp=sequence_number_temp<<32;
 592    sequence_number+=sequence_number_temp;
 593    record_length = tvb_get_ntohs(tvb, offset + 11);
 594   
 595    if(ssl){
 596      if(ssl_packet_from_server(dtls_associations, pinfo->srcport, pinfo->ptype == PT_TCP)){
 597       if (ssl->server) {
 598        ssl->server->seq=(guint32)sequence_number;
 599        ssl->server->epoch=epoch;
 600       }
 601      }
 602      else{
 603       if (ssl->client) {
 604        ssl->client->seq=(guint32)sequence_number;
 605        ssl->client->epoch=epoch;
 606       }
 607      }
 608    }
 609    if (!ssl_is_valid_content_type(content_type)) {
 610   
 611      /* if we don't have a valid content_type, there's no sense
 612       * continuing any further 
 613       */
 614      if (check_col(pinfo->cinfo, COL_INFO))
 615        col_append_str(pinfo->cinfo, COL_INFO, "Continuation Data");
 616   
 617      /* Set the protocol column */
 618      if (check_col(pinfo->cinfo, COL_PROTOCOL))
 619        {
 620          col_set_str(pinfo->cinfo, COL_PROTOCOL,"DTLS");
 621        }
 622      return offset + 13 + record_length;
 623    }
 624   
 625    /*
 626     * If GUI, fill in record layer part of tree 
 627     */
 628   
 629    if (tree)
 630      {
 631        /* add the record layer subtree header */
 632        tvb_ensure_bytes_exist(tvb, offset, 13 + record_length);
 633        ti = proto_tree_add_item(tree, hf_dtls_record, tvb,
 634                                 offset, 13 + record_length, 0);
 635        dtls_record_tree = proto_item_add_subtree(ti, ett_dtls_record);
 636      }
 637   
 638    if (dtls_record_tree)
 639      {
 640   
 641        /* show the one-byte content type */
 642        proto_tree_add_item(dtls_record_tree, hf_dtls_record_content_type,
 643                            tvb, offset, 1, FALSE);
 644        offset++;
 645   
 646        /* add the version */
 647        proto_tree_add_item(dtls_record_tree, hf_dtls_record_version, tvb,
 648                            offset, 2, FALSE);
 649        offset += 2;
 650   
 651        /* show epoch */
 652        proto_tree_add_uint(dtls_record_tree, hf_dtls_record_epoch, tvb, offset, 2, epoch);
 653   
 654        offset += 2;
 655   
 656        /* add sequence_number */
 657   
 658        proto_tree_add_double(dtls_record_tree, hf_dtls_record_sequence_number, tvb, offset, 6, sequence_number);
 659   
 660        offset += 6;
 661   
 662        /* add the length */
 663        proto_tree_add_uint(dtls_record_tree, hf_dtls_record_length, tvb,
 664                            offset, 2, record_length);
 665        offset += 2;    /* move past length field itself */
 666   
 667      }
 668    else 
 669      {
 670        /* if no GUI tree, then just skip over those fields */
 671        offset += 13;
 672      }
 673   
 674   
 675    /*
 676     * if we don't already have a version set for this conversation,
 677     * but this message's version is authoritative (i.e., it's
 678     * not client_hello, then save the version to to conversation 
 679     * structure and print the column version
 680     */
 681    next_byte = tvb_get_guint8(tvb, offset);
 682    if (*conv_version == SSL_VER_UNKNOWN 
 683        && dtls_is_authoritative_version_message(content_type, next_byte))
 684      {
 685        if (version == DTLSV1DOT0_VERSION ||
 686            version == DTLSV1DOT0_VERSION_NOT)
 687          {
 688   
 689            *conv_version = SSL_VER_DTLS;
 690            if (ssl) {
 691              ssl->version_netorder = version;
 692              ssl->state |= SSL_VERSION;
 693            }
 694            /*ssl_set_conv_version(pinfo, ssl->version);*/
 695          }
 696      }
 697    if (check_col(pinfo->cinfo, COL_PROTOCOL))
 698      {
 699        if (version == DTLSV1DOT0_VERSION)
 700          {
 701            col_set_str(pinfo->cinfo, COL_PROTOCOL,
 702                        ssl_version_short_names[SSL_VER_DTLS]);
 703          }
 704        else 
 705          {
 706            col_set_str(pinfo->cinfo, COL_PROTOCOL,"DTLS");
 707          }
 708      }
 709   
 710    /*
 711     * now dissect the next layer 
 712     */
 713    ssl_debug_printf("dissect_dtls_record: content_type %d\n",content_type);
 714   
 715    /* PAOLO try to decrypt each record (we must keep ciphers "in sync")
 716     * store plain text only for app data */
 717   
 718    switch (content_type) {
 719    case SSL_ID_CHG_CIPHER_SPEC:
 720      if (check_col(pinfo->cinfo, COL_INFO))
 721        col_append_str(pinfo->cinfo, COL_INFO, "Change Cipher Spec");
 722      dissect_dtls_change_cipher_spec(tvb, dtls_record_tree,
 723                                      offset, conv_version, content_type);
 724      break;
 725    case SSL_ID_ALERT:
 726      {
 727        tvbuff_t* decrypted;
 728        decrypted = 0;
 729        if (ssl&&decrypt_dtls_record(tvb, pinfo, offset,
 730                                     record_length, content_type, ssl, FALSE))
 731          ssl_add_record_info(proto_dtls, pinfo, dtls_decrypted_data.data,
 732                              dtls_decrypted_data_avail, offset);
 733   
 734        /* try to retrive and use decrypted alert record, if any. */
 735        decrypted = ssl_get_record_info(proto_dtls, pinfo, offset);
 736        if (decrypted)
 737          dissect_dtls_alert(decrypted, pinfo, dtls_record_tree, 0,
 738                             conv_version);
 739        else 
 740          dissect_dtls_alert(tvb, pinfo, dtls_record_tree, offset,
 741                             conv_version);
 742        break;
 743      }
 744    case SSL_ID_HANDSHAKE:
 745      {
 746        tvbuff_t* decrypted;
 747        decrypted = 0;
 748        /* try to decrypt handshake record, if possible. Store decrypted
 749         * record for later usage. The offset is used as 'key' to itentify
 750         * this record into the packet (we can have multiple handshake records 
 751         * in the same frame) */
 752        if (ssl && decrypt_dtls_record(tvb, pinfo, offset,
 753                                       record_length, content_type, ssl, FALSE))
 754          ssl_add_record_info(proto_dtls, pinfo, dtls_decrypted_data.data,
 755                              dtls_decrypted_data_avail, offset);
 756   
 757        /* try to retrive and use decrypted handshake record, if any. */
 758        decrypted = ssl_get_record_info(proto_dtls, pinfo, offset);
 759        if (decrypted)
 760          dissect_dtls_handshake(decrypted, pinfo, dtls_record_tree, 0,
 761                                 decrypted->length, conv_version, ssl, content_type);
 762        else 
 763          dissect_dtls_handshake(tvb, pinfo, dtls_record_tree, offset,
 764                                 record_length, conv_version, ssl, content_type);
 765        break;
 766      }
 767    case SSL_ID_APP_DATA:
 768      if (ssl)
 769        decrypt_dtls_record(tvb, pinfo, offset,
 770                            record_length, content_type, ssl, TRUE);
 771   
 772      /* show on info colum what we are decoding */
 773      if (check_col(pinfo->cinfo, COL_INFO))
 774        col_append_str(pinfo->cinfo, COL_INFO, "Application Data");
 775   
 776      if (!dtls_record_tree)
 777        break;
 778   
 779      /* we need dissector information when the selected packet is shown.
 780       * ssl session pointer is NULL at that time, so we can't access 
 781       * info cached there*/
 782      association = ssl_association_find(dtls_associations, pinfo->srcport, pinfo->ptype == PT_TCP);
 783      association = association ? association: ssl_association_find(dtls_associations, pinfo->destport, pinfo->ptype == PT_TCP);
 784   
 785      proto_item_set_text(dtls_record_tree,
 786                          "%s Record Layer: %s Protocol: %s",
 787                          ssl_version_short_names[*conv_version],
 788                          val_to_str(content_type, ssl_31_content_type, "unknown"),
 789                          association?association->info:"Application Data");
 790   
 791      proto_tree_add_item(dtls_record_tree, hf_dtls_record_appdata, tvb,
 792                          offset, record_length, 0);
 793   
 794      /* show decrypted data info, if available */
 795      appl_data = ssl_get_data_info(proto_dtls, pinfo, TVB_RAW_OFFSET(tvb)+offset);
 796      if (appl_data && (appl_data->plain_data.data_len > 0))
 797        {
 798                  tvbuff_t *next_tvb;
 799          /* try to dissect decrypted data*/
 800          ssl_debug_printf("dissect_dtls_record decrypted len %d\n",
 801                           appl_data->plain_data.data_len);
 802   
 803                  /* create a new TVB structure for desegmented data */
 804                  next_tvb = tvb_new_child_real_data(tvb, appl_data->plain_data.data, appl_data->plain_data.data_len, appl_data->plain_data.data_len);
 805   
 806          add_new_data_source(pinfo, next_tvb, "Decrypted DTLS data");
 807   
 808          /* find out a dissector using server port*/
 809          if (association && association->handle) {
 810            ssl_debug_printf("dissect_dtls_record found association %p\n", (void *)association);
 811            ssl_print_text_data("decrypted app data",appl_data->plain_data.data, appl_data->plain_data.data_len);
 812   
 813            call_dissector(association->handle, next_tvb, pinfo, top_tree);
 814          }
 815        }
 816      break;
 817   
 818    default:
 819      /* shouldn't get here since we check above for valid types */
 820      if (check_col(pinfo->cinfo, COL_INFO))
 821        col_append_str(pinfo->cinfo, COL_INFO, "Bad DTLS Content Type");
 822      break;
 823    }
 824    offset += record_length; /* skip to end of record */
 825   
 826    return offset;
 827  }
Show more  




Change Warning 12446.35222 : Null Test After Dereference

Priority:
State:
Finding:
Owner:
Note: