test: fix 32 bit overflow in pcapng test

Message ID 20240718174253.16346-1-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series test: fix 32 bit overflow in pcapng test |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS

Commit Message

Stephen Hemminger July 18, 2024, 5:42 p.m. UTC
The conversion from seconds to nanoseconds in the pcapng test
would overflow on 32 bit platforms leading to this test failing.

Reported-by: Luca Boccassi <bluca@debian.org>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test/test_pcapng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Luca Boccassi July 18, 2024, 7:07 p.m. UTC | #1
On Thu, 18 Jul 2024 at 18:43, Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> The conversion from seconds to nanoseconds in the pcapng test
> would overflow on 32 bit platforms leading to this test failing.
>
> Reported-by: Luca Boccassi <bluca@debian.org>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  app/test/test_pcapng.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c
> index 89535efad0..2665b08c76 100644
> --- a/app/test/test_pcapng.c
> +++ b/app/test/test_pcapng.c
> @@ -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

Tested-by: Luca Boccassi <bluca@debian.org>
  
Thomas Monjalon July 29, 2024, 4:33 p.m. UTC | #2
18/07/2024 21:07, Luca Boccassi:
> On Thu, 18 Jul 2024 at 18:43, Stephen Hemminger
> <stephen@networkplumber.org> wrote:
> >
> > The conversion from seconds to nanoseconds in the pcapng test
> > would overflow on 32 bit platforms leading to this test failing.
> >
> > Reported-by: Luca Boccassi <bluca@debian.org>
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> > -       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;
> 
> Thanks this fixes the issue, the build is now green
> 
> Tested-by: Luca Boccassi <bluca@debian.org>

Applied, thanks.
  

Patch

diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c
index 89535efad0..2665b08c76 100644
--- a/app/test/test_pcapng.c
+++ b/app/test/test_pcapng.c
@@ -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];