Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB0C6C48BD6 for ; Wed, 26 Jun 2019 20:44:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7C641208E3 for ; Wed, 26 Jun 2019 20:44:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726320AbfFZUoN (ORCPT ); Wed, 26 Jun 2019 16:44:13 -0400 Received: from fnsib-smtp07.srv.cat ([46.16.61.68]:34764 "EHLO fnsib-smtp07.srv.cat" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726239AbfFZUoN (ORCPT ); Wed, 26 Jun 2019 16:44:13 -0400 Received: from localhost.localdomain (unknown [47.62.206.189]) by fnsib-smtp07.srv.cat (Postfix) with ESMTPSA id 4625B819E; Wed, 26 Jun 2019 22:44:09 +0200 (CEST) From: Ander Juaristi To: netfilter-devel@vger.kernel.org Cc: Ander Juaristi Subject: [PATCH v2 2/7] nftables: meta: hour: Fix integer overflow error Date: Wed, 26 Jun 2019 22:43:57 +0200 Message-Id: <20190626204402.5257-2-a@juaristi.eus> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190626204402.5257-1-a@juaristi.eus> References: <20190626204402.5257-1-a@juaristi.eus> Reply-To: a@juaristi.eus Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org 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 --- 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