(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/ngsniffer.c) |
| |
| 506 | | | int ngsniffer_open(wtap *wth, int *err, gchar **err_info) |
| 507 | | | { |
| 508 | | | int bytes_read; |
| 509 | | | char magic[sizeof ngsniffer_magic]; |
| 510 | | | char record_type[2]; |
| 511 | | | char record_length[4]; |
| 512 | | | |
| 513 | | | guint16 type, length; |
| 514 | | | struct vers_rec version; |
| 515 | | | guint16 maj_vers; |
| 516 | | | guint16 start_date; |
| 517 | | | guint16 start_time; |
| 518 | | | static const int sniffer_encap[] = { |
| 519 | | | WTAP_ENCAP_TOKEN_RING, |
| 520 | | | WTAP_ENCAP_ETHERNET, |
| 521 | | | WTAP_ENCAP_ARCNET, |
| 522 | | | WTAP_ENCAP_UNKNOWN, |
| 523 | | | WTAP_ENCAP_UNKNOWN, |
| 524 | | | WTAP_ENCAP_UNKNOWN, |
| 525 | | | WTAP_ENCAP_UNKNOWN, |
| 526 | | | WTAP_ENCAP_PER_PACKET, |
| 527 | | | WTAP_ENCAP_PER_PACKET, |
| 528 | | | WTAP_ENCAP_FDDI_BITSWAPPED, |
| 529 | | | WTAP_ENCAP_ATM_PDUS |
| 530 | | | }; |
| 531 | | | #define NUM_NGSNIFF_ENCAPS (sizeof sniffer_encap / sizeof sniffer_encap[0]) |
| 532 | | | struct tm tm; |
| 533 | | | |
| 534 | | | |
| 535 | | | errno = WTAP_ERR_CANT_READ; |
| 536 | | | bytes_read = file_read(magic, 1, sizeof magic, wth->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))) |
| |
|
| 537 | | | if (bytes_read != sizeof magic) { |
| 538 | | | *err = file_error(wth->fh); |
| 539 | | | if (*err != 0) |
| 540 | | | return -1; |
| 541 | | | return 0; |
| 542 | | | } |
| 543 | | | wth->data_offset += sizeof magic; |
| 544 | | | |
| 545 | | | if (memcmp(magic, ngsniffer_magic, sizeof ngsniffer_magic)) { |
| 546 | | | return 0; |
| 547 | | | } |
| 548 | | | |
| 549 | | | |
| 550 | | | |
| 551 | | | |
| 552 | | | |
| 553 | | | errno = WTAP_ERR_CANT_READ; |
| 554 | | | bytes_read = file_read(record_type, 1, 2, wth->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))) |
| |
|
| 555 | | | bytes_read += file_read(record_length, 1, 4, wth->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))) |
| |
|
| 556 | | | if (bytes_read != 6) { |
| 557 | | | *err = file_error(wth->fh); |
| 558 | | | if (*err != 0) |
| 559 | | | return -1; |
| 560 | | | return 0; |
| 561 | | | } |
| 562 | | | wth->data_offset += 6; |
| 563 | | | |
| 564 | | | type = pletohs(record_type);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
| 565 | | | length = pletohs(record_length);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
Unused Value
The value assigned to length is never subsequently used on any execution path. |
|
| 566 | | | |
| 567 | | | if (type != REC_VERS) { |
| 568 | | | *err = WTAP_ERR_BAD_RECORD; |
| 569 | | | *err_info = g_strdup_printf("ngsniffer: Sniffer file doesn't start with a version record"); |
| 570 | | | return -1; |
| 571 | | | } |
| 572 | | | |
| 573 | | | errno = WTAP_ERR_CANT_READ; |
| 574 | | | bytes_read = file_read(&version, 1, sizeof version, wth->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))) |
| |
|
| 575 | | | if (bytes_read != sizeof version) { |
| 576 | | | *err = file_error(wth->fh); |
| 577 | | | if (*err != 0) |
| 578 | | | return -1; |
| 579 | | | return 0; |
| 580 | | | } |
| 581 | | | wth->data_offset += sizeof version; |
| 582 | | | |
| 583 | | | |
| 584 | | | if (version.network >= NUM_NGSNIFF_ENCAPS
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/ngsniffer.c |
| |
531 | #define NUM_NGSNIFF_ENCAPS (sizeof sniffer_encap / sizeof sniffer_encap[0]) |
| |
|
| 585 | | | || sniffer_encap[version.network] == WTAP_ENCAP_UNKNOWN) { |
| 586 | | | *err = WTAP_ERR_UNSUPPORTED_ENCAP; |
| 587 | | | *err_info = g_strdup_printf("ngsniffer: network type %u unknown or unsupported", |
| 588 | | | version.network); |
| 589 | | | return -1; |
| 590 | | | } |
| 591 | | | |
| 592 | | | |
| 593 | | | if (version.timeunit >= NUM_NGSNIFF_TIMEUNITS) { |
| 594 | | | *err = WTAP_ERR_UNSUPPORTED; |
| 595 | | | *err_info = g_strdup_printf("ngsniffer: Unknown timeunit %u", version.timeunit); |
| 596 | | | return -1; |
| 597 | | | } |
| 598 | | | |
| 599 | | | |
| 600 | | | if (version.format != 1) { |
| 601 | | | wth->file_type = WTAP_FILE_NGSNIFFER_COMPRESSED; |
| 602 | | | |
| 603 | | | } else { |
| 604 | | | wth->file_type = WTAP_FILE_NGSNIFFER_UNCOMPRESSED; |
| 605 | | | } |
| 606 | | | |
| 607 | | | |
| 608 | | | |
| 609 | | | |
| 610 | | | wth->file_encap = sniffer_encap[version.network]; |
| 611 | | | |
| 612 | | | |
| 613 | | | |
| 614 | | | |
| 615 | | | |
| 616 | | | |
| 617 | | | |
| 618 | | | |
| 619 | | | |
| 620 | | | |
| 621 | | | |
| 622 | | | |
| 623 | | | |
| 624 | | | |
| 625 | | | maj_vers = pletohs(&version.maj_vers);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
| 626 | | | if ((wth, err, err_info, maj_vers, |
| 627 | | | version.network) < 0) |
| 628 | | | return -1; |
| 629 | | | if ((version.network == NETWORK_SYNCHRO ||
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/ngsniffer.c |
| |
125 | #define NETWORK_SYNCHRO 7 /* Internetwork analyzer (synchronous) */ |
| |
|
| 630 | | | version.network == NETWORK_ASYNC) &&
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/ngsniffer.c |
| |
126 | #define NETWORK_ASYNC 8 /* Internetwork analyzer (asynchronous) */ |
| |
|
| 631 | | | wth->file_encap == WTAP_ENCAP_PER_PACKET) { |
| 632 | | | |
| 633 | | | |
| 634 | | | |
| 635 | | | |
| 636 | | | switch (maj_vers) { |
| 637 | | | |
| 638 | | | case 1: |
| 639 | | | |
| 640 | | | |
| 641 | | | |
| 642 | | | |
| 643 | | | switch (pletohs(&version.rsvd[0])) {
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
| 644 | | | |
| 645 | | | case 1: |
| 646 | | | case 2: |
| 647 | | | wth->file_encap = WTAP_ENCAP_ISDN; |
| 648 | | | break; |
| 649 | | | } |
| 650 | | | break; |
| 651 | | | |
| 652 | | | case 3: |
| 653 | | | |
| 654 | | | |
| 655 | | | |
| 656 | | | |
| 657 | | | |
| 658 | | | |
| 659 | | | |
| 660 | | | wth->file_encap = WTAP_ENCAP_FRELAY_WITH_PHDR; |
| 661 | | | break; |
| 662 | | | } |
| 663 | | | } |
| 664 | | | |
| 665 | | | |
| 666 | | | |
| 667 | | | |
| 668 | | | |
| 669 | | | |
| 670 | | | |
| 671 | | | |
| 672 | | | |
| 673 | | | |
| 674 | | | if (wth->random_fh != NULL) { |
| 675 | | | if (file_seek(wth->random_fh, wth->data_offset, SEEK_SET, err) == -1)
x /usr/include/stdio.h |
| |
141 | #define SEEK_SET 0 /* Seek from beginning of file. */ |
| |
|
| 676 | | | return -1; |
| 677 | | | } |
| 678 | | | |
| 679 | | | |
| 680 | | | wth->capture.ngsniffer = g_malloc(sizeof(ngsniffer_t)); |
| 681 | | | wth->capture.ngsniffer->maj_vers = maj_vers; |
| 682 | | | wth->capture.ngsniffer->min_vers = pletohs(&version.min_vers);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
| 683 | | | |
| 684 | | | |
| 685 | | | wth->capture.ngsniffer->seq.buf = NULL; |
| 686 | | | wth->capture.ngsniffer->rand.buf = NULL; |
| 687 | | | |
| 688 | | | |
| 689 | | | |
| 690 | | | wth->capture.ngsniffer->seq.uncomp_offset = wth->data_offset; |
| 691 | | | wth->capture.ngsniffer->seq.comp_offset = wth->data_offset; |
| 692 | | | wth->capture.ngsniffer->rand.uncomp_offset = wth->data_offset; |
| 693 | | | wth->capture.ngsniffer->rand.comp_offset = wth->data_offset; |
| 694 | | | |
| 695 | | | |
| 696 | | | wth->capture.ngsniffer->first_blob = NULL; |
| 697 | | | wth->capture.ngsniffer->last_blob = NULL; |
| 698 | | | wth->capture.ngsniffer->current_blob = NULL; |
| 699 | | | |
| 700 | | | wth->subtype_read = ngsniffer_read; |
| 701 | | | wth->subtype_seek_read = ngsniffer_seek_read; |
| 702 | | | wth->subtype_sequential_close = ngsniffer_sequential_close; |
| 703 | | | wth->subtype_close = ngsniffer_close; |
| 704 | | | wth->snapshot_length = 0; |
| 705 | | | wth->capture.ngsniffer->timeunit = Psec[version.timeunit]; |
| 706 | | | wth->capture.ngsniffer->network = version.network; |
| 707 | | | |
| 708 | | | |
| 709 | | | start_time = pletohs(&version.time);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
| 710 | | | start_date = pletohs(&version.date);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
| 711 | | | tm.tm_year = ((start_date&0xfe00)>>9) + 1980 - 1900; |
| 712 | | | tm.tm_mon = ((start_date&0x1e0)>>5) - 1; |
| 713 | | | tm.tm_mday = (start_date&0x1f); |
| 714 | | | |
| 715 | | | |
| 716 | | | |
| 717 | | | |
| 718 | | | tm.tm_hour = 0; |
| 719 | | | tm.tm_min = 0; |
| 720 | | | tm.tm_sec = 0; |
| 721 | | | tm.tm_isdst = -1; |
| 722 | | | wth->capture.ngsniffer->start = mktime(&tm); |
| 723 | | | |
| 724 | | | |
| 725 | | | |
| 726 | | | |
| 727 | | | |
| 728 | | | |
| 729 | | | |
| 730 | | | |
| 731 | | | |
| 732 | | | |
| 733 | | | |
| 734 | | | |
| 735 | | | |
| 736 | | | |
| 737 | | | |
| 738 | | | |
| 739 | | | wth->tsprecision = WTAP_FILE_TSPREC_NSEC; |
| 740 | | | |
| 741 | | | return 1; |
| 742 | | | } |
| |