pcapng: avoid potential unaligned data
PATCH 1/1 pcapng: avoid potential unaligned data
The buffer used to construct headers (which contain 32 bit values) was declared as uint8_t which can lead to unaligned access. Change to declare buffer as uint32_t.
Signed-off-by Stephen Hemminger <[email protected]>
--- lib/pcapng/rte_pcapng.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/pcapng/rte_pcapng.c +5 -5
@@ -33,8 +33,8 @@/* conversion from DPDK speed to PCAPNG */ #define PCAPNG_MBPS_SPEED 1000000ull -/* upper bound for section, stats and interface blocks */ -#define PCAPNG_BLKSIZ 2048 +/* upper bound for section, stats and interface blocks (in uint32_t) */ +#define PCAPNG_BLKSIZ (2048 / sizeof(uint32_t))/* Format of the capture file handle */ struct rte_pcapng {
@@ -144,7 +144,7 @@ pcapng_section_block(rte_pcapng_t *self, {struct pcapng_section_header *hdr;struct pcapng_option *opt; -uint8_t buf[PCAPNG_BLKSIZ ]; +uint32_t buf[PCAPNG_BLKSIZ ];uint32_t len; len =sizeof (*hdr);
@@ -212,7 +212,7 @@ rte_pcapng_add_interface(rte_pcapng_t *self, uint16_t port,struct pcapng_option *opt;const uint8_t tsresol =9 ;/* nanosecond resolution */ uint32_t len; -uint8_t buf[PCAPNG_BLKSIZ ]; +uint32_t buf[PCAPNG_BLKSIZ ];char ifname_buf[IF_NAMESIZE ];char ifhw[256 ];uint64_t speed =0 ;
@@ -330,7 +330,7 @@ rte_pcapng_write_stats(rte_pcapng_t *self, uint16_t port_id,uint64_t start_time = self->offset_ns;uint64_t sample_time;uint32_t optlen, len; -uint8_t buf[PCAPNG_BLKSIZ ]; +uint32_t buf[PCAPNG_BLKSIZ ];RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -EINVAL );
Signature · 1 line
2.45.2
Thomas Monjalon
Applied21/11/2024 00:06, Stephen Hemminger:
Quoted 5 lines
The buffer used to construct headers (which contain 32 bit values) was declared as
uint8_twhich can lead to unaligned access. Change to declare buffer asuint32_t.Signed-off-by Stephen Hemminger <[email protected]>
Fixes dc2d6d20047e ("pcapng: avoid using alloca")
Applied, thanks.