Text   |  XML   |  ReML   |   Visible Warnings:

Useless Assignment  at pcapng.c:533

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

pcapng_read_if_descr_block

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/pcapng.c)expand/collapse
Show more  
 468  pcapng_read_if_descr_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn,
 469                             wtapng_block_t *wblock, int *err, gchar **err_info _U_)
 470  {
 471          guint64 time_units_per_second;
 472          int     bytes_read;
 473          int     block_read;
 474          int to_read;
 475          pcapng_interface_description_block_t idb;
 476          pcapng_option_header_t oh;
 477          interface_data_t int_data;
 478          char option_content[100]; /* XXX - size might need to be increased, if we see longer options */
 479   
 480   
 481          time_units_per_second = 1000000; /* default */
 482          /* read block content */
 483          errno = WTAP_ERR_CANT_READ;
 484          bytes_read = file_read(&idb, 1, sizeof idb, fh);
 485          if (bytes_read != sizeof idb) {
 486                  pcapng_debug0("pcapng_read_if_descr_block: failed to read IDB");
 487                  *err = file_error(fh);
 488                  if (*err != 0)
 489                          return -1;
 490                  return 0;
 491          }
 492          block_read = bytes_read;
 493   
 494          /* mandatory values */
 495          if(pn->byte_swapped) {
 496                  wblock->data.if_descr.link_type = BSWAP16(idb.linktype);
 497                  wblock->data.if_descr.snap_len  = BSWAP32(idb.snaplen);
 498          } else {
 499                  wblock->data.if_descr.link_type = idb.linktype;
 500                  wblock->data.if_descr.snap_len  = idb.snaplen;
 501          }
 502   
 503          pcapng_debug2("pcapng_read_if_descr_block: IDB link_type %u, snap %u",
 504                        wblock->data.if_descr.link_type, wblock->data.if_descr.snap_len);
 505   
 506          /* XXX - sanity check of snapshot length */
 507          /* XXX - while a very big snapshot length is valid, it's more likely that it's a bug in the file */
 508          /* XXX - so do a sanity check for now, it's likely e.g. a byte swap order problem */
 509          if(wblock->data.if_descr.snap_len > WTAP_MAX_PACKET_SIZE) {
 510                  pcapng_debug1("pcapng_read_if_descr_block: snapshot length %u unrealistic",  
 511                                wblock->data.if_descr.snap_len);
 512                  /*wblock->data.if_descr.snap_len = 65535;*/
 513                  return 0;
 514          }
 515   
 516          /* Option defaults */
 517          wblock->data.if_descr.opt_comment       = NULL;
 518          wblock->data.if_descr.if_name           = NULL;
 519          wblock->data.if_descr.if_description    = NULL;
 520          /* XXX: if_IPv4addr */
 521          /* XXX: if_IPv6addr */
 522          /* XXX: if_MACaddr */
 523          /* XXX: if_EUIaddr */
 524          wblock->data.if_descr.if_speed          = 0xFFFFFFFF;   /* "unknown" */
 525          wblock->data.if_descr.if_tsresol        = 6;            /* default is 6 for microsecond resolution */
 526          wblock->data.if_descr.if_filter         = NULL;
 527          wblock->data.if_descr.if_os             = NULL;
 528          wblock->data.if_descr.if_fcslen         = (gchar) -1;   /* unknown or changes between packets */
 529          /* XXX: guint64 if_tsoffset; */
 530   
 531   
 532          /* Options */
 533          errno = WTAP_ERR_CANT_READ;
 534          to_read = bh->block_total_length  
 535          - (int)sizeof(pcapng_block_header_t)  
 536          - (int)sizeof (pcapng_interface_description_block_t)  
 537          - (int)sizeof(bh->block_total_length);
 538          while(to_read > 0) {
 539                  /* read option */
 540                  bytes_read = pcapng_read_option(fh, pn, &oh, option_content, sizeof(option_content), err, err_info);
 541                  if (bytes_read <= 0) {
 542                          pcapng_debug0("pcapng_read_if_descr_block: failed to read option");
 543                          return bytes_read;
 544                  }
 545                  block_read += bytes_read;
 546                  to_read -= bytes_read;
 547   
 548                  /* handle option content */
 549                  switch(oh.option_code) {
 550                      case(0): /* opt_endofopt */
 551                          if(to_read != 0) {
 552                                  pcapng_debug1("pcapng_read_if_descr_block: %u bytes after opt_endofopt", to_read);
 553                          }
 554                          /* padding should be ok here, just get out of this */
 555                          to_read = 0;
 556                          break;
 557                      case(1): /* opt_comment */
 558                          if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) {
 559                                  wblock->data.section.opt_comment = g_strndup(option_content, sizeof(option_content));
 560                                  pcapng_debug1("pcapng_read_if_descr_block: opt_comment %s", wblock->data.section.opt_comment);
 561                          } else {
 562                                  pcapng_debug1("pcapng_read_if_descr_block: opt_comment length %u seems strange", oh.option_length);
 563                          }
 564                          break;
 565                      case(2): /* if_name */
 566                          if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) {
 567                                  wblock->data.if_descr.if_name = g_strndup(option_content, sizeof(option_content));
 568                                  pcapng_debug1("pcapng_read_if_descr_block: if_name %s", wblock->data.if_descr.if_name);
 569                          } else {
 570                                  pcapng_debug1("pcapng_read_if_descr_block: if_name length %u seems strange", oh.option_length);
 571                          }
 572                          break;
 573                      case(3): /* if_description */
 574                          if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) {
 575                              wblock->data.if_descr.if_description = g_strndup(option_content, sizeof(option_content));
 576                                  pcapng_debug1("pcapng_read_if_descr_block: if_description %s", wblock->data.if_descr.if_description);
 577                          } else {
 578                                  pcapng_debug1("pcapng_read_if_descr_block: if_description length %u seems strange", oh.option_length);
 579                          }
 580                          break;
 581                      case(8): /* if_speed */
 582                          if(oh.option_length == 8) {
 583                                  /*  Don't cast a char[] into a guint64--the
 584                                   *  char[] may not be aligned correctly.
 585                                   */
 586                                  memcpy(&wblock->data.if_descr.if_speed, option_content, sizeof(guint64));
 587                                  if(pn->byte_swapped)  
 588                                          wblock->data.if_descr.if_speed = BSWAP64(wblock->data.if_descr.if_speed);
 589                                  pcapng_debug1("pcapng_read_if_descr_block: if_speed %" G_GINT64_MODIFIER "u (bps)", wblock->data.if_descr.if_speed);
 590                          } else {
 591                                      pcapng_debug1("pcapng_read_if_descr_block: if_speed length %u not 8 as expected", oh.option_length);
 592                          }
 593                          break;
 594                      case(9): /* if_tsresol */
 595                          if (oh.option_length == 1) {
 596                                  guint64 base;
 597                                  guint64 result;
 598                                  guint8 i, exponent;
 599   
 600                                  wblock->data.if_descr.if_tsresol = option_content[0];
 601                                  if (wblock->data.if_descr.if_tsresol & 0x80) {
 602                                          base = 2;
 603                                  } else {
 604                                          base = 10;
 605                                  }
 606                                  exponent = (guint8)(wblock->data.if_descr.if_tsresol & 0x7f);
 607                                  if (((base == 2) && (exponent < 64)) || ((base == 10) && (exponent < 20))) {
 608                                          result = 1;
 609                                          for (i = 0; i < exponent; i++) {
 610                                                  result *= base;
 611                                          }
 612                                          time_units_per_second = result;
 613                                  } else {
 614                                          time_units_per_second = G_MAXUINT64;
 615                                  }
 616                                  if (time_units_per_second > (((guint64)1) << 32)) {
 617                                          pcapng_debug0("pcapng_open: time conversion might be inaccurate");
 618                                  }
 619                                  pcapng_debug1("pcapng_read_if_descr_block: if_tsresol %u", wblock->data.if_descr.if_tsresol);
 620                          } else {
 621                                  pcapng_debug1("pcapng_read_if_descr_block: if_tsresol length %u not 1 as expected", oh.option_length);
 622                          }
 623                          break;
 624                      case(11): /* if_filter */
 625                          if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) {
 626                                  wblock->data.if_descr.if_filter = g_strndup(option_content, sizeof(option_content));
 627                                  pcapng_debug1("pcapng_read_if_descr_block: if_filter %s", wblock->data.if_descr.if_filter);
 628                          } else {
 629                                  pcapng_debug1("pcapng_read_if_descr_block: if_filter length %u seems strange", oh.option_length);
 630                          }
 631                          break;
 632                      case(13): /* if_fcslen */
 633                          if(oh.option_length == 1) {
 634                                  wblock->data.if_descr.if_fcslen = option_content[0];
 635                                  pn->if_fcslen = wblock->data.if_descr.if_fcslen;
 636                                  pcapng_debug1("pcapng_read_if_descr_block: if_fcslen %u", wblock->data.if_descr.if_fcslen);
 637                                  /* XXX - add sanity check */
 638                          } else {
 639                                  pcapng_debug1("pcapng_read_if_descr_block: if_fcslen length %u not 1 as expected", oh.option_length);
 640                          }
 641                          break;
 642                      default:
 643                          pcapng_debug2("pcapng_read_if_descr_block: unknown option %u - ignoring %u bytes",
 644                                        oh.option_code, oh.option_length);
 645                  }
 646          }
 647          int_data.wtab_encap = wtap_pcap_encap_to_wtap_encap(wblock->data.if_descr.link_type);
 648          int_data.time_units_per_second = time_units_per_second;
 649          g_array_append_val(pn->interface_data, int_data);
 650          pn->number_of_interfaces++;
 651          return block_read;
 652  }
Show more  




Change Warning 1042.29955 : Useless Assignment

Priority:
State:
Finding:
Owner:
Note: