(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/pcapng.c) |
| |
| 656 | | | pcapng_read_packet_block(FILE_T fh, *bh, pcapng_t *pn, wtapng_block_t *wblock,int *err, gchar **err_info _U_, gboolean enhanced) |
| 657 | | | { |
| 658 | | | int bytes_read; |
| 659 | | | int block_read; |
| 660 | | | int to_read; |
| 661 | | | guint64 file_offset64; |
| 662 | | | pcapng_enhanced_packet_block_t epb; |
| 663 | | | pcapng_packet_block_t pb; |
| 664 | | | guint32 block_total_length; |
| 665 | | | oh; |
| 666 | | | char option_content[100]; |
| 667 | | | |
| 668 | | | |
| 669 | | | |
| 670 | | | errno = WTAP_ERR_CANT_READ; |
| 671 | | | if (enhanced) { |
| 672 | | | bytes_read = file_read(&epb, 1, sizeof epb, fh);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/file_wrappers.h |
| |
36 | #define file_read(buf, bsize, count, file) gzread((file),(buf),(unsigned)((count)*(bsize))) |
| |
|
| 673 | | | if (bytes_read != sizeof epb) { |
| 674 | | | pcapng_debug0("pcapng_read_packet_block: failed to read packet data"); |
| 675 | | | *err = file_error(fh); |
| 676 | | | return 0; |
| 677 | | | } |
| 678 | | | block_read = bytes_read; |
| 679 | | | |
| 680 | | | if (pn->byte_swapped) { |
| 681 | | | wblock->data.packet.interface_id = BSWAP32(epb.interface_id);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
297 | #define BSWAP32(x) \ |
298 | ((((x)&0xFF000000)>>24) | \ |
299 | (((x)&0x00FF0000)>>8) | \ |
300 | (((x)&0x0000FF00)<<8) | \ |
301 | (((x)&0x000000FF)<<24)) |
| |
|
| 682 | | | wblock->data.packet.drops_count = -1; |
| 683 | | | wblock->data.packet.ts_high = BSWAP32(epb.timestamp_high);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
297 | #define BSWAP32(x) \ |
298 | ((((x)&0xFF000000)>>24) | \ |
299 | (((x)&0x00FF0000)>>8) | \ |
300 | (((x)&0x0000FF00)<<8) | \ |
301 | (((x)&0x000000FF)<<24)) |
| |
|
| 684 | | | wblock->data.packet.ts_low = BSWAP32(epb.timestamp_low);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
297 | #define BSWAP32(x) \ |
298 | ((((x)&0xFF000000)>>24) | \ |
299 | (((x)&0x00FF0000)>>8) | \ |
300 | (((x)&0x0000FF00)<<8) | \ |
301 | (((x)&0x000000FF)<<24)) |
| |
|
| 685 | | | wblock->data.packet.cap_len = BSWAP32(epb.captured_len);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
297 | #define BSWAP32(x) \ |
298 | ((((x)&0xFF000000)>>24) | \ |
299 | (((x)&0x00FF0000)>>8) | \ |
300 | (((x)&0x0000FF00)<<8) | \ |
301 | (((x)&0x000000FF)<<24)) |
| |
|
| 686 | | | wblock->data.packet.packet_len = BSWAP32(epb.packet_len);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
297 | #define BSWAP32(x) \ |
298 | ((((x)&0xFF000000)>>24) | \ |
299 | (((x)&0x00FF0000)>>8) | \ |
300 | (((x)&0x0000FF00)<<8) | \ |
301 | (((x)&0x000000FF)<<24)) |
| |
|
| 687 | | | } else { |
| 688 | | | wblock->data.packet.interface_id = epb.interface_id; |
| 689 | | | wblock->data.packet.drops_count = -1; |
| 690 | | | wblock->data.packet.ts_high = epb.timestamp_high; |
| 691 | | | wblock->data.packet.ts_low = epb.timestamp_low; |
| 692 | | | wblock->data.packet.cap_len = epb.captured_len; |
| 693 | | | wblock->data.packet.packet_len = epb.packet_len; |
| 694 | | | } |
| 695 | | | } else { |
| 696 | | | bytes_read = file_read(&pb, 1, sizeof pb, fh);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/file_wrappers.h |
| |
36 | #define file_read(buf, bsize, count, file) gzread((file),(buf),(unsigned)((count)*(bsize))) |
| |
|
| 697 | | | if (bytes_read != sizeof pb) { |
| 698 | | | pcapng_debug0("pcapng_read_packet_block: failed to read packet data"); |
| 699 | | | *err = file_error(fh); |
| 700 | | | return 0; |
| 701 | | | } |
| 702 | | | block_read = bytes_read; |
| 703 | | | |
| 704 | | | if (pn->byte_swapped) { |
| 705 | | | wblock->data.packet.interface_id = BSWAP16(pb.interface_id); |
| 706 | | | wblock->data.packet.drops_count = BSWAP16(pb.drops_count); |
| 707 | | | wblock->data.packet.ts_high = BSWAP32(pb.timestamp_high);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
297 | #define BSWAP32(x) \ |
298 | ((((x)&0xFF000000)>>24) | \ |
299 | (((x)&0x00FF0000)>>8) | \ |
300 | (((x)&0x0000FF00)<<8) | \ |
301 | (((x)&0x000000FF)<<24)) |
| |
|
| 708 | | | wblock->data.packet.ts_low = BSWAP32(pb.timestamp_low);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
297 | #define BSWAP32(x) \ |
298 | ((((x)&0xFF000000)>>24) | \ |
299 | (((x)&0x00FF0000)>>8) | \ |
300 | (((x)&0x0000FF00)<<8) | \ |
301 | (((x)&0x000000FF)<<24)) |
| |
|
| 709 | | | wblock->data.packet.cap_len = BSWAP32(pb.captured_len);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
297 | #define BSWAP32(x) \ |
298 | ((((x)&0xFF000000)>>24) | \ |
299 | (((x)&0x00FF0000)>>8) | \ |
300 | (((x)&0x0000FF00)<<8) | \ |
301 | (((x)&0x000000FF)<<24)) |
| |
|
| 710 | | | wblock->data.packet.packet_len = BSWAP32(pb.packet_len);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
297 | #define BSWAP32(x) \ |
298 | ((((x)&0xFF000000)>>24) | \ |
299 | (((x)&0x00FF0000)>>8) | \ |
300 | (((x)&0x0000FF00)<<8) | \ |
301 | (((x)&0x000000FF)<<24)) |
| |
|
| 711 | | | } else { |
| 712 | | | wblock->data.packet.interface_id = pb.interface_id; |
| 713 | | | wblock->data.packet.drops_count = pb.drops_count; |
| 714 | | | wblock->data.packet.ts_high = pb.timestamp_high; |
| 715 | | | wblock->data.packet.ts_low = pb.timestamp_low; |
| 716 | | | wblock->data.packet.cap_len = pb.captured_len; |
| 717 | | | wblock->data.packet.packet_len = pb.packet_len; |
| 718 | | | } |
| 719 | | | } |
| 720 | | | |
| 721 | | | pcapng_debug3("pcapng_read_packet_block: packet data: packet_len %u captured_len %u interface_id %u", |
| 722 | | | wblock->data.packet.packet_len, |
| 723 | | | wblock->data.packet.cap_len, |
| 724 | | | wblock->data.packet.interface_id); |
| 725 | | | |
| 726 | | | |
| 727 | | | |
| 728 | | | |
| 729 | | | |
| 730 | | | ((union *) wblock->)->eth.fcs_len = pn->if_fcslen; |
| 731 | | | |
| 732 | | | |
| 733 | | | errno = WTAP_ERR_CANT_READ; |
Useless Assignment
This code assigns the variable the same value it already had. |
|
| 734 | | | bytes_read = file_read((guchar *) (wblock->frame_buffer), 1, wblock->data.packet.cap_len, fh);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/file_wrappers.h |
| |
36 | #define file_read(buf, bsize, count, file) gzread((file),(buf),(unsigned)((count)*(bsize))) |
| |
|
| 735 | | | if (bytes_read != (int) wblock->data.packet.cap_len) { |
| 736 | | | *err = file_error(fh); |
| 737 | | | pcapng_debug1("pcapng_read_packet_block: couldn't read %u bytes of captured data", |
| 738 | | | wblock->data.packet.cap_len); |
| 739 | | | if (*err == 0) |
| 740 | | | *err = WTAP_ERR_SHORT_READ; |
| 741 | | | return FALSE; |
| 742 | | | } |
| 743 | | | block_read += bytes_read; |
| 744 | | | |
| 745 | | | |
| 746 | | | if( (wblock->data.packet.cap_len % 4) != 0) { |
| 747 | | | file_offset64 = file_seek(fh, 4 - (wblock->data.packet.cap_len % 4), SEEK_CUR, err);
x /usr/include/stdio.h |
| |
142 | #define SEEK_CUR 1 /* Seek from current position. */ |
| |
|
| 748 | | | if (file_offset64 <= 0) { |
| 749 | | | if (*err != 0) |
| 750 | | | return -1; |
| 751 | | | return 0; |
| 752 | | | } |
| 753 | | | block_read += 4 - (wblock->data.packet.cap_len % 4); |
| 754 | | | } |
| 755 | | | |
| 756 | | | |
| 757 | | | |
| 758 | | | if(bh->block_total_length % 4) { |
| 759 | | | block_total_length = bh->block_total_length + 4 - (bh->block_total_length % 4); |
| 760 | | | } else { |
| 761 | | | block_total_length = bh->block_total_length; |
| 762 | | | } |
| 763 | | | |
| 764 | | | |
| 765 | | | wblock->data.packet. = NULL; |
| 766 | | | wblock->data.packet.drop_count = -1; |
| 767 | | | wblock->data.packet.pack_flags = 0; |
| 768 | | | |
| 769 | | | |
| 770 | | | errno = WTAP_ERR_CANT_READ; |
| 771 | | | to_read = block_total_length |
| 772 | | | - (int)sizeof() |
| 773 | | | - block_read |
| 774 | | | - (int)sizeof(bh->block_total_length); |
| 775 | | | while(to_read > 0) { |
| 776 | | | |
| 777 | | | bytes_read = pcapng_read_option(fh, pn, &oh, option_content, sizeof(option_content), err, err_info); |
| 778 | | | if (bytes_read <= 0) { |
| 779 | | | pcapng_debug0("pcapng_read_packet_block: failed to read option"); |
| 780 | | | return bytes_read; |
| 781 | | | } |
| 782 | | | block_read += bytes_read; |
| 783 | | | to_read -= bytes_read; |
| 784 | | | |
| 785 | | | |
| 786 | | | switch(oh.option_code) { |
| 787 | | | case(0): |
| 788 | | | if(to_read != 0) { |
| 789 | | | pcapng_debug1("pcapng_read_packet_block: %u bytes after opt_endofopt", to_read); |
| 790 | | | } |
| 791 | | | |
| 792 | | | to_read = 0; |
| 793 | | | break; |
| 794 | | | case(1): |
| 795 | | | if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) { |
| 796 | | | wblock->data.section. = g_strndup(option_content, sizeof(option_content)); |
| 797 | | | pcapng_debug1("pcapng_read_packet_block: %s", wblock->data.section.); |
| 798 | | | } else { |
| 799 | | | pcapng_debug1("pcapng_read_packet_block: length %u seems strange", oh.option_length); |
| 800 | | | } |
| 801 | | | break; |
| 802 | | | case(2): |
| 803 | | | if(oh.option_length == 4) { |
| 804 | | | |
| 805 | | | |
| 806 | | | |
| 807 | | | memcpy(&wblock->data.packet.pack_flags, option_content, sizeof(guint32)); |
| 808 | | | if(pn->byte_swapped) |
| 809 | | | wblock->data.packet.pack_flags = BSWAP32(wblock->data.packet.pack_flags);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
297 | #define BSWAP32(x) \ |
298 | ((((x)&0xFF000000)>>24) | \ |
299 | (((x)&0x00FF0000)>>8) | \ |
300 | (((x)&0x0000FF00)<<8) | \ |
301 | (((x)&0x000000FF)<<24)) |
| |
|
| 810 | | | pcapng_debug1("pcapng_read_if_descr_block: pack_flags %u (ignored)", wblock->data.packet.pack_flags); |
| 811 | | | } else { |
| 812 | | | pcapng_debug1("pcapng_read_if_descr_block: pack_flags length %u not 4 as expected", oh.option_length); |
| 813 | | | } |
| 814 | | | break; |
| 815 | | | default: |
| 816 | | | pcapng_debug2("pcapng_read_packet_block: unknown option %u - ignoring %u bytes", |
| 817 | | | oh.option_code, oh.option_length); |
| 818 | | | } |
| 819 | | | } |
| 820 | | | |
| 821 | | | return block_read; |
| 822 | | | } |
| |