* [PATCH] pcapng: avoid potential unaligned data
@ 2024-11-20 23:06 Stephen Hemminger
2024-11-26 19:22 ` Thomas Monjalon
0 siblings, 1 reply; 2+ messages in thread
From: Stephen Hemminger @ 2024-11-20 23:06 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger
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 <stephen@networkplumber.org>
---
lib/pcapng/rte_pcapng.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c
index e5326c1d38..16485b27cb 100644
--- a/lib/pcapng/rte_pcapng.c
+++ b/lib/pcapng/rte_pcapng.c
@@ -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);
--
2.45.2
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-11-26 19:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-20 23:06 [PATCH] pcapng: avoid potential unaligned data Stephen Hemminger
2024-11-26 19:22 ` Thomas Monjalon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).