Skip to contentSkip to conversation

test: fix 32 bit overflow in pcapng test

PATCH Applied Stephen Hemminger 3 participants 3 messages Jul 18, 2024 – Jul 29, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test: fix 32 bit overflow in pcapng test

The conversion from seconds to nanoseconds in the pcapng test would overflow on 32 bit platforms leading to this test failing.

---
 app/test/test_pcapng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test/test_pcapng.c +1 -1
index 89535efad0..2665b08c76 100644
@@ -235,7 +235,7 @@ parse_pcap_packet(u_char *user, const struct pcap_pkthdr *h,
 	 * but the file is open in nanonsecond mode therefore
 	 * the timestamp is really in timespec (ie. nanoseconds).
 	 */
-	ns = h->ts.tv_sec * NS_PER_S + h->ts.tv_usec;
+	ns = (uint64_t)h->ts.tv_sec * NS_PER_S + h->ts.tv_usec;
 	if (ns < ctx->start_ns || ns > ctx->end_ns) {
 		char tstart[128], tend[128];
 
Signature · 1 line
2.43.0
Tested-by on v1 1/1
#1 lore raw
Quoted 15 lines · Stephen Hemminger

The conversion from seconds to nanoseconds in the pcapng test would overflow on 32 bit platforms leading to this test failing.

---
 app/test/test_pcapng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test/test_pcapng.c +0 -0
index 89535efad0..2665b08c76 100644

app/test/test_pcapng.c parse_pcap_packet(u_char *user, const struct pcap_pkthdr *h, · line 240

Quoted 7 lines
app/test/test_pcapng.c +1 -1
@@ -235,7 +235,7 @@ parse_pcap_packet(u_char *user, const struct pcap_pkthdr *h,
         * but the file is open in nanonsecond mode therefore
         * the timestamp is really in timespec (ie. nanoseconds).
         */
-       ns = h->ts.tv_sec * NS_PER_S + h->ts.tv_usec;
+       ns = (uint64_t)h->ts.tv_sec * NS_PER_S + h->ts.tv_usec;
        if (ns < ctx->start_ns || ns > ctx->end_ns) {
                char tstart[128], tend[128];

Thanks this fixes the issue, the build is now green

#2 lore raw

18/07/2024 21:07, Luca Boccassi:

Quoted 12 lines

app/test/test_pcapng.c parse_pcap_packet(u_char *user, const struct pcap_pkthdr *h, · line 238

Quoted 9 lines · Stephen Hemminger

The conversion from seconds to nanoseconds in the pcapng test would overflow on 32 bit platforms leading to this test failing.

---

app/test/test_pcapng.c +1 -1
-       ns = h->ts.tv_sec * NS_PER_S + h->ts.tv_usec;
+       ns = (uint64_t)h->ts.tv_sec * NS_PER_S + h->ts.tv_usec;
Quoted 3 lines

Thanks this fixes the issue, the build is now green

Applied, thanks.