All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Ander Juaristi <a@juaristi.eus>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH 2/2] meta: hour: Fix integer overflow error
Date: Tue, 25 Jun 2019 02:21:25 +0200	[thread overview]
Message-ID: <20190625002125.k6yphdm2l3ne4k2u@salvia> (raw)
In-Reply-To: <20190623162544.11604-2-a@juaristi.eus>

On Sun, Jun 23, 2019 at 06:25:44PM +0200, Ander Juaristi wrote:
> This patch fixes an overflow error that would happen when introducing edge times
> whose second representation is smaller than the value of the tm_gmtoff field, such
> as 00:00.

Please, send a v2 that includes a test for this to tests/py/

Thanks.

> Signed-off-by: Ander Juaristi <a@juaristi.eus>
> ---
>  src/meta.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/src/meta.c b/src/meta.c
> index 31a86b2..39e551c 100644
> --- a/src/meta.c
> +++ b/src/meta.c
> @@ -565,7 +565,7 @@ static void hour_type_print(const struct expr *expr, struct output_ctx *octx)
>  		cur_tm = localtime(&ts);
>  
>  		if (cur_tm)
> -			seconds += cur_tm->tm_gmtoff;
> +			seconds = (seconds + cur_tm->tm_gmtoff) % 86400;
>  
>  		__hour_type_print_r(0, 0, seconds, out);
>  		nft_print(octx, "\"%s\"", out);
> @@ -616,8 +616,12 @@ convert:
>  		result = tm.tm_hour * 3600 + tm.tm_min * 60 + tm.tm_sec;
>  
>  	/* Substract tm_gmtoff to get the current time */
> -	if (cur_tm)
> -		result -= cur_tm->tm_gmtoff;
> +	if (cur_tm) {
> +		if (result >= cur_tm->tm_gmtoff)
> +			result -= cur_tm->tm_gmtoff;
> +		else
> +			result = 86400 - cur_tm->tm_gmtoff + result;
> +	}
>  
>  success:
>  	*res = constant_expr_alloc(&sym->location, sym->dtype,
> -- 
> 2.17.1
> 

  reply	other threads:[~2019-06-25  0:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-23 16:25 [PATCH 1/2] meta: Introduce new conditions 'time', 'day' and 'hour' Ander Juaristi
2019-06-23 16:25 ` [PATCH 2/2] meta: hour: Fix integer overflow error Ander Juaristi
2019-06-25  0:21   ` Pablo Neira Ayuso [this message]
2019-06-23 23:33 ` [PATCH 1/2] meta: Introduce new conditions 'time', 'day' and 'hour' Florian Westphal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190625002125.k6yphdm2l3ne4k2u@salvia \
    --to=pablo@netfilter.org \
    --cc=a@juaristi.eus \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.