netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ander Juaristi <a@juaristi.eus>
To: netfilter-devel@vger.kernel.org
Cc: Ander Juaristi <a@juaristi.eus>
Subject: [PATCH v2 2/7] nftables: meta: hour: Fix integer overflow error
Date: Wed, 26 Jun 2019 22:43:57 +0200	[thread overview]
Message-ID: <20190626204402.5257-2-a@juaristi.eus> (raw)
In-Reply-To: <20190626204402.5257-1-a@juaristi.eus>

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.

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-26 20:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-26 20:43 [PATCH v2 1/7] nftables: meta: Introduce new conditions 'time', 'day' and 'hour' Ander Juaristi
2019-06-26 20:43 ` Ander Juaristi [this message]
2019-06-26 21:07   ` [PATCH v2 2/7] nftables: meta: hour: Fix integer overflow error Florian Westphal
2019-06-26 20:43 ` [PATCH v2 3/7] nftables: meta: time: Proper handling of DST Ander Juaristi
2019-06-26 21:07   ` Florian Westphal
2019-06-27 19:10     ` Pablo Neira Ayuso
2019-06-26 20:43 ` [PATCH v2 4/7] nftables: tests/py: Add tests for day and hour Ander Juaristi
2019-06-26 21:06   ` Florian Westphal
2019-06-26 20:44 ` [PATCH v2 5/7] nftables: meta: Some small style fixes Ander Juaristi
2019-06-26 21:11   ` Florian Westphal
2019-06-26 20:44 ` [PATCH v2 6/7] nftables: Compute result modulo 86400 in case gmtoff is negative Ander Juaristi
2019-06-26 20:44 ` [PATCH v2 7/7] nftables: tests/py: More tests for day and hour Ander Juaristi
2019-06-26 21:12   ` 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=20190626204402.5257-2-a@juaristi.eus \
    --to=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 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).