(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-lldp.c) |
| |
| 515 | | | dissect_lldp_chassis_id(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 offset) |
| 516 | | | { |
| 517 | | | guint8 tempType; |
| 518 | | | guint16 tempShort; |
| 519 | | | guint32 tempLen = 0; |
| 520 | | | const char *strPtr=NULL; |
| 521 | | | guint8 incorrectLen = 0; |
| 522 | | | |
| 523 | | | const guint8 *mac_addr = NULL; |
| 524 | | | guint32 ip_addr; |
| 525 | | | struct e_in6_addr ip6_addr; |
| 526 | | | guint8 addr_family = 0; |
| 527 | | | |
| 528 | | | proto_tree *chassis_tree = NULL; |
| 529 | | | proto_item *tf = NULL; |
| 530 | | | |
| 531 | | | |
| 532 | | | tempShort = tvb_get_ntohs(tvb, offset); |
| 533 | | | tempType = TLV_TYPE(tempShort); |
| 534 | | | if (tempType != CHASSIS_ID_TLV_TYPE) |
| 535 | | | { |
| 536 | | | if (tree) |
| 537 | | | { |
| 538 | | | tf = proto_tree_add_text(tree, tvb, offset, 2, "Invalid Chassis ID (0x%02X)", tempType); |
| 539 | | | chassis_tree = proto_item_add_subtree(tf, ett_chassis_id); |
| 540 | | | proto_tree_add_text(chassis_tree, tvb, offset, 2, "%s Invalid Chassis ID (%u)", |
| 541 | | | decode_boolean_bitfield(tempType, TLV_TYPE_MASK, 16, "", ""), tempType); |
| 542 | | | } |
| 543 | | | |
| 544 | | | return -1; |
| 545 | | | } |
| 546 | | | |
| 547 | | | |
| 548 | | | tempLen = TLV_INFO_LEN(tempShort); |
| 549 | | | if (tempLen < 2) |
| 550 | | | { |
| 551 | | | if (tree) |
| 552 | | | { |
| 553 | | | tf = proto_tree_add_text(tree, tvb, offset, 2, "Invalid Chassis ID Length (%u)", tempLen); |
| 554 | | | chassis_tree = proto_item_add_subtree(tf, ett_chassis_id); |
| 555 | | | proto_tree_add_item(chassis_tree, hf_lldp_tlv_type, tvb, offset, 2, FALSE); |
| 556 | | | proto_tree_add_text(chassis_tree, tvb, offset, 2, "%s Invalid Length: %u", |
| 557 | | | decode_boolean_bitfield(tempLen, TLV_INFO_LEN_MASK, 16, "", ""), tempLen); |
| 558 | | | } |
| 559 | | | |
| 560 | | | return -1; |
| 561 | | | } |
| 562 | | | |
| 563 | | | |
| 564 | | | tempType = tvb_get_guint8(tvb, (offset+2)); |
| 565 | | | |
| 566 | | | switch (tempType) |
| 567 | | | { |
| 568 | | | case 4: |
| 569 | | | { |
| 570 | | | if (tempLen != 7) |
| 571 | | | { |
| 572 | | | incorrectLen = 1; |
| 573 | | | break; |
| 574 | | | } |
| 575 | | | |
| 576 | | | mac_addr=tvb_get_ptr(tvb, (offset+3), 6); |
| 577 | | | strPtr = ether_to_str(mac_addr); |
| 578 | | | |
| 579 | | | break; |
| 580 | | | } |
| 581 | | | case 5: |
| 582 | | | { |
| 583 | | | |
| 584 | | | addr_family = tvb_get_guint8(tvb,offset+3); |
| 585 | | | |
| 586 | | | switch(addr_family){ |
| 587 | | | case AFNUM_INET: |
| 588 | | | if (tempLen == 6){ |
| 589 | | | ip_addr = tvb_get_ipv4(tvb, (offset+4)); |
| 590 | | | strPtr = ip_to_str((guint8 *)&ip_addr); |
Ignored Return Value
The return value of ip_to_str() is never checked in the highlighted execution scenario. - If the return value can indicate an error, the error will be ignored if the highlighted code executes.
- The return value of ip_to_str() is checked 99% of the time in this project. CodeSonar is configured to enforce Ignored Return Value checks for any function whose return value is checked at least 96% of the time, unless the function is used fewer than 20 times. (To modify these thresholds, use configuration file parameters RETURN_CHECKER_SAMPLE_SIZE and RETURN_CHECKER_RATIO. To exempt ip_to_str() from the Ignored Return Value check, use configuration file parameter RETURN_CHECKER_IGNORED_FUNCS).
Show: All events | Only primary events |
|
| 591 | | | }else{ |
| 592 | | | incorrectLen = 1; |
| 593 | | | } |
| 594 | | | break; |
| 595 | | | case AFNUM_INET6: |
| 596 | | | if (tempLen == 18){ |
| 597 | | | tvb_get_ipv6(tvb, (offset+4), &ip6_addr); |
| 598 | | | strPtr = ip6_to_str(&ip6_addr); |
| 599 | | | }else{ |
| 600 | | | incorrectLen = 1; |
| 601 | | | } |
| 602 | | | break; |
| 603 | | | default: |
| 604 | | | strPtr = tvb_bytes_to_str(tvb, (offset+4), (tempLen-2)); |
| 605 | | | break; |
| 606 | | | } |
| 607 | | | break; |
| 608 | | | } |
| 609 | | | case 2: |
| 610 | | | case 6: |
| 611 | | | case 7: |
| 612 | | | { |
| 613 | | | if (tempLen > 256) |
| 614 | | | { |
| 615 | | | incorrectLen = 1; |
| 616 | | | break; |
| 617 | | | } |
| 618 | | | |
| 619 | | | strPtr = tvb_format_stringzpad(tvb, (offset+3), (tempLen-1)); |
| 620 | | | |
| 621 | | | break; |
| 622 | | | } |
| 623 | | | case 1: |
| 624 | | | case 3: |
| 625 | | | { |
| 626 | | | if (tempLen > 256) |
| 627 | | | { |
| 628 | | | incorrectLen = 1; |
| 629 | | | break; |
| 630 | | | } |
| 631 | | | |
| 632 | | | strPtr = tvb_bytes_to_str(tvb, (offset+3), (tempLen-1)); |
| 633 | | | break; |
| 634 | | | } |
| 635 | | | default: |
| 636 | | | { |
| 637 | | | if (tempLen > 256) |
| 638 | | | { |
| 639 | | | incorrectLen = 1; |
| 640 | | | break; |
| 641 | | | } |
| 642 | | | |
| 643 | | | strPtr = "Reserved"; |
| 644 | | | |
| 645 | | | break; |
| 646 | | | } |
| 647 | | | } |
| 648 | | | |
| 649 | | | if (incorrectLen == 1) |
Event 2:
Skipping " if". incorrectLen == 1 evaluates to false.
hide
|
|
| 650 | | | { |
| 651 | | | if (tree) |
| 652 | | | { |
| 653 | | | tf = proto_tree_add_text(tree, tvb, offset, 2, "Invalid Chassis ID Length (%u)", tempLen); |
| 654 | | | chassis_tree = proto_item_add_subtree(tf, ett_chassis_id); |
| 655 | | | proto_tree_add_item(chassis_tree, hf_lldp_tlv_type, tvb, offset, 2, FALSE); |
| 656 | | | proto_tree_add_text(chassis_tree, tvb, offset, 2, "%s Invalid Length: %u", |
| 657 | | | decode_boolean_bitfield(tempLen, TLV_INFO_LEN_MASK, 16, "", ""), tempLen); |
| 658 | | | |
| 659 | | | proto_tree_add_item(chassis_tree, hf_chassis_id_subtype, tvb, (offset+2), 1, FALSE); |
| 660 | | | |
| 661 | | | } |
| 662 | | | |
| 663 | | | return -1; |
| 664 | | | } |
| 665 | | | |
| 666 | | | if (check_col(pinfo->cinfo, COL_INFO)) |
Event 3:
Skipping " if". check_col(...) evaluates to false.
hide
|
|
| 667 | | | col_add_fstr(pinfo->cinfo, COL_INFO, "Chassis Id = %s ", strPtr); |
| 668 | | | |
| 669 | | | if (tree) |
Event 4:
Taking true branch. tree evaluates to true.
hide
|
|
| 670 | | | { |
| 671 | | | |
| 672 | | | tf = proto_tree_add_text(tree, tvb, offset, (tempLen + 2), "Chassis Subtype = %s", |
| 673 | | | val_to_str(tempType, chassis_id_subtypes, "Reserved" )); |
| 674 | | | chassis_tree = proto_item_add_subtree(tf, ett_chassis_id); |
| 675 | | | |
| 676 | | | proto_tree_add_item(chassis_tree, hf_lldp_tlv_type, tvb, offset, 2, FALSE); |
| 677 | | | proto_tree_add_item(chassis_tree, hf_lldp_tlv_len, tvb, offset, 2, FALSE); |
| 678 | | | |
| 679 | | | |
| 680 | | | proto_tree_add_item(chassis_tree, hf_chassis_id_subtype, tvb, (offset+2), 1, FALSE); |
| 681 | | | |
| 682 | | | |
| 683 | | | switch (tempType) |
Event 5:
tempType evaluates to 5.
hide
|
|
| 684 | | | { |
| 685 | | | case 4: |
| 686 | | | proto_tree_add_ether(chassis_tree, hf_chassis_id_mac, tvb, (offset+3), 6, mac_addr); |
| 687 | | | proto_item_append_text(tf, ", Id: %s", strPtr); |
| 688 | | | break; |
| 689 | | | case 5: |
| 690 | | | proto_tree_add_item(chassis_tree, hf_lldp_network_address_family, tvb, offset+3, 1, FALSE); |
| 691 | | | switch(addr_family){ |
Event 6:
addr_family evaluates to 1.
hide
|
|
| 692 | | | case AFNUM_INET: |
| 693 | | | proto_tree_add_ipv4(chassis_tree, hf_chassis_id_ip4, tvb, (offset+4), 4, ip_addr); |
| 694 | | | break; |
| 695 | | | case AFNUM_INET6: |
| 696 | | | proto_tree_add_ipv6(chassis_tree, hf_chassis_id_ip6, tvb, (offset+4), 16, ip6_addr.bytes); |
| 697 | | | break; |
| 698 | | | default: |
| 699 | | | proto_tree_add_text(chassis_tree, tvb, (offset+4), (tempLen-2), "Chassis Id: %s", strPtr); |
| 700 | | | break; |
| 701 | | | } |
| 702 | | | break; |
| 703 | | | case 2: |
| 704 | | | case 6: |
| 705 | | | case 7: |
| 706 | | | proto_tree_add_text(chassis_tree, tvb, (offset+3), (tempLen-1), "Chassis Id: %s", strPtr); |
| 707 | | | proto_item_append_text(tf, ", Id: %s", strPtr); |
| 708 | | | break; |
| 709 | | | case 1: |
| 710 | | | case 3: |
| 711 | | | proto_tree_add_item(chassis_tree, hf_chassis_id, tvb, (offset+3), (tempLen-1), FALSE); |
| 712 | | | break; |
| 713 | | | } |
| 714 | | | } |
| 715 | | | |
| 716 | | | return (tempLen + 2); |
| 717 | | | } |
| |