Text   |  XML   |  ReML   |   Visible Warnings:

Useless Assignment  at pcapng.c:394

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

pcapng_read_section_header_block

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/pcapng.c)expand/collapse
Show more  
 321  pcapng_read_section_header_block(FILE_T fh, pcapng_block_header_t *bh,
 322                                   pcapng_t *pn, wtapng_block_t *wblock, int *err,
 323                                   gchar **err_info _U_)
 324  {
 325          int     bytes_read;
 326          int     block_read;
 327          int to_read;
 328          pcapng_section_header_block_t shb;
 329          pcapng_option_header_t oh;
 330          char option_content[100]; /* XXX - size might need to be increased, if we see longer options */
 331   
 332   
 333          /* read block content */
 334          errno = WTAP_ERR_CANT_READ;
 335          bytes_read = file_read(&shb, 1, sizeof shb, fh);
 336          if (bytes_read != sizeof shb) {
 337                  *err = file_error(fh);
 338                  if (*err != 0)
 339                          return -1;
 340                  return 0;
 341          }
 342          block_read = bytes_read;
 343   
 344          /* is the magic number one we expect? */
 345          switch(shb.magic) {
 346              case(0x1A2B3C4D):
 347                  /* this seems pcapng with correct byte order */
 348                  pn->byte_swapped                = FALSE;
 349                  pn->version_major               = shb.version_major;
 350                  pn->version_minor               = shb.version_minor;
 351   
 352                  pcapng_debug3("pcapng_read_section_header_block: SHB (little endian) V%u.%u, len %u",
 353                                  pn->version_major, pn->version_minor, bh->block_total_length);
 354                  break;
 355              case(0x4D3C2B1A):
 356                  /* this seems pcapng with swapped byte order */
 357                  pn->byte_swapped                = TRUE;
 358                  pn->version_major               = BSWAP16(shb.version_major);
 359                  pn->version_minor               = BSWAP16(shb.version_minor);
 360                           
 361                  /* tweak the block length to meet current swapping that we know now */
 362                  bh->block_total_length  = BSWAP32(bh->block_total_length);
 363   
 364                  pcapng_debug3("pcapng_read_section_header_block: SHB (big endian) V%u.%u, len %u",
 365                                  pn->version_major, pn->version_minor, bh->block_total_length);
 366                  break;
 367              default:
 368                  /* Not a "pcapng" magic number we know about. */
 369                  pcapng_debug1("pcapng_read_section_header_block: unknown magic number %u (probably not an pcapng file)", shb.magic);
 370                  return 0;
 371          }
 372   
 373          /* we currently only understand SHB V1.0 */
 374          if(pn->version_major != 1 || pn->version_minor != 0) {
 375                  pcapng_debug2("pcapng_read_section_header_block: unknown SHB version %u.%u",  
 376                                pn->version_major, pn->version_minor);
 377                  return 0;
 378          }
 379   
 380          /* 64bit section_length (currently unused) */
 381          if(pn->byte_swapped) {
 382                  wblock->data.section.section_length = BSWAP64(shb.section_length);
 383          } else {
 384                  wblock->data.section.section_length = shb.section_length;
 385          }
 386   
 387          /* Option defaults */
 388          wblock->data.section.opt_comment        = NULL;
 389          wblock->data.section.shb_hardware       = NULL;
 390          wblock->data.section.shb_os             = NULL;
 391          wblock->data.section.shb_user_appl      = NULL;
 392   
 393          /* Options */
 394          errno = WTAP_ERR_CANT_READ;
 395          to_read = bh->block_total_length
 396          - (int)sizeof(pcapng_block_header_t)  
 397          - (int)sizeof (pcapng_section_header_block_t)  
 398          - (int)sizeof(bh->block_total_length);
 399          while(to_read > 0) {
 400                  /* read option */
 401                  bytes_read = pcapng_read_option(fh, pn, &oh, option_content, sizeof(option_content), err, err_info);
 402                  if (bytes_read <= 0) {
 403                          pcapng_debug0("pcapng_read_section_header_block: failed to read option");
 404                          return bytes_read;
 405                  }
 406                  block_read += bytes_read;
 407                  to_read -= bytes_read;
 408   
 409                  /* handle option content */
 410                  switch(oh.option_code) {
 411                      case(0): /* opt_endofopt */
 412                          if(to_read != 0) {
 413                                  pcapng_debug1("pcapng_read_section_header_block: %u bytes after opt_endofopt", to_read);
 414                          }
 415                          /* padding should be ok here, just get out of this */
 416                          to_read = 0;
 417                          break;
 418                      case(1): /* opt_comment */
 419                          if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) {
 420                                  wblock->data.section.opt_comment = g_strndup(option_content, sizeof(option_content));
 421                                  pcapng_debug1("pcapng_read_section_header_block: opt_comment %s", wblock->data.section.opt_comment);
 422                          } else {
 423                                  pcapng_debug1("pcapng_read_section_header_block: opt_comment length %u seems strange", oh.option_length);
 424                          }
 425                          break;
 426                      case(2): /* shb_hardware */
 427                          if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) {
 428                                  wblock->data.section.shb_hardware = g_strndup(option_content, sizeof(option_content));
 429                                  pcapng_debug1("pcapng_read_section_header_block: shb_hardware %s", wblock->data.section.shb_hardware);
 430                          } else {
 431                                  pcapng_debug1("pcapng_read_section_header_block: shb_hardware length %u seems strange", oh.option_length);
 432                          }
 433                          break;
 434                      case(3): /* shb_os */
 435                          if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) {
 436                                  wblock->data.section.shb_os = g_strndup(option_content, sizeof(option_content));
 437                                  pcapng_debug1("pcapng_read_section_header_block: shb_os %s", wblock->data.section.shb_os);
 438                          } else {
 439                                  pcapng_debug1("pcapng_read_section_header_block: shb_os length %u seems strange", oh.option_length);
 440                          }
 441                          break;
 442                      case(4): /* shb_userappl */
 443                          if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) {
 444                                  wblock->data.section.shb_user_appl = g_strndup(option_content, sizeof(option_content));
 445                                  pcapng_debug1("pcapng_read_section_header_block: shb_userappl %s", wblock->data.section.shb_user_appl);
 446                          } else {
 447                                  pcapng_debug1("pcapng_read_section_header_block: shb_userappl length %u seems strange", oh.option_length);
 448                          }
 449                          break;
 450                      default:
 451                          pcapng_debug2("pcapng_read_section_header_block: unknown option %u - ignoring %u bytes",
 452                                        oh.option_code, oh.option_length);
 453                  }
 454          }
 455   
 456          if (pn->interface_data != NULL) {
 457                  g_array_free(pn->interface_data, TRUE);
 458          }
 459          pn->interface_data = g_array_new(FALSE, FALSE, sizeof(interface_data_t));
 460          pn->number_of_interfaces = 0;
 461   
 462          return block_read;
 463  }
Show more  




Change Warning 1041.29953 : Useless Assignment

Priority:
State:
Finding:
Owner:
Note: