Text   |  XML   |  ReML   |   Visible Warnings:

Useless Assignment  at visual.c:371

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

visual_read

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/visual.c)expand/collapse
Show more  
 295  static gboolean visual_read(wtap *wth, int *err, gchar **err_info,
 296      gint64 *data_offset)
 297  {
 298      struct visual_read_info *visual = wth->capture.generic;
 299      guint32 packet_size = 0;
 300      int bytes_read;
 301      struct visual_pkt_hdr vpkt_hdr;
 302      struct visual_atm_hdr vatm_hdr;
 303      int phdr_size = sizeof(vpkt_hdr);
 304      int ahdr_size = sizeof(vatm_hdr);
 305      time_t  secs;
 306      guint32 usecs;
 307      double  t;
 308   
 309      /* Check for the end of the packet data.  Note that a check for file EOF
 310         will not work because there are index values stored after the last 
 311         packet's data. */
 312      if (visual->current_pkt > visual->num_pkts)
 313      {
 314          *err = 0;   /* it's just an EOF, not an error */
 315          return FALSE;
 316      }
 317      visual->current_pkt++;
 318   
 319      /* Read the packet header. */
 320      errno = WTAP_ERR_CANT_READ;
 321      bytes_read = file_read(&vpkt_hdr, 1, phdr_size, wth->fh);
 322      if (bytes_read != phdr_size)
 323      {
 324          *err = file_error(wth->fh);
 325          if (*err == 0 && bytes_read != 0)
 326          {
 327              *err = WTAP_ERR_SHORT_READ;
 328          }
 329          return FALSE;
 330      }
 331      wth->data_offset += phdr_size;
 332   
 333      /* Get the included length of data. This includes extra headers + payload */
 334      packet_size = pletohs(&vpkt_hdr.incl_len);
 335   
 336      /* Check for additional ATM packet header */
 337      if (wth->file_encap == WTAP_ENCAP_ATM_PDUS)
 338      {
 339         /* Read the atm packet header. */
 340         errno = WTAP_ERR_CANT_READ;
 341         bytes_read = file_read(&vatm_hdr, 1, ahdr_size, wth->fh);
 342         if (bytes_read != ahdr_size)
 343         {
 344             *err = file_error(wth->fh);
 345             if (*err == 0 && bytes_read != 0)
 346             {
 347                 *err = WTAP_ERR_SHORT_READ;
 348             }
 349             return FALSE;
 350         }
 351         wth->data_offset += ahdr_size;
 352         
 353         /* Remove ATM header from length of included bytes in capture, as 
 354            this header was appended by the processor doing the packet reassembly,
 355            and was not transmitted across the wire */
 356         packet_size -= ahdr_size;
 357      }
 358   
 359      /* Read the packet data. */
 360      if (packet_size > WTAP_MAX_PACKET_SIZE)
 361      {
 362          /* Probably a corrupt capture file; don't blow up trying 
 363            to allocate space for an immensely-large packet. */
 364          *err = WTAP_ERR_BAD_RECORD;
 365          *err_info = g_strdup_printf("visual: File has %u-byte packet, bigger than maximum of %u",
 366              packet_size, WTAP_MAX_PACKET_SIZE);
 367          return FALSE;
 368      }
 369      buffer_assure_space(wth->frame_buffer, packet_size);
 370      *data_offset = wth->data_offset;
 371      errno = WTAP_ERR_CANT_READ;
 372      bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1,
 373              packet_size, wth->fh);
 374   
 375      if (bytes_read != (int) packet_size)
 376      {
 377          *err = file_error(wth->fh);
 378          if (*err == 0)
 379              *err = WTAP_ERR_SHORT_READ;
 380          return FALSE;
 381      }
 382      wth->data_offset += packet_size;
 383   
 384      /* Set the packet time and length. */
 385      t = visual->start_time;
 386      t += ((double)pletohl(&vpkt_hdr.ts_delta))*1000;
 387      secs = (time_t)(t/1000000);
 388      usecs = (guint32)(t - secs*1000000);
 389      wth->phdr.ts.secs = secs;
 390      wth->phdr.ts.nsecs = usecs * 1000;
 391       
 392      /* Most visual capture types include FCS checks in the original length value, but 
 393      * but don't include the FCS as part of the payload or captured length.  
 394      * This causes the RTP audio payload save to fail since then captured len != orig len.
 395      * Adjusting the original length to remove the FCS bytes we counted based
 396      * on the file encapsualtion type.
 397      *
 398      * Only downside to this fix is throughput calculations will be slightly lower
 399      * as they won't include the FCS bytes.
 400      */
 401   
 402      wth->phdr.caplen = packet_size;
 403      wth->phdr.len = pletohs(&vpkt_hdr.orig_len);
 404   
 405      switch (wth->file_encap)
 406      {
 407      case WTAP_ENCAP_ETHERNET:
 408         wth->phdr.len -= 4;
 409         break;
 410       
 411      case WTAP_ENCAP_FRELAY_WITH_PHDR:
 412      case WTAP_ENCAP_CHDLC_WITH_PHDR:
 413      case WTAP_ENCAP_LAPB:
 414         wth->phdr.len -= 2;
 415         break;
 416   
 417      /* ATM original length doesn't include any FCS. Do nothing. */
 418      case WTAP_ENCAP_ATM_PDUS:
 419      /* Not sure about token ring. Just leaving alone for now. */
 420      case WTAP_ENCAP_TOKEN_RING:
 421      default:
 422         break;
 423      }
 424   
 425      /* Sanity check */
 426      if (wth->phdr.len < wth->phdr.caplen)
 427      {
 428         wth->phdr.len = wth->phdr.caplen;
 429      }
 430   
 431      /* Set the pseudo_header. */
 432      visual_set_pseudo_header(wth->file_encap, &vpkt_hdr, &vatm_hdr, &wth->pseudo_header);
 433   
 434      /* Fill in the encapsulation.  Visual files have a media type in the 
 435         file header and an encapsulation type in each packet header.  Files
 436         with a media type of HDLC can be either Cisco EtherType or PPP.
 437   
 438         The encapsulation hint values we've seen are:
 439   
 440           2 - seen in an Ethernet capture 
 441           13 - seen in a PPP capture; possibly also seen in Cisco HDLC
 442                captures 
 443           14 - seen in a PPP capture; probably seen only for PPP */
 444      if (wth->file_encap == WTAP_ENCAP_CHDLC_WITH_PHDR)
 445      {
 446          /* If PPP is specified in the encap hint, then use that */
 447          if (vpkt_hdr.encap_hint == 14)
 448          {
 449              wth->phdr.pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR;
 450          }
 451          else 
 452          {
 453              /* Otherwise, we need to examine the first two octets to 
 454                 try to determine the encapsulation. */
 455              guint8 *buf = buffer_start_ptr(wth->frame_buffer);
 456              if ((0xff == buf[0]) && (0x03 == buf[1]))
 457              {
 458                  /* It is actually PPP */
 459                  wth->phdr.pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR;
 460              }
 461          }
 462      }
 463      return TRUE;
 464  }
Show more  




Change Warning 1060.29854 : Useless Assignment

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

Priority:
State:
Finding:
Owner:
Note: