(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/iseries.c) |
| |
| 473 | | | iseries_parse_packet (wtap * wth, FILE_T fh, |
| 474 | | | union *, guint8 * pd, |
| 475 | | | int *err, gchar ** err_info) |
| 476 | | | { |
| 477 | | | gint64 cur_off; |
| 478 | | | gboolean isValid, isCurrentPacket, IPread, TCPread, isDATA; |
| 479 | | | int num_items_scanned, line, pktline, buflen, i; |
| 480 | | | guint32 pkt_len; |
| 481 | | | int cap_len, pktnum, month, day, year, hr, min, sec, csec; |
| 482 | | | char direction[2], destmac[13], srcmac[13], type[5], [41], |
| 483 | | | [81]; |
| 484 | | | char hex1[17], hex2[17], hex3[17], hex4[17]; |
| 485 | | | char data[ISERIES_LINE_LENGTH * 2]; |
| 486 | | | guint8 *buf, *asciibuf; |
| 487 | | | char *tcpdatabuf, *workbuf; |
| 488 | | | struct tm tm; |
| 489 | | | |
| 490 | | | |
| 491 | | | |
| 492 | | | |
| 493 | | | |
| 494 | | | |
| 495 | | | isValid = FALSE; |
| 496 | | | for (line = 1; line < ISERIES_PKT_LINES_TO_CHECK; line++) |
| 497 | | | { |
| 498 | | | cur_off = file_tell (fh); |
| 499 | | | if (file_gets (data, ISERIES_LINE_LENGTH, fh) == NULL) |
| 500 | | | { |
| 501 | | | *err = file_error (fh); |
| 502 | | | if (*err == 0) |
| 503 | | | { |
| 504 | | | *err = WTAP_ERR_SHORT_READ; |
| 505 | | | } |
| 506 | | | return -1; |
| 507 | | | } |
| 508 | | | |
| 509 | | | if (wth->capture.iseries->format == ISERIES_FORMAT_UNICODE) |
| 510 | | | { |
| 511 | | | iseries_UNICODE_to_ASCII ((guint8 *)data, ISERIES_LINE_LENGTH); |
| 512 | | | } |
| 513 | | | |
| 514 | | | for (i=0; i<8; i++) { |
| 515 | | | if (strncmp(data+i,"*",1) == 0) |
| 516 | | | g_strlcpy(data+i," ",(ISERIES_LINE_LENGTH * 2)); |
| 517 | | | } |
| 518 | | | num_items_scanned = |
| 519 | | | sscanf (data, |
| 520 | | | "%6d %1s %6d %d:%d:%d.%d %12s %12s ETHV2 Type: %4s", |
| 521 | | | &pktnum, direction, &cap_len, &hr, &min, &sec, &csec, destmac, |
| 522 | | | srcmac, type); |
| 523 | | | if (num_items_scanned == 10) |
| 524 | | | { |
| 525 | | | |
| 526 | | | isValid = TRUE; |
| 527 | | | |
| 528 | | | |
| 529 | | | |
| 530 | | | |
| 531 | | | cap_len += 14; |
| 532 | | | break; |
| 533 | | | } |
| 534 | | | } |
| 535 | | | |
| 536 | | | |
| 537 | | | |
| 538 | | | |
| 539 | | | if (!isValid) |
| 540 | | | { |
| 541 | | | *err = WTAP_ERR_BAD_RECORD; |
| 542 | | | *err_info = g_strdup ("iseries: packet isn't valid"); |
| 543 | | | return -1; |
| 544 | | | } |
| 545 | | | |
| 546 | | | |
| 547 | | | |
| 548 | | | |
| 549 | | | |
| 550 | | | |
| 551 | | | |
| 552 | | | |
| 553 | | | if (wth->capture.iseries->sdate) |
| 554 | | | { |
| 555 | | | num_items_scanned = |
| 556 | | | sscanf (wth->capture.iseries->sdate, "%d/%d/%d", &month, &day, &year); |
Ignored Return Value
The return value of __isoc99_sscanf() 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.
- CodeSonar is configured to enforce Ignored Return Value checks for __isoc99_sscanf(). (To change the set of enforced Ignored Return Value checks, use configuration file parameters RETURN_CHECKER_CHECKED_FUNCS and RETURN_CHECKER_IGNORED_FUNCS).
Show: All events | Only primary events |
|
| 557 | | | tm.tm_year = 100 + year; |
| 558 | | | tm.tm_mon = month - 1; |
| 559 | | | tm.tm_mday = day; |
| 560 | | | tm.tm_hour = hr; |
| 561 | | | tm.tm_min = min; |
| 562 | | | tm.tm_sec = sec; |
| 563 | | | tm.tm_isdst = -1; |
| 564 | | | wth->phdr.ts.secs = mktime (&tm); |
| 565 | | | |
| 566 | | | if (csec > 99999) |
Event 2:
Taking false branch. csec > 99999 evaluates to false.
hide
|
|
| 567 | | | { |
| 568 | | | wth->phdr.ts.nsecs = csec * 1000; |
| 569 | | | } |
| 570 | | | |
| 571 | | | else |
| 572 | | | { |
| 573 | | | wth->phdr.ts.nsecs = csec * 10000; |
| 574 | | | } |
| 575 | | | } |
| 576 | | | |
| 577 | | | wth->phdr.caplen = cap_len; |
| 578 | | | wth->phdr.pkt_encap = WTAP_ENCAP_ETHERNET; |
| 579 | | | ->eth.fcs_len = -1; |
| 580 | | | |
| 581 | | | |
| 582 | | | |
| 583 | | | |
| 584 | | | isCurrentPacket = TRUE; |
Event 3:
!0 evaluates to true.
hide
|
|
| 585 | | | IPread = FALSE; |
| 586 | | | TCPread = FALSE; |
| 587 | | | isDATA = FALSE; |
| 588 | | | |
| 589 | | | |
| 590 | | | |
| 591 | | | tcpdatabuf = g_malloc (ISERIES_PKT_ALLOC_SIZE); |
| 592 | | | g_snprintf (tcpdatabuf, 1, "%s", ""); |
| 593 | | | workbuf = g_malloc (ISERIES_PKT_ALLOC_SIZE); |
| 594 | | | g_snprintf (workbuf, 1, "%s", ""); |
| 595 | | | |
| 596 | | | pktline = 0; |
| 597 | | | while (isCurrentPacket) |
| 598 | | | { |
| 599 | | | pktline++; |
| 600 | | | |
| 601 | | | if (file_gets (data, ISERIES_LINE_LENGTH, fh) == NULL) |
| 602 | | | { |
| 603 | | | if (file_eof (fh)) |
Event 5:
Taking true branch. gzeof(fh) evaluates to true.
hide
|
|
| 604 | | | { |
| 605 | | | break; |
| 606 | | | } |
| 607 | | | else |
| 608 | | | { |
| 609 | | | *err = file_error (fh); |
| 610 | | | if (*err == 0) |
| 611 | | | { |
| 612 | | | *err = WTAP_ERR_SHORT_READ; |
| 613 | | | } |
| 614 | | | return -1; |
| 615 | | | } |
| 616 | | | } |
| 617 | | | |
| 618 | | | |
| 619 | | | if (wth->capture.iseries->format == ISERIES_FORMAT_UNICODE) |
| 620 | | | { |
| 621 | | | buflen = iseries_UNICODE_to_ASCII ((guint8 *)data, ISERIES_LINE_LENGTH); |
| 622 | | | } |
| 623 | | | else |
| 624 | | | { |
| 625 | | | |
| 626 | | | buflen = (int) strlen (data); |
| 627 | | | } |
| 628 | | | |
| 629 | | | |
| 630 | | | num_items_scanned = sscanf (data + 22, "IP : %40s", ); |
| 631 | | | if (num_items_scanned == 1) |
| 632 | | | { |
| 633 | | | IPread = TRUE; |
| 634 | | | } |
| 635 | | | |
| 636 | | | |
| 637 | | | num_items_scanned = sscanf (data + 22, "TCP : %80s", ); |
| 638 | | | if (num_items_scanned == 1) |
| 639 | | | { |
| 640 | | | TCPread = TRUE; |
| 641 | | | } |
| 642 | | | |
| 643 | | | |
| 644 | | | |
| 645 | | | |
| 646 | | | |
| 647 | | | |
| 648 | | | num_items_scanned = |
| 649 | | | sscanf (data + 27, "%16[A-Z0-9] %16[A-Z0-9] %16[A-Z0-9] %16[A-Z0-9]", |
| 650 | | | hex1, hex2, hex3, hex4); |
| 651 | | | if (num_items_scanned > 0) |
| 652 | | | { |
| 653 | | | isDATA = TRUE; |
| 654 | | | |
| 655 | | | |
| 656 | | | |
| 657 | | | |
| 658 | | | |
| 659 | | | |
| 660 | | | switch (num_items_scanned) |
| 661 | | | { |
| 662 | | | case 1: |
| 663 | | | g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s", tcpdatabuf, |
| 664 | | | hex1); |
| 665 | | | break; |
| 666 | | | case 2: |
| 667 | | | g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s", |
| 668 | | | tcpdatabuf, hex1, hex2); |
| 669 | | | break; |
| 670 | | | case 3: |
| 671 | | | g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s", |
| 672 | | | tcpdatabuf, hex1, hex2, hex3); |
| 673 | | | break; |
| 674 | | | default: |
| 675 | | | g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s%s", |
| 676 | | | tcpdatabuf, hex1, hex2, hex3, hex4); |
| 677 | | | } |
| 678 | | | memcpy (tcpdatabuf, workbuf, ISERIES_PKT_ALLOC_SIZE); |
| 679 | | | } |
| 680 | | | |
| 681 | | | |
| 682 | | | |
| 683 | | | |
| 684 | | | |
| 685 | | | if ((strncmp (data + 80, ISERIES_PKT_MAGIC_STR, ISERIES_PKT_MAGIC_LEN) |
| 686 | | | == 0) && pktline > 1) |
| 687 | | | { |
| 688 | | | isCurrentPacket = FALSE; |
| 689 | | | cur_off = file_tell (fh); |
| 690 | | | if (cur_off == -1) |
| 691 | | | { |
| 692 | | | |
| 693 | | | *err = file_error (fh); |
| 694 | | | return -1; |
| 695 | | | } |
| 696 | | | if (file_seek (fh, cur_off - buflen, SEEK_SET, err) == -1)
x /usr/include/stdio.h |
| |
141 | #define SEEK_SET 0 /* Seek from beginning of file. */ |
| |
|
| 697 | | | { |
| 698 | | | return -1; |
| 699 | | | } |
| 700 | | | } |
| 701 | | | } |
| 702 | | | |
| 703 | | | |
| 704 | | | |
| 705 | | | |
| 706 | | | |
| 707 | | | if (wth->capture.iseries->tcp_formatted) |
Event 6:
Taking true branch. wth->capture.iseries->tcp_formatted evaluates to true.
hide
|
|
| 708 | | | { |
| 709 | | | if (!IPread) |
Event 7:
Skipping " if". IPread evaluates to true.
hide
|
|
| 710 | | | { |
| 711 | | | *err = WTAP_ERR_BAD_RECORD; |
| 712 | | | *err_info = g_strdup ("iseries: IP isn't valid"); |
| 713 | | | return -1; |
| 714 | | | } |
| 715 | | | if (!TCPread) |
Event 8:
Skipping " if". TCPread evaluates to true.
hide
|
|
| 716 | | | { |
| 717 | | | *err = WTAP_ERR_BAD_RECORD; |
| 718 | | | *err_info = g_strdup ("iseries: TCP isn't valid"); |
| 719 | | | return -1; |
| 720 | | | } |
| 721 | | | } |
| 722 | | | |
| 723 | | | |
| 724 | | | |
| 725 | | | |
| 726 | | | |
| 727 | | | asciibuf = g_malloc (ISERIES_PKT_ALLOC_SIZE); |
| 728 | | | if (isDATA) |
Event 9:
Taking false branch. isDATA evaluates to false.
hide
|
|
| 729 | | | { |
| 730 | | | |
| 731 | | | if (wth->capture.iseries->tcp_formatted) |
| 732 | | | { |
| 733 | | | |
| 734 | | | g_snprintf (asciibuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s%s%s", |
| 735 | | | destmac, srcmac, type, , , tcpdatabuf); |
| 736 | | | } |
| 737 | | | else |
| 738 | | | { |
| 739 | | | |
| 740 | | | g_snprintf (asciibuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s", destmac, |
| 741 | | | srcmac, type, tcpdatabuf); |
| 742 | | | } |
| 743 | | | } |
| 744 | | | else |
| 745 | | | { |
| 746 | | | |
| 747 | | | g_snprintf (asciibuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s%s", destmac, |
| 748 | | | srcmac, type, , ); |
| 749 | | | } |
| 750 | | | |
| 751 | | | |
| 752 | | | |
| 753 | | | |
| 754 | | | |
| 755 | | | |
| 756 | | | |
| 757 | | | |
| 758 | | | |
| 759 | | | |
| 760 | | | num_items_scanned = sscanf (asciibuf + 32, "%4x", &pkt_len); |
| 761 | | | wth->phdr.len = pkt_len + 14; |
| 762 | | | if (wth->phdr.caplen > wth->phdr.len) |
Event 10:
Taking true branch. wth->phdr.caplen > wth->phdr.len evaluates to true.
hide
|
|
| 763 | | | wth->phdr.len = wth->phdr.caplen; |
| 764 | | | |
| 765 | | | |
| 766 | | | if (pd == NULL) |
Event 11:
Taking true branch. pd == (void *)0 evaluates to true.
hide
|
|
| 767 | | | { |
| 768 | | | buffer_assure_space (wth->frame_buffer, ISERIES_MAX_PACKET_LEN); |
| 769 | | | buf = buffer_start_ptr (wth->frame_buffer);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/buffer.h |
| |
46 | # define buffer_start_ptr(buffer) ((buffer)->data + (buffer)->start) |
| |
|
| 770 | | | |
| 771 | | | iseries_parse_hex_string (asciibuf, buf, (int) strlen (asciibuf)); |
| 772 | | | } |
| 773 | | | else |
| 774 | | | { |
| 775 | | | |
| 776 | | | iseries_parse_hex_string (asciibuf, pd, (int) strlen (asciibuf)); |
| 777 | | | } |
| 778 | | | |
| 779 | | | |
| 780 | | | *err = 0; |
| 781 | | | g_free (asciibuf); |
| 782 | | | g_free (tcpdatabuf); |
| 783 | | | g_free (workbuf); |
| 784 | | | return wth->phdr.len; |
| 785 | | | } |
| |