From patchwork Wed Oct 10 01:26:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lev Stipakov X-Patchwork-Id: 535 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id IEy3J67wvVvxBAAAIUCqbw for ; Wed, 10 Oct 2018 08:29:34 -0400 Received: from proxy6.mail.iad3b.rsapps.net ([172.31.255.6]) by director11.mail.ord1d.rsapps.net with LMTP id oB7bJK7wvVvjbwAAvGGmqA ; Wed, 10 Oct 2018 08:29:34 -0400 Received: from smtp30.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy6.mail.iad3b.rsapps.net with LMTP id mPM2H67wvVvcCAAARawThA ; Wed, 10 Oct 2018 08:29:34 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp30.gate.iad3b.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=gmail.com; dmarc=fail (p=none; dis=none) header.from=gmail.com X-Suspicious-Flag: YES X-Classification-ID: 24a50772-cc88-11e8-859a-525400502618-1-1 Received: from [216.105.38.7] ([216.105.38.7:57699] helo=lists.sourceforge.net) by smtp30.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id FD/DB-26546-EA0FDBB5; Wed, 10 Oct 2018 08:29:34 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1gADbh-0005fn-SX; Wed, 10 Oct 2018 12:28:53 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1gADbg-0005fd-Nh for openvpn-devel@lists.sourceforge.net; Wed, 10 Oct 2018 12:28:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:To: From:Sender:Reply-To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=RyPRyJBJhfW2cPIeolw/avPW62CR5lU2TPY9TVo/uHU=; b=h8X5ZPS34v+JEC3Vee/+0sBVaK 4Tt8UrPXwMQESpn4QU9iO/OSVH8XROh0FgB20x+0W4LFW7Ek6u6b5hY7h9LUFgb1HOSmAgsAtHAzQ xhfNFuAhC7YzRMJ/xlBcnTIVB7yUAXLigbt8BPu65OZyyUF0M3fF6HQG9QttIIOdTxRc=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc :MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=RyPRyJBJhfW2cPIeolw/avPW62CR5lU2TPY9TVo/uHU=; b=GBu+ZSA+v9MNcjfCvdUkgE4YP9 8KhC7wosZDn/ju3X6Mdbw+sgiCyQM8uBfnkpSXbNeXu6b+4oFK3etLmwB907O12Uc0rz7KrfftBcz 45lWAh6YDYuYrKDYvsLJhtakqG6Cb4OqnAHMcwAPqSLADkkSnARe/MF36YQ61ButG0Jk=; Received: from mail-ed1-f43.google.com ([209.85.208.43]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) id 1gADbX-004zDZ-Ak for openvpn-devel@lists.sourceforge.net; Wed, 10 Oct 2018 12:28:52 +0000 Received: by mail-ed1-f43.google.com with SMTP id g32-v6so4723324edg.13 for ; Wed, 10 Oct 2018 05:28:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=RyPRyJBJhfW2cPIeolw/avPW62CR5lU2TPY9TVo/uHU=; b=mr50LF2Nfx7LK7hbWv/O69kDxBtPCPoGiMQK/31a0ncgWb9fLXRyEHPjwBsF8lgIhQ CdbPNWuskhr3T2CYMnfQIhIxqW5/D9V3HKcHliCZTUSlEoT/X9YJ1nKgIR4zgWXjE/8y JH6MR+ZNshq8GqbcpsNbdB8gZc+cBxP+E4yQM5K1WvHsTPlcqo6pUNpydfEJAcNGv3UI HgGC7FnCFR4n6LvLxhRnJCxzicff6srHKy2MQ/rw/KPNvXX+Wiu3blo8tgP6W1iMiP7g YlZSfUNTulmSnLwZmIx87tUVb4ypdXQ1gde2BDsw3jkWfNKjR9x9ZuaraD0ugHyrHbYk aKSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=RyPRyJBJhfW2cPIeolw/avPW62CR5lU2TPY9TVo/uHU=; b=WepcsaKmRCXWy4AnhOT1gpz5VlugVQRs0nA/1uXzg0WweCgM6q8dw++lrGz9ZnHCdt VNgX6i6ZsiX2JqvyM7wNL4tbnkYiJUVpcMOoYKaFg3+rOpFJNoeT6iIc4OBrgFPH0yna b2IkSMrebUCd9wG2dCHxZVBGWKHxIDV840LnWB4ILNvuEOcrSPsON80RsTTewB1g8Kq6 onBaFqTproDAPsTlGv2vssuHg05QQKD/EKOxcOHiVqQBA6QMY1Hcyr2W/iNdt5nu6jAR HSmp/iuTGuoLCQdoRJ50/JJFg9cqQfYsUUQ+Tvd0cpjCXPU9PiAE566c8hQItti/JqyA 6IYQ== X-Gm-Message-State: ABuFfogTuSkmUmllr3Zojyz7to4h9zUREYKnaMAo2eFLl6x3AsdqZAn3 X2bZMeSD4sOPGIiIyNnbwgt3wYXl X-Google-Smtp-Source: ACcGV60cwA9vdskwyoULfZpUsuw1cXGkf6VKj1hjPkAgodn9z8LA7ZKx9crkM3bqQ2IYa8IfH5YAsA== X-Received: by 2002:a50:fb8a:: with SMTP id e10-v6mr27885044edq.153.1539174516231; Wed, 10 Oct 2018 05:28:36 -0700 (PDT) Received: from stipakov.fi (stipakov.fi. [128.199.52.117]) by smtp.gmail.com with ESMTPSA id i6-v6sm3870022eja.63.2018.10.10.05.28.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Oct 2018 05:28:35 -0700 (PDT) From: Lev Stipakov To: openvpn-devel@lists.sourceforge.net Date: Wed, 10 Oct 2018 15:26:17 +0300 Message-Id: <1539174377-2678-1-git-send-email-lstipakov@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.208.43 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (lstipakov[at]gmail.com) -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.208.43 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-Headers-End: 1gADbX-004zDZ-Ak Subject: [Openvpn-devel] [PATCH v2] options.c: fix broken unary minus usage X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Lev Stipakov In Visual Studio when unary minus is applied to unsigned, result is still unsigned. This means that when we use result as function formal parameter, we pass incorrect value. Fix by introducing frame_remove_from_extra_frame function, which makes code semantically more clear and eliminates the need in negative value and cast. Since GCC didn't complain (and users too :), it probably performed cast to signed automatically. Signed-off-by: Lev Stipakov Acked-By: Arne Schwabe --- v2: use frame_remove_from_extra_frame instead of passing negative value src/openvpn/crypto.c | 2 +- src/openvpn/init.c | 2 +- src/openvpn/mtu.h | 8 +++++++- src/openvpn/options.c | 2 +- src/openvpn/ssl.c | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index 6d34acd..b1d6780 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -722,7 +722,7 @@ crypto_adjust_frame_parameters(struct frame *frame, crypto_overhead += kt->hmac_length; - frame_add_to_extra_frame(frame, crypto_overhead); + frame_add_to_extra_frame(frame, (unsigned int) crypto_overhead); msg(D_MTU_DEBUG, "%s: Adjusting frame parameters for crypto by %u bytes", __func__, (unsigned int) crypto_overhead); diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 52c64da..fe70175 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -2675,7 +2675,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) if (c->options.pull || c->options.mode == MODE_SERVER) { /* Account for worst-case crypto overhead before allocating buffers */ - frame_add_to_extra_frame(&c->c2.frame, crypto_max_overhead()); + frame_add_to_extra_frame(&c->c2.frame, (unsigned int) crypto_max_overhead()); } else { diff --git a/src/openvpn/mtu.h b/src/openvpn/mtu.h index a82154a..690eb81 100644 --- a/src/openvpn/mtu.h +++ b/src/openvpn/mtu.h @@ -271,12 +271,18 @@ frame_add_to_link_mtu(struct frame *frame, const int increment) } static inline void -frame_add_to_extra_frame(struct frame *frame, const int increment) +frame_add_to_extra_frame(struct frame *frame, const unsigned int increment) { frame->extra_frame += increment; } static inline void +frame_remove_from_extra_frame(struct frame *frame, const unsigned int increment) +{ + frame->extra_frame -= increment; +} + +static inline void frame_add_to_extra_tun(struct frame *frame, const int increment) { frame->extra_tun += increment; diff --git a/src/openvpn/options.c b/src/openvpn/options.c index e42029c..be47090 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -3509,7 +3509,7 @@ calc_options_string_link_mtu(const struct options *o, const struct frame *frame) struct key_type fake_kt; init_key_type(&fake_kt, o->ciphername, o->authname, o->keysize, true, false); - frame_add_to_extra_frame(&fake_frame, -(crypto_max_overhead())); + frame_remove_from_extra_frame(&fake_frame, (unsigned int) crypto_max_overhead()); crypto_adjust_frame_parameters(&fake_frame, &fake_kt, o->replay, cipher_kt_mode_ofb_cfb(fake_kt.cipher)); frame_finalize(&fake_frame, o->ce.link_mtu_defined, o->ce.link_mtu, diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 315303b..747e176 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -1987,7 +1987,7 @@ tls_session_update_crypto_params(struct tls_session *session, } /* Update frame parameters: undo worst-case overhead, add actual overhead */ - frame_add_to_extra_frame(frame, -(crypto_max_overhead())); + frame_remove_from_extra_frame(frame, (unsigned int) crypto_max_overhead()); crypto_adjust_frame_parameters(frame, &session->opt->key_type, options->replay, packet_id_long_form); frame_finalize(frame, options->ce.link_mtu_defined, options->ce.link_mtu,