Text   |  XML   |  ReML   |   Visible Warnings:

Null Test After Dereference  at packet-imf.c:582

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

dissect_imf

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-imf.c)expand/collapse
Show more  
 469  static void dissect_imf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 470  {
 471    proto_item  *item;
 472    proto_tree  *unknown_tree, *text_tree;
 473    char  *content_type_str = NULL;
 474    char  *parameters = NULL;
 475    int   hf_id;
 476    gint  start_offset = 0;
 477    gint  value_offset = 0;
 478    gint  unknown_offset = 0;
 479    gint  end_offset = 0;
 480    gint   max_length;
 481    guint8 *key;
 482    gboolean last_field = FALSE;
 483    gboolean dissected = FALSE;
 484    tvbuff_t *next_tvb;
 485    struct imf_field *f_info;
 486   
 487    if (check_col(pinfo->cinfo, COL_PROTOCOL))
 488      col_set_str(pinfo->cinfo, COL_PROTOCOL, PSNAME);
 489    if (check_col(pinfo->cinfo, COL_INFO))
 490      col_clear(pinfo->cinfo, COL_INFO);
 491   
 492    if(tree){
 493      item = proto_tree_add_item(tree, proto_imf, tvb, 0, -1, FALSE);
 494      tree = proto_item_add_subtree(item, ett_imf);
 495    }
 496   
 497    max_length = tvb_length(tvb);
 498    /* first go through the tvb until we find a blank line and extract the content type if 
 499       we find one */
 500   
 501    while(!last_field) {
 502   
 503      /* look for a colon first */
 504      end_offset = tvb_find_guint8(tvb, start_offset, max_length - start_offset, ':');
 505   
 506      if(end_offset == -1) {
 507        /* we couldn't find another colon - strange - we should have broken out of here by now */
 508        /* XXX: flag an error */
 509        break;
 510      } else {
 511        guint8 *p;
 512   
 513        key = tvb_get_ephemeral_string(tvb, start_offset, end_offset - start_offset);
 514   
 515        /* convert to lower case */
 516   
 517        for(p=key; *p; p++)
 518          if(isupper(*p))
 519            *p = tolower(*p);
 520   
 521        /* look up the key */
 522        f_info = (struct imf_field *)g_hash_table_lookup(imf_field_table, key);
 523   
 524        if(f_info == (struct imf_field *)NULL) {
 525          /* set as an unknown extension */
 526          f_info = imf_fields;
 527          unknown_offset = start_offset;
 528        }
 529   
 530        hf_id = *(f_info->hf_id);
 531   
 532        /* value starts immediately after the colon */
 533        start_offset = end_offset+1;
 534   
 535        end_offset = imf_find_field_end(tvb, start_offset, max_length, &last_field);
 536   
 537        if(end_offset != -1) {
 538   
 539          /* remove any leading whitespace */
 540   
 541          for(value_offset = start_offset; value_offset < end_offset; value_offset++)
 542            if(!isspace(tvb_get_guint8(tvb, value_offset))) {
 543              break;
 544            }
 545   
 546          if(value_offset == end_offset) {
 547            /* empty field - show whole value */
 548            value_offset = start_offset;
 549          }
 550   
 551          if(hf_id == hf_imf_extension_type) {
 552   
 553            /* remove 2 bytes to take off the final CRLF to make things a little prettier */
 554            item = proto_tree_add_item(tree, hf_imf_extension, tvb, unknown_offset, end_offset - unknown_offset - 2, FALSE);
 555   
 556            proto_item_append_text(item, " (Contact Wireshark developers if you want this supported.)");
 557   
 558            unknown_tree = proto_item_add_subtree(item, ett_imf_extension);
 559   
 560            item = proto_tree_add_item(unknown_tree, hf_imf_extension_type, tvb, unknown_offset, start_offset - 1 - unknown_offset, FALSE);
 561   
 562            /* remove 2 bytes to take off the final CRLF to make things a little prettier */
 563            item = proto_tree_add_item(unknown_tree, hf_imf_extension_value, tvb, start_offset, end_offset - start_offset - 2, FALSE);
 564   
 565          } else 
 566   
 567            /* remove 2 bytes to take off the final CRLF to make things a little prettier */
 568            item = proto_tree_add_item(tree, hf_id, tvb, value_offset, end_offset - value_offset - 2, FALSE);
 569   
 570          if(f_info->add_to_col_info && check_col(pinfo->cinfo, COL_INFO)) {
 571   
 572            col_append_fstr(pinfo->cinfo, COL_INFO, "%s: %s, ", f_info->name,
 573                            tvb_format_text(tvb, value_offset, end_offset - value_offset - 2));
 574          }
 575   
 576          if(hf_id == hf_imf_content_type) {
 577            /* we need some additional processing to extract the content type and parameters */
 578   
 579            dissect_imf_content_type(tvb, start_offset, end_offset - start_offset, item,
 580                                     &content_type_str, &parameters);
 581   
 582          } else if(f_info && f_info->subdissector) {
 583   
 584            /* we have a subdissector */
 585            f_info->subdissector(tvb, value_offset, end_offset - value_offset, item);
 586   
 587          }
 588        }
 589      }
 590      start_offset = end_offset;
 591    }
 592   
 593    /* specify a content type until we can work it out for ourselves */
 594    /* content_type_str = "multipart/mixed"; */
 595   
 596    /* now dissect the MIME based upon the content type */
 597   
 598    if(content_type_str && media_type_dissector_table) {
 599      void* pd_save;
 600      pd_save = pinfo->private_data;
 601      pinfo->private_data = parameters;  
 602   
 603      next_tvb = tvb_new_subset(tvb, end_offset, -1, -1);
 604   
 605      dissected = dissector_try_string(media_type_dissector_table, content_type_str, next_tvb, pinfo, tree);
 606   
 607      pinfo->private_data = pd_save;
 608    } else {
 609   
 610      /* just show the lines or highlight the rest of the buffer as message text */
 611   
 612      item = proto_tree_add_item(tree, hf_imf_message_text, tvb, start_offset, -1 , FALSE);
 613      text_tree = proto_item_add_subtree(item, ett_imf_message_text);
 614   
 615      start_offset = end_offset;
 616      while (tvb_offset_exists(tvb, start_offset)) {
 617   
 618        /*
 619         * Find the end of the line.
 620         */
 621        tvb_find_line_end(tvb, start_offset, -1, &end_offset, FALSE);
 622   
 623        /*
 624         * Put this line.
 625         */
 626        proto_tree_add_text(text_tree, tvb, start_offset, end_offset - start_offset,
 627                            "%s",
 628                            tvb_format_text(tvb, start_offset, end_offset - start_offset - 2));
 629   
 630        /*
 631         * Step to the next line.
 632         */
 633        start_offset = end_offset;
 634      }
 635    }
 636  }
Show more  




Change Warning 2673.33419 : Null Test After Dereference

Priority:
State:
Finding:
Owner:
Note: