(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/pcapng.c) |
| |
| 468 | | | pcapng_read_if_descr_block(FILE_T fh, *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 | | | oh; |
| 477 | | | interface_data_t int_data; |
| 478 | | | char option_content[100]; |
| 479 | | | |
| 480 | | | |
| 481 | | | time_units_per_second = 1000000; |
| 482 | | | |
| 483 | | | errno = WTAP_ERR_CANT_READ; |
| 484 | | | bytes_read = file_read(&idb, 1, sizeof idb, fh);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/file_wrappers.h |
| |
36 | #define file_read(buf, bsize, count, file) gzread((file),(buf),(unsigned)((count)*(bsize))) |
| |
|
| 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 | | | |
| 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);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
297 | #define BSWAP32(x) \ |
298 | ((((x)&0xFF000000)>>24) | \ |
299 | (((x)&0x00FF0000)>>8) | \ |
300 | (((x)&0x0000FF00)<<8) | \ |
301 | (((x)&0x000000FF)<<24)) |
| |
|
| 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 | | | |
| 507 | | | |
| 508 | | | |
| 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 | | | |
| 513 | | | return 0; |
| 514 | | | } |
| 515 | | | |
| 516 | | | |
| 517 | | | wblock->data.if_descr. = NULL; |
| 518 | | | wblock->data.if_descr.if_name = NULL; |
| 519 | | | wblock->data.if_descr.if_description = NULL; |
| 520 | | | |
| 521 | | | |
| 522 | | | |
| 523 | | | |
| 524 | | | wblock->data.if_descr.if_speed = 0xFFFFFFFF; |
| 525 | | | wblock->data.if_descr.if_tsresol = 6; |
| 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; |
| 529 | | | |
| 530 | | | |
| 531 | | | |
| 532 | | | |
| 533 | | | errno = WTAP_ERR_CANT_READ; |
Useless Assignment
This code assigns the variable the same value it already had. |
|
| 534 | | | to_read = bh->block_total_length |
| 535 | | | - (int)sizeof() |
| 536 | | | - (int)sizeof (pcapng_interface_description_block_t) |
| 537 | | | - (int)sizeof(bh->block_total_length); |
| 538 | | | while(to_read > 0) { |
| 539 | | | |
| 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 | | | |
| 549 | | | switch(oh.option_code) { |
| 550 | | | case(0): |
| 551 | | | if(to_read != 0) { |
| 552 | | | pcapng_debug1("pcapng_read_if_descr_block: %u bytes after opt_endofopt", to_read); |
| 553 | | | } |
| 554 | | | |
| 555 | | | to_read = 0; |
| 556 | | | break; |
| 557 | | | case(1): |
| 558 | | | if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) { |
| 559 | | | wblock->data.section. = g_strndup(option_content, sizeof(option_content)); |
| 560 | | | pcapng_debug1("pcapng_read_if_descr_block: %s", wblock->data.section.); |
| 561 | | | } else { |
| 562 | | | pcapng_debug1("pcapng_read_if_descr_block: length %u seems strange", oh.option_length); |
| 563 | | | } |
| 564 | | | break; |
| 565 | | | case(2): |
| 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): |
| 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): |
| 582 | | | if(oh.option_length == 8) { |
| 583 | | | |
| 584 | | | |
| 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);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
288 | #define BSWAP64(x) \ |
289 | ((((x)&G_GINT64_CONSTANT(0xFF00000000000000U))>>56) | \ |
290 | (((x)&G_GINT64_CONSTANT(0x00FF000000000000U))>>40) | \ |
291 | (((x)&G_GINT64_CONSTANT(0x0000FF0000000000U))>>24) | \ |
292 | (((x)&G_GINT64_CONSTANT(0x000000FF00000000U))>>8) | \ |
293 | (((x)&G_GINT64_CONSTANT(0x00000000FF000000U))<<8) | \ |
294 | (((x)&G_GINT64_CONSTANT(0x0000000000FF0000U))<<24) | \ |
295 | (((x)&G_GINT64_CONSTANT(0x000000000000FF00U))<<40) | \ |
296 | (((x)&G_GINT64_CONSTANT(0x00000000000000FFU))<<56)) |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
|
| 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): |
| 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;
x /usr/include/glib-2.0/glib/gtypes.h |
| |
76 | #define G_MAXUINT64 G_GINT64_CONSTANT(0xffffffffffffffffU) |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
|
| 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): |
| 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): |
| 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 | | | |
| 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);
x /usr/include/glib-2.0/glib/garray.h |
| |
65 | #define g_array_append_val(a,v) g_array_append_vals (a, &(v), 1) |
| |
|
| 650 | | | pn->number_of_interfaces++; |
| 651 | | | return block_read; |
| 652 | | | } |
| |