Text   |  XML   |  ReML   |   Visible Warnings:

Useless Assignment  at pcapng.c:733

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

pcapng_read_packet_block

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/pcapng.c)expand/collapse
Show more  
 656  pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *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          pcapng_option_header_t oh;
 666          char option_content[100]; /* XXX - size might need to be increased, if we see longer options */
 667   
 668   
 669          /* "(Enhanced) Packet Block" read fixed part */
 670          errno = WTAP_ERR_CANT_READ;
 671          if (enhanced) {
 672                  bytes_read = file_read(&epb, 1, sizeof epb, fh);
 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);
 682                          wblock->data.packet.drops_count         = -1; /* invalid */
 683                          wblock->data.packet.ts_high             = BSWAP32(epb.timestamp_high);
 684                          wblock->data.packet.ts_low              = BSWAP32(epb.timestamp_low);
 685                          wblock->data.packet.cap_len             = BSWAP32(epb.captured_len);
 686                          wblock->data.packet.packet_len          = BSWAP32(epb.packet_len);
 687                  } else {
 688                          wblock->data.packet.interface_id        = epb.interface_id;
 689                          wblock->data.packet.drops_count         = -1; /* invalid */
 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);
 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);
 708                          wblock->data.packet.ts_low              = BSWAP32(pb.timestamp_low);
 709                          wblock->data.packet.cap_len             = BSWAP32(pb.captured_len);
 710                          wblock->data.packet.packet_len          = BSWAP32(pb.packet_len);
 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          /* XXX - implement other linktypes then Ethernet */
 727          /* (or even better share the code with libpcap.c) */
 728   
 729          /* Ethernet FCS length, might be overwritten by "per packet" options */
 730          ((union wtap_pseudo_header *) wblock->pseudo_header)->eth.fcs_len = pn->if_fcslen;
 731   
 732          /* "(Enhanced) Packet Block" read capture data */
 733          errno = WTAP_ERR_CANT_READ;
 734          bytes_read = file_read((guchar *) (wblock->frame_buffer), 1, wblock->data.packet.cap_len, fh);
 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          /* jump over potential padding bytes at end of the packet data */
 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);
 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          /* add padding bytes to "block total length" */
 757          /* (the "block total length" of some example files don't contain the packet data padding bytes!) */
 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          /* Option defaults */
 765          wblock->data.packet.opt_comment = NULL;
 766          wblock->data.packet.drop_count  = -1;
 767          wblock->data.packet.pack_flags  = 0;    /* XXX - is 0 ok to signal "not used"? */
 768   
 769          /* Options */
 770          errno = WTAP_ERR_CANT_READ;
 771          to_read = block_total_length 
 772          - (int)sizeof(pcapng_block_header_t)  
 773          - block_read    /* fixed and variable part, including padding */
 774          - (int)sizeof(bh->block_total_length);
 775          while(to_read > 0) {
 776                  /* read option */
 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                  /* handle option content */
 786                  switch(oh.option_code) {
 787                      case(0): /* opt_endofopt */
 788                          if(to_read != 0) {
 789                                  pcapng_debug1("pcapng_read_packet_block: %u bytes after opt_endofopt", to_read);
 790                          }
 791                          /* padding should be ok here, just get out of this */
 792                          to_read = 0;
 793                          break;
 794                      case(1): /* opt_comment */
 795                          if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) {
 796                                  wblock->data.section.opt_comment = g_strndup(option_content, sizeof(option_content));
 797                                  pcapng_debug1("pcapng_read_packet_block: opt_comment %s", wblock->data.section.opt_comment);
 798                          } else {
 799                                  pcapng_debug1("pcapng_read_packet_block: opt_comment length %u seems strange", oh.option_length);
 800                          }
 801                          break;
 802                      case(2): /* pack_flags / epb_flags */
 803                          if(oh.option_length == 4) {
 804                                  /*  Don't cast a char[] into a guint32--the
 805                                   *  char[] may not be aligned correctly.
 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);
 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  }
Show more  




Change Warning 1043.29956 : Useless Assignment

Because they are very similar, this warning shares annotations with warning 1043.29957.

Priority:
State:
Finding:
Owner:
Note: