test: fix 32 bit overflow in pcapng test
Checks
Commit Message
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
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>
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.
@@ -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];