Changes in / [823d8e1:47d64ce]
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
AUTHORS
rc7f1faf r35de364 36 36 * Anthony Coddington for adding ERF provenance support and fixing a number 37 37 of other ERF/DAG issues 38 * Tim Dawson for fixing issues with building against musl libc 38 39 * Hendrik Leppelsack for reporting and fixing some errors in the tool manpages 39 40 * Jamie Curtis for fixing a couple of bugs many many years ago -
README
r0e8f8cb r096851a 1 libtrace 4.0. 31 libtrace 4.0.4 2 2 3 3 --------------------------------------------------------------------------- -
configure.in
r823d8e1 rb6579db 4 4 # and in the README 5 5 6 AC_INIT([libtrace],[4.0. 3],[contact@wand.net.nz],[libtrace])6 AC_INIT([libtrace],[4.0.4],[contact@wand.net.nz],[libtrace]) 7 7 8 8 LIBTRACE_MAJOR=4 9 9 LIBTRACE_MID=0 10 LIBTRACE_MINOR= 310 LIBTRACE_MINOR=4 11 11 12 12 # OpenSolaris hides libraries like libncurses in /usr/gnu/lib, which is not … … 198 198 199 199 # Check for libwandio (no longer bundled with libtrace) 200 AC_CHECK_LIB(wandio,wandio_ create,wandiofound=1,wandiofound=0)200 AC_CHECK_LIB(wandio,wandio_wflush,wandiofound=1,wandiofound=0) 201 201 if test "$wandiofound" = 0; then 202 AC_MSG_ERROR(libwandio is required to compile libtrace. If you have installed itin a non-standard location please use LDFLAGS to specify the location of the library. WANDIO can be obtained from http://research.wand.net.nz/software/libwandio.php)202 AC_MSG_ERROR(libwandio 1.0.5 or better is required to compile this version of libtrace. If you have installed libwandio in a non-standard location please use LDFLAGS to specify the location of the library. WANDIO can be obtained from http://research.wand.net.nz/software/libwandio.php) 203 203 else 204 204 LIBTRACE_LIBS="$LIBTRACE_LIBS -lwandio" … … 485 485 with_numa=yes 486 486 else 487 AC_DEFINE(HAVE_LIBNUMA, 0, [Set to 1 if libnuma is supported])488 487 with_numa=no 489 488 fi … … 494 493 wandder_avail=yes 495 494 else 496 AC_DEFINE(HAVE_WANDDER, 0, [Set to 1 if libwandder is available])497 495 wandder_avail=no 498 496 fi … … 545 543 with_clock_gettime=yes 546 544 else 547 AC_DEFINE(HAVE_CLOCK_GETTIME, 0, [Set to 1 if clock_gettime is supported])548 545 with_clock_gettime=no 549 546 fi -
lib/data-struct/simple_circular_buffer.c
re8e9052 r1ed69dc 10 10 #include <fcntl.h> 11 11 #include <sys/socket.h> 12 #include <errno.h> 12 13 13 14 #include "simple_circular_buffer.h" 14 15 15 DLLEXPORT voidlibtrace_scb_init(libtrace_scb_t *buf, uint32_t size,16 DLLEXPORT int libtrace_scb_init(libtrace_scb_t *buf, uint32_t size, 16 17 uint16_t id) { 17 18 … … 28 29 buf->fd = shm_open(anonname, O_RDWR | O_CREAT, 0600); 29 30 #endif 30 ftruncate(buf->fd, size); 31 32 buf->address = mmap(NULL, 2 * size, PROT_NONE, 33 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 34 mmap(buf->address, size, PROT_READ | PROT_WRITE, 35 MAP_SHARED | MAP_FIXED, buf->fd, 0); 36 mmap(buf->address + size, size, PROT_READ | PROT_WRITE, 37 MAP_SHARED | MAP_FIXED, buf->fd, 0); 31 if (ftruncate(buf->fd, size) < 0) { 32 perror("ftruncate in libtrace_scb_init"); 33 close(buf->fd); 34 buf->fd = -1; 35 buf->address = NULL; 36 } else { 37 buf->address = mmap(NULL, 2 * size, PROT_NONE, 38 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 39 mmap(buf->address, size, PROT_READ | PROT_WRITE, 40 MAP_SHARED | MAP_FIXED, buf->fd, 0); 41 mmap(buf->address + size, size, PROT_READ | PROT_WRITE, 42 MAP_SHARED | MAP_FIXED, buf->fd, 0); 43 } 38 44 buf->read_offset = 0; 39 45 buf->write_offset = 0; 40 46 buf->count_bytes = size; 47 48 if (buf->address) { 49 return 0; 50 } 51 return -1; 41 52 } 42 53 … … 44 55 /* TODO shm_unlink the file name if we used shm_open? */ 45 56 46 munmap(buf->address, buf->count_bytes * 2); 47 close(buf->fd); 57 if (buf->address) { 58 munmap(buf->address, buf->count_bytes * 2); 59 } 60 if (buf->fd != -1) { 61 close(buf->fd); 62 } 48 63 } 49 64 … … 52 67 int space = buf->count_bytes - (buf->write_offset - buf->read_offset); 53 68 int ret; 69 70 if (buf->address == NULL) { 71 return -1; 72 } 54 73 55 74 if (space == 0) { … … 68 87 uint32_t *available) { 69 88 89 if (buf->address == NULL) { 90 return NULL; 91 } 70 92 *available = buf->write_offset - buf->read_offset; 71 93 return buf->address + buf->read_offset; -
lib/data-struct/simple_circular_buffer.h
rb94478f r1ed69dc 13 13 14 14 15 DLLEXPORT voidlibtrace_scb_init(libtrace_scb_t *buf, uint32_t size,15 DLLEXPORT int libtrace_scb_init(libtrace_scb_t *buf, uint32_t size, 16 16 uint16_t id); 17 17 DLLEXPORT void libtrace_scb_destroy(libtrace_scb_t *buf); -
lib/format_bpf.c
r32ee9b2 ra0f031b 371 371 /* TODO investigate hashing in BSD? */ 372 372 break; 373 373 case TRACE_OPTION_REPLAY_SPEEDUP: 374 break; 374 375 /* Avoid default: so that future options will cause a warning 375 376 * here to remind us to implement it, or flag it as … … 616 617 NULL, /* fin_packet */ 617 618 NULL, /* write_packet */ 619 NULL, /* flush_output */ 618 620 bpf_get_link_type, /* get_link_type */ 619 621 bpf_get_direction, /* get_direction */ -
lib/format_dpdk.c
r32ee9b2 r3b94ef2 57 57 #include <math.h> 58 58 59 #if HAVE_LIBNUMA59 #ifdef HAVE_LIBNUMA 60 60 #include <numa.h> 61 61 #endif … … 460 460 } 461 461 462 #if HAVE_LIBNUMA462 #ifdef HAVE_LIBNUMA 463 463 format_data->nic_numa_node = pci_to_numa(&use_addr); 464 464 if (my_cpu < 0) { … … 702 702 case TRACE_OPTION_META_FREQ: 703 703 case TRACE_OPTION_EVENT_REALTIME: 704 case TRACE_OPTION_REPLAY_SPEEDUP: 704 705 break; 705 706 /* Avoid default: so that future options will cause a warning … … 891 892 * these to any particular physical core */ 892 893 if (real) { 893 #if HAVE_LIBNUMA894 #ifdef HAVE_LIBNUMA 894 895 for (i = 0; i < RTE_MAX_LCORE; ++i) { 895 896 if (!rte_lcore_is_enabled(i) && numa_node_of_cpu(i) == socket) { -
lib/format_linux_common.c
rf9df20e r47d4f8c 87 87 sock = socket(PF_INET, SOCK_STREAM, 0); 88 88 memset(&ifr, 0, sizeof(struct ifreq)); 89 strncpy(ifr.ifr_name, libtrace->uridata, IF_NAMESIZE );89 strncpy(ifr.ifr_name, libtrace->uridata, IF_NAMESIZE - 1); 90 90 if (ioctl(sock, SIOCGIFHWADDR, &ifr) != 0) { 91 91 perror("Can't get HWADDR for interface"); -
lib/format_linux_ring.c
r32ee9b2 r8a63abd 61 61 ((mac) > (hdrend) && (mac) < (net) ? (mac) : (net)) 62 62 63 static pthread_mutex_t pagesize_mutex; 63 64 #ifdef HAVE_NETPACKET_PACKET_H 64 65 /* Get current frame in the ring buffer*/ … … 71 72 static int pagesize = 0; 72 73 73 static pthread_mutex_t pagesize_mutex;74 74 75 75 /* -
lib/format_pcapng.c
r32ee9b2 re9da777 173 173 }; 174 174 175 typedef struct pcapng_peeker pcapng_hdr_t; 176 175 177 176 178 #define DATA(x) ((struct pcapng_format_data_t *)((x)->format_data)) … … 287 289 288 290 static char *pcapng_parse_next_option(libtrace_t *libtrace, char **pktbuf, 289 uint16_t *code, uint16_t *length ) {291 uint16_t *code, uint16_t *length, pcapng_hdr_t *blockhdr) { 290 292 291 293 struct pcapng_optheader *opthdr = (struct pcapng_optheader *)*pktbuf; 292 294 int to_skip; 293 295 int padding = 0; 296 char *eob; //end of block 294 297 char *optval; 298 if (DATA(libtrace)->byteswapped) { 299 eob = ((char *) blockhdr) + byteswap32(blockhdr->blocklen); 300 } else { 301 eob = ((char *) blockhdr) + blockhdr->blocklen; 302 } 303 304 assert((char *)blockhdr < *pktbuf); 305 // Check if we have reached the end of the block, +4 for trailing block-size 306 // We cannot assume a endofopt, so we add one 307 if (eob == (*pktbuf) + 4) { 308 *code = 0; 309 *length = 0; 310 return *pktbuf; 311 } 312 // If there is not enough space for another header we've encountered an error 313 if (eob < (*pktbuf) + 4 + sizeof(struct pcapng_optheader)) { 314 return NULL; 315 } 295 316 296 317 if (DATA(libtrace)->byteswapped) { … … 311 332 312 333 to_skip = (*length) + padding; 334 // Check the value we return is within the block length 335 if (eob < optval + to_skip + 4) { 336 return NULL; 337 } 313 338 *pktbuf = optval + to_skip; 314 339 315 340 return optval; 316 }317 318 static inline int skip_block(libtrace_t *libtrace, uint32_t toread) {319 int err;320 321 while (toread > 0) {322 char buf[4096];323 int nextread;324 325 if (toread < 4096) {326 nextread = toread;327 } else {328 nextread = 4096;329 }330 331 err = wandio_read(libtrace->io, buf, nextread);332 if (err < 0) {333 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED,334 "Reading section header options");335 return -1;336 }337 if (err == 0) {338 return 0;339 }340 toread -= err;341 }342 343 return 1;344 345 341 } 346 342 … … 353 349 if (err < 0) { 354 350 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED, 355 "Failed to read pcapng interface options");351 "Failed reading pcapng block"); 356 352 return err; 357 353 } … … 363 359 if (err < (int)to_read) { 364 360 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 365 "Incomplete pcapng interface headerblock");361 "Incomplete pcapng block"); 366 362 return -1; 367 363 } … … 454 450 } 455 451 456 if (err < (int)(sizeof( sechdr))) {452 if (err < (int)(sizeof(pcapng_sec_t))) { 457 453 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 458 454 "Incomplete pcapng section header block"); … … 491 487 /* Read all of the options etc. -- we don't need them for now, but 492 488 * we have to skip forward to the next useful header. */ 493 bodyptr = packet->buffer + sizeof(pcapng_sec_t);489 bodyptr = (char *) packet->buffer + sizeof(pcapng_sec_t); 494 490 err = pcapng_read_body(libtrace, bodyptr, to_read); 495 491 if (err <= 0) { … … 507 503 508 504 static int pcapng_read_interface(libtrace_t *libtrace, 509 libtrace_packet_t *packet, uint32_t flags) {505 libtrace_packet_t *packet, uint32_t blocklen, uint32_t flags) { 510 506 511 507 pcapng_int_t *inthdr; 512 int err;513 uint32_t to_read;514 508 pcapng_interface_t *newint; 515 509 uint16_t optcode, optlen; … … 517 511 char *bodyptr = NULL; 518 512 519 err = wandio_read(libtrace->io, packet->buffer, sizeof(pcapng_int_t)); 520 521 if (err < 0) { 522 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED, 523 "Reading pcapng interface header block"); 524 return -1; 525 } 526 527 if (err == 0) { 528 return 0; 529 } 530 531 if (err < (int)sizeof(inthdr)) { 513 if (blocklen < sizeof(pcapng_int_t) + 4) { 532 514 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 533 515 "Incomplete pcapng interface header block"); … … 552 534 newint->snaplen = byteswap32(inthdr->snaplen); 553 535 newint->linktype = byteswap16(inthdr->linktype); 554 to_read = byteswap32(inthdr->blocklen) - sizeof(pcapng_int_t);555 536 } else { 556 537 assert(inthdr->blocktype == PCAPNG_INTERFACE_TYPE); 557 538 newint->snaplen = inthdr->snaplen; 558 539 newint->linktype = inthdr->linktype; 559 to_read = inthdr->blocklen - sizeof(pcapng_int_t);560 540 } 561 541 … … 566 546 DATA(libtrace)->allocatedinterfaces * sizeof( 567 547 pcapng_interface_t *)); 568 569 /* Could memset the new memory to zero, if required */ 548 memset(&DATA(libtrace)->interfaces[DATA(libtrace)->nextintid], 0, sizeof(void *) * 10); 570 549 } 571 550 … … 573 552 DATA(libtrace)->nextintid += 1; 574 553 575 bodyptr = packet->buffer + sizeof(pcapng_int_t); 576 err = pcapng_read_body(libtrace, bodyptr, to_read); 577 if (err <= 0) { 578 return err; 579 } 554 bodyptr = (char *) packet->buffer + sizeof(pcapng_int_t); 580 555 581 556 packet->type = TRACE_RT_PCAPNG_META; … … 588 563 do { 589 564 optval = pcapng_parse_next_option(libtrace, &bodyptr, 590 &optcode, &optlen );565 &optcode, &optlen, (pcapng_hdr_t *) packet->buffer); 591 566 if (optval == NULL) { 592 567 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, … … 608 583 } while (optcode != 0); 609 584 610 return 1;585 return (int) blocklen; 611 586 612 587 } 613 588 614 589 static int pcapng_read_nrb(libtrace_t *libtrace, libtrace_packet_t *packet, 615 uint32_t flags) {590 uint32_t blocklen, uint32_t flags) { 616 591 617 592 /* Just read the NR records and pass them off to the caller. If … … 620 595 */ 621 596 pcapng_nrb_t *hdr = NULL; 622 int err; 623 uint32_t to_read; 624 char *bodyptr; 625 626 err = wandio_read(libtrace->io, packet->buffer, sizeof(pcapng_nrb_t)); 627 628 if (err < 0) { 629 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED, "reading pcapng name resolution block"); 630 return -1; 631 } 632 633 if (err == 0) { 634 return 0; 635 } 636 637 if (err < (int)sizeof(pcapng_nrb_t)) { 597 598 if (blocklen < sizeof(pcapng_nrb_t) + 4) { 638 599 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 639 600 "Incomplete pcapng name resolution block"); … … 646 607 if (DATA(libtrace)->byteswapped) { 647 608 assert(byteswap32(hdr->blocktype) == PCAPNG_NAME_RESOLUTION_TYPE); 648 to_read = byteswap32(hdr->blocklen) - sizeof(pcapng_nrb_t);649 609 } else { 650 610 assert(hdr->blocktype == PCAPNG_NAME_RESOLUTION_TYPE); 651 to_read = hdr->blocklen - sizeof(pcapng_nrb_t);652 }653 654 bodyptr = packet->buffer + sizeof(pcapng_nrb_t);655 err = pcapng_read_body(libtrace, bodyptr, to_read);656 if (err <= 0) {657 return err;658 611 } 659 612 … … 664 617 } 665 618 666 return sizeof(pcapng_nrb_t) + to_read;619 return (int) blocklen; 667 620 668 621 } 669 622 670 623 static int pcapng_read_custom(libtrace_t *libtrace, libtrace_packet_t *packet, 671 uint32_t flags) {624 uint32_t blocklen, uint32_t flags) { 672 625 673 626 /* Just read the custom records and pass them off to the caller. If … … 676 629 */ 677 630 pcapng_custom_t *hdr = NULL; 678 int err; 679 uint32_t to_read; 680 char *bodyptr; 681 682 err = wandio_read(libtrace->io, packet->buffer, sizeof(pcapng_custom_t)); 683 684 if (err < 0) { 685 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED, "reading pcapng custom block"); 686 return -1; 687 } 688 689 if (err == 0) { 690 return 0; 691 } 692 693 if (err < (int)sizeof(pcapng_custom_t)) { 631 632 if (blocklen < sizeof(pcapng_custom_t) + 4) { 694 633 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 695 634 "Incomplete pcapng custom block"); … … 703 642 assert(byteswap32(hdr->blocktype) == PCAPNG_CUSTOM_TYPE || 704 643 byteswap32(hdr->blocktype) == PCAPNG_CUSTOM_NONCOPY_TYPE); 705 to_read = byteswap32(hdr->blocklen) - sizeof(pcapng_custom_t); 706 } else { 707 assert(hdr->blocktype == PCAPNG_NAME_RESOLUTION_TYPE || 644 } else { 645 assert(hdr->blocktype == PCAPNG_CUSTOM_TYPE || 708 646 hdr->blocktype == PCAPNG_CUSTOM_NONCOPY_TYPE); 709 to_read = hdr->blocklen - sizeof(pcapng_custom_t);710 }711 712 bodyptr = packet->buffer + sizeof(pcapng_custom_t);713 err = pcapng_read_body(libtrace, bodyptr, to_read);714 if (err <= 0) {715 return err;716 647 } 717 648 … … 722 653 } 723 654 724 return sizeof(pcapng_custom_t) + to_read;655 return (int) blocklen; 725 656 726 657 } 727 658 728 659 static int pcapng_read_stats(libtrace_t *libtrace, libtrace_packet_t *packet, 729 uint32_t flags) {660 uint32_t blocklen, uint32_t flags) { 730 661 pcapng_stats_t *hdr = NULL; 731 int err;732 uint32_t to_read;733 662 uint32_t ifaceid; 734 663 uint64_t timestamp; … … 738 667 char *bodyptr; 739 668 740 err = wandio_read(libtrace->io, packet->buffer, sizeof(pcapng_stats_t)); 741 742 if (err < 0) { 743 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED, "reading pcapng interface stats"); 744 return -1; 745 } 746 747 if (err == 0) { 748 return 0; 749 } 750 751 if (err < (int)sizeof(pcapng_stats_t)) { 669 if (blocklen < sizeof(pcapng_stats_t) + 4) { 752 670 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 753 671 "Incomplete pcapng interface stats header"); … … 760 678 if (DATA(libtrace)->byteswapped) { 761 679 assert(byteswap32(hdr->blocktype) == PCAPNG_INTERFACE_STATS_TYPE); 762 to_read = byteswap32(hdr->blocklen) - sizeof(pcapng_stats_t);763 680 ifaceid = byteswap32(hdr->interfaceid); 764 681 timestamp = ((uint64_t)(byteswap32(hdr->timestamp_high)) << 32) + byteswap32(hdr->timestamp_low); 765 682 } else { 766 683 assert(hdr->blocktype == PCAPNG_INTERFACE_STATS_TYPE); 767 to_read = hdr->blocklen - sizeof(pcapng_stats_t);768 684 ifaceid = hdr->interfaceid; 769 685 timestamp = ((uint64_t)(hdr->timestamp_high) << 32) + 770 686 hdr->timestamp_low; 771 }772 773 bodyptr = packet->buffer + sizeof(pcapng_stats_t);774 err = pcapng_read_body(libtrace, bodyptr, to_read);775 if (err <= 0) {776 return err;777 687 } 778 688 … … 791 701 792 702 if (timestamp < interface->laststats) { 793 return sizeof(pcapng_stats_t) + to_read;703 return (int) blocklen; 794 704 } 795 705 … … 799 709 do { 800 710 optval = pcapng_parse_next_option(packet->trace, &bodyptr, 801 &optcode, &optlen );711 &optcode, &optlen, (pcapng_hdr_t *) packet->buffer); 802 712 if (optval == NULL) { 803 713 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 804 "Failed to read options for pcapng enhanced packet");714 "Failed to read options for pcapng interface stats"); 805 715 return -1; 806 716 } … … 845 755 interface->laststats = timestamp; 846 756 847 return sizeof(pcapng_stats_t) + to_read;757 return (int) blocklen; 848 758 849 759 } 850 760 851 761 static int pcapng_read_simple(libtrace_t *libtrace, libtrace_packet_t *packet, 852 uint32_t flags) { 853 854 int err; 855 uint32_t to_read; 762 uint32_t blocklen, uint32_t flags) { 763 856 764 uint32_t caplen; 857 765 pcapng_spkt_t *hdr = NULL; 858 766 pcapng_interface_t *interface; 859 char *bodyptr; 860 861 err = wandio_read(libtrace->io, packet->buffer, sizeof(pcapng_spkt_t)); 862 863 if (err < 0) { 864 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED, "reading pcapng simple packet"); 865 return -1; 866 } 867 868 if (err == 0) { 869 return 0; 870 } 871 872 if (err < (int)sizeof(pcapng_spkt_t)) { 767 768 if (blocklen < sizeof(pcapng_spkt_t) + 4) { 873 769 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 874 770 "Incomplete pcapng simple packet header"); … … 881 777 if (DATA(libtrace)->byteswapped) { 882 778 assert(byteswap32(hdr->blocktype) == PCAPNG_SIMPLE_PACKET_TYPE); 883 to_read = byteswap32(hdr->blocklen) - sizeof(pcapng_spkt_t);884 caplen = to_read - 4;/* account for trailing length field */779 caplen = byteswap32(hdr->blocklen) - sizeof(pcapng_spkt_t) - 4; 780 /* account for trailing length field */ 885 781 } else { 886 782 assert(hdr->blocktype == PCAPNG_SIMPLE_PACKET_TYPE); 887 to_read = hdr->blocklen - sizeof(pcapng_spkt_t); 888 caplen = to_read - 4; /* account for trailing length field */ 889 } 890 891 bodyptr = packet->buffer + sizeof(pcapng_spkt_t); 892 err = pcapng_read_body(libtrace, bodyptr, to_read); 893 if (err <= 0) { 894 return err; 783 caplen = hdr->blocklen - sizeof(pcapng_spkt_t) - 4; 784 /* account for trailing length field */ 895 785 } 896 786 … … 912 802 return -1; 913 803 } 914 return sizeof(pcapng_spkt_t) + to_read;804 return (int) blocklen; 915 805 916 806 } 917 807 918 808 static int pcapng_read_enhanced(libtrace_t *libtrace, libtrace_packet_t *packet, 919 uint32_t flags) {809 uint32_t blocklen, uint32_t flags) { 920 810 pcapng_epkt_t *hdr = NULL; 921 int err;922 uint32_t to_read;923 811 uint32_t caplen; 924 812 uint32_t ifaceid; … … 928 816 char *bodyptr; 929 817 930 err = wandio_read(libtrace->io, packet->buffer, sizeof(pcapng_epkt_t)); 931 932 if (err < 0) { 933 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED, "reading pcapng enhanced packet"); 934 return -1; 935 } 936 937 if (err == 0) { 938 return 0; 939 } 940 941 if (err < (int)sizeof(pcapng_epkt_t)) { 818 if (blocklen < (int)sizeof(pcapng_epkt_t) + 4) { 942 819 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 943 820 "Incomplete pcapng enhanced packet header"); … … 951 828 assert(byteswap32(hdr->blocktype) == PCAPNG_ENHANCED_PACKET_TYPE); 952 829 caplen = byteswap32(hdr->caplen); 953 to_read = byteswap32(hdr->blocklen) - sizeof(pcapng_epkt_t);954 830 ifaceid = byteswap32(hdr->interfaceid); 955 831 } else { 956 832 assert(hdr->blocktype == PCAPNG_ENHANCED_PACKET_TYPE); 957 833 caplen = hdr->caplen; 958 to_read = hdr->blocklen - sizeof(pcapng_epkt_t);959 834 ifaceid = hdr->interfaceid; 960 835 } 961 836 962 bodyptr = packet->buffer + sizeof(pcapng_epkt_t); 963 err = pcapng_read_body(libtrace, bodyptr, to_read); 964 if (err <= 0) { 965 return err; 966 } 837 bodyptr = (char *) packet->buffer + sizeof(pcapng_epkt_t); 967 838 968 839 /* Set packet type based on interface linktype */ … … 985 856 /* Make sure to parse any useful options */ 986 857 if ((caplen % 4) == 0) { 987 bodyptr = packet->payload + caplen; 988 } else { 989 bodyptr = packet->payload + caplen + (4 - (caplen % 4)); 858 bodyptr = (char *) packet->payload + caplen; 859 } else { 860 bodyptr = (char *) packet->payload + caplen + (4 - (caplen % 4)); 861 } 862 // Check the packet caplen actually fits within the block we read 863 if ((char *) packet->buffer + blocklen < bodyptr + 4) { 864 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 865 "Incomplete pcapng enhanced packet header"); 866 return -1; 990 867 } 991 868 992 869 do { 993 870 optval = pcapng_parse_next_option(packet->trace, &bodyptr, 994 &optcode, &optlen );871 &optcode, &optlen, (pcapng_hdr_t *) packet->buffer); 995 872 if (optval == NULL) { 996 873 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, … … 1009 886 1010 887 } while (optcode != 0); 1011 return sizeof(pcapng_epkt_t) + to_read;888 return (int) blocklen; 1012 889 1013 890 } … … 1053 930 } 1054 931 932 // Warning: the byteorder might not be set yet, the section header sets this 1055 933 if (DATA(libtrace)->byteswapped) { 1056 934 btype = byteswap32(peeker.blocktype); 935 to_read = byteswap32(peeker.blocklen); 1057 936 } else { 1058 937 btype = peeker.blocktype; 938 to_read = peeker.blocklen; 939 } 940 941 // Check we won't read off the end of the packet buffer. Assuming corruption. 942 // Exclude the SECTION header, as this is used to identify the byteorder 943 if (to_read > LIBTRACE_PACKET_BUFSIZE && btype != PCAPNG_SECTION_TYPE) { 944 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 945 "Oversized pcapng block found, is the trace corrupted?"); 946 return -1; 947 } 948 if (btype != PCAPNG_SECTION_TYPE) { 949 // Read the entire block, unless it is a section as our byte ordering has 950 // not been set yet. 951 err = pcapng_read_body(libtrace, packet->buffer, to_read); 952 if (err <= 0) { 953 return err; 954 } 955 if (*((uint32_t *)((char *)packet->buffer+to_read-4)) != peeker.blocklen) { 956 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 957 "Mismatched pcapng block sizes found, trace is invalid."); 958 return -1; 959 } 1059 960 } 1060 961 … … 1068 969 /* Interface Header */ 1069 970 case PCAPNG_INTERFACE_TYPE: 1070 err = pcapng_read_interface(libtrace, packet, flags);971 err = pcapng_read_interface(libtrace, packet, to_read, flags); 1071 972 gotpacket = 1; 1072 973 break; … … 1075 976 case PCAPNG_ENHANCED_PACKET_TYPE: 1076 977 err = pcapng_read_enhanced(libtrace, packet, 1077 flags);978 to_read, flags); 1078 979 gotpacket = 1; 1079 980 break; 1080 981 1081 982 case PCAPNG_SIMPLE_PACKET_TYPE: 1082 err = pcapng_read_simple(libtrace, packet, flags);983 err = pcapng_read_simple(libtrace, packet, to_read, flags); 1083 984 gotpacket = 1; 1084 985 break; 1085 986 1086 987 case PCAPNG_INTERFACE_STATS_TYPE: 1087 err = pcapng_read_stats(libtrace, packet, flags);988 err = pcapng_read_stats(libtrace, packet, to_read, flags); 1088 989 gotpacket = 1; 1089 990 break; 1090 991 1091 992 case PCAPNG_NAME_RESOLUTION_TYPE: 1092 err = pcapng_read_nrb(libtrace, packet, flags);993 err = pcapng_read_nrb(libtrace, packet, to_read, flags); 1093 994 gotpacket = 1; 1094 995 break; … … 1096 997 case PCAPNG_CUSTOM_TYPE: 1097 998 case PCAPNG_CUSTOM_NONCOPY_TYPE: 1098 err = pcapng_read_custom(libtrace, packet, flags);999 err = pcapng_read_custom(libtrace, packet, to_read, flags); 1099 1000 gotpacket = 1; 1100 1001 break; … … 1106 1007 /* Everything else -- don't care, skip it */ 1107 1008 default: 1108 if (DATA(libtrace)->byteswapped) {1109 to_read = byteswap32(peeker.blocklen);1110 } else {1111 to_read = peeker.blocklen;1112 }1113 err = skip_block(libtrace, to_read);1114 1009 break; 1115 1010 } -
lib/libtrace.h.in
r32ee9b2 r47d4f8c 277 277 typedef struct trace_err_t{ 278 278 int err_num; /**< error code */ 279 char problem[ 255]; /**< the format, uri etc that caused the error for reporting purposes */279 char problem[1024]; /**< the format, uri etc that caused the error for reporting purposes */ 280 280 } libtrace_err_t; 281 281 -
lib/protocols_pktmeta.c
r691b182 r59b2ed8 142 142 143 143 #else 144 *remaining = NULL; 144 (void)link; 145 (void)type; 146 *remaining = 0; 145 147 return NULL; 146 148 #endif -
lib/trace.c
r32ee9b2 r47d4f8c 107 107 * will use our own one that does 108 108 */ 109 static void xstrncpy(char *dest, const char *src, size_t n) 110 { 111 strncpy(dest,src,n); 112 dest[n]='\0'; 109 static inline void xstrncpy(char *dest, const char *src, size_t n, 110 size_t destlen) 111 { 112 size_t slen = destlen - 1; 113 if (n < slen) { 114 slen = n; 115 } 116 strncpy(dest,src,slen); 117 dest[slen]='\0'; 113 118 } 114 119 … … 120 125 exit(EXIT_FAILURE); 121 126 } 122 xstrncpy(ret,src,n );127 xstrncpy(ret,src,n,n+1); 123 128 return ret; 124 129 } … … 371 376 372 377 if((uridata = strchr(uri,':')) == NULL) { 373 xstrncpy(scan, uri, strlen(uri) );378 xstrncpy(scan, uri, strlen(uri), URI_PROTO_LINE); 374 379 } else { 375 xstrncpy(scan,uri, (size_t)(uridata - uri) );380 xstrncpy(scan,uri, (size_t)(uridata - uri), URI_PROTO_LINE); 376 381 } 377 382 -
lib/trace_parallel.c
r8a237c7 rc95ef4a 690 690 if (!trace->pread) { 691 691 assert(packets[0]); 692 ASSERT_RET(pthread_mutex_lock(&trace->libtrace_lock), == 0);693 692 nb_packets = trace_read_packet(trace, packets[0]); 694 ASSERT_RET(pthread_mutex_unlock(&trace->libtrace_lock), == 0);695 693 packets[0]->error = nb_packets; 696 694 if (nb_packets > 0) -
libpacketdump/Makefile.am
ra82a9e8 r055a2c9 62 62 63 63 # 22: ETSI LI 64 if HAVE_WANDDER 64 65 BIN_PROTOCOLS+=link_22.la 66 endif 65 67 66 68 # Decoders for various ethertypes (in decimal) … … 138 140 link_11_la_LDFLAGS=$(modflags) 139 141 link_15_la_LDFLAGS=$(modflags) 142 if HAVE_WANDDER 140 143 link_22_la_LDFLAGS=$(modflags) 144 endif 141 145 eth_0_la_LDFLAGS=$(modflags) 142 146 eth_2048_la_LDFLAGS=$(modflags) -
libpacketdump/eth_2054.c
ree6e802 r47d4f8c 47 47 static char *format_hrd(const struct arphdr *arp, const char *hrd) { 48 48 static char buffer[1024] = {0,}; 49 int i; 49 int i, ret; 50 size_t bufused; 50 51 51 52 if (!hrd) { … … 59 60 break; 60 61 default: 62 bufused = 0; 61 63 for (i=0;i<arp->ar_hln;i++) { 62 snprintf(buffer,sizeof(buffer),"%s %02x", 63 buffer,(unsigned char)hrd[i]); 64 if (bufused >= sizeof(buffer)) { 65 break; 66 } 67 ret = snprintf(buffer + bufused, 68 sizeof(buffer) - bufused, 69 "%02x ", 70 (unsigned char)hrd[i]); 71 if (ret > 0) { 72 bufused += ret; 73 } 64 74 } 65 75 break; … … 77 87 static char *format_pro(const struct arphdr *arp, const char *pro) { 78 88 static char buffer[1024] = {0,}; 79 int i; 89 int i, ret; 90 size_t bufused; 80 91 81 92 if (!pro) { … … 91 102 default: 92 103 snprintf(buffer, sizeof(buffer), "%s", " ("); 104 bufused = 2; 93 105 for (i=0;i<arp->ar_pln;i++) { 94 snprintf(buffer,sizeof(buffer),"%s %02x", 95 buffer,(unsigned char)pro[i]); 106 if (bufused >= sizeof(buffer)) { 107 break; 108 } 109 ret = snprintf(buffer + bufused, 110 sizeof(buffer) - bufused, 111 "%02x ", 112 (unsigned char)pro[i]); 113 if (ret > 0) { 114 bufused += ret; 115 } 96 116 } 97 strncat(buffer,")",sizeof(buffer) - strlen(buffer) - 1); 117 if (bufused < sizeof(buffer)) { 118 snprintf(buffer + bufused, 119 sizeof(buffer) - bufused, 120 ")"); 121 } 98 122 break; 99 123 } -
tools/tracereport/misc_report.c
r8e11beb r47d4f8c 67 67 { 68 68 static char ret[1024]; 69 char tmp[1 024];69 char tmp[128]; 70 70 ret[0]='\0'; 71 71 if (ts == 0) -
tools/tracesplit/tracesplit.c
r92cf299 r47d4f8c 61 61 static char *strdupcat(char *str,char *app) 62 62 { 63 str=realloc(str,strlen(str)+strlen(app)+1); 64 strncat(str,app,strlen(str) + strlen(app)); 63 int newsize = strlen(str)+strlen(app)+1; 64 str=realloc(str,newsize); 65 strncat(str,app,newsize - strlen(str) - 1); 65 66 return str; 66 67 }
Note: See TracChangeset
for help on using the changeset viewer.