| Message ID | 1539022378-24485-1-git-send-email-lstipakov@gmail.com |
|---|---|
| State | Accepted |
| Headers |
Return-Path: <openvpn-devel-bounces@lists.sourceforge.net> Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id kD4UHfWeu1sMTwAAIUCqbw for <patchwork@openvpn.net>; Mon, 08 Oct 2018 14:16:21 -0400 Received: from proxy14.mail.ord1d.rsapps.net ([172.30.191.6]) by director11.mail.ord1d.rsapps.net with LMTP id eBKfHPWeu1vZWAAAvGGmqA ; Mon, 08 Oct 2018 14:16:21 -0400 Received: from smtp2.gate.ord1c ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy14.mail.ord1d.rsapps.net with LMTP id MN9qHPWeu1vlNQAAtEH5vw ; Mon, 08 Oct 2018 14:16:21 -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: smtp2.gate.ord1c.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: 41ba3750-cb26-11e8-ae2c-842b2b4e7063-1-1 Received: from [216.105.38.7] ([216.105.38.7:29356] helo=lists.sourceforge.net) by smtp2.gate.ord1c.rsapps.net (envelope-from <openvpn-devel-bounces@lists.sourceforge.net>) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id E3/F6-32381-5FE9BBB5; Mon, 08 Oct 2018 14:16:21 -0400 Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from <openvpn-devel-bounces@lists.sourceforge.net>) id 1g9a41-0000Bz-CB; Mon, 08 Oct 2018 18:15:29 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from <lstipakov@gmail.com>) id 1g9a3z-0000Bp-VH for openvpn-devel@lists.sourceforge.net; Mon, 08 Oct 2018 18:15:27 +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=Ph1dZ6Non+5RdpNh22gFwrey0AHKQHOmZC45KckZ12U=; b=bbySAPKTxuveDacWv7We0bOofc ALVdDYbO0o7T+bEOvd4Ox2EI4A/zT8U1xTE7RnWDRV3+FmM14ggR6V2B60nkOHdXudXkMWQl6ZQ82 DWfsuFE0BD/FA1CsdFSL6gqka6fZct6XUhQtCb8W2PWzkkbeux0dWwbFiheVdbXyUIZI=; 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=Ph1dZ6Non+5RdpNh22gFwrey0AHKQHOmZC45KckZ12U=; b=M5YWbWzjuXrQhwpv3MtSl4/OUF R0S2N5bzYVhVqCGSe06awFhTgZzu5nZGfFQivagiNyaSfX1PaPo78Y6/QNL8wySOInOd7+zRSRvmF 8THjp4lW6RY06jQNfNxLw58sEx+Oj47B91Zjhk2OYerKOny+F0AYxZ39gVw+I44mMBC0=; Received: from mail-ed1-f44.google.com ([209.85.208.44]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) id 1g9a3y-003OHj-HJ for openvpn-devel@lists.sourceforge.net; Mon, 08 Oct 2018 18:15:27 +0000 Received: by mail-ed1-f44.google.com with SMTP id r1-v6so3933093edd.7 for <openvpn-devel@lists.sourceforge.net>; Mon, 08 Oct 2018 11:15:26 -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=Ph1dZ6Non+5RdpNh22gFwrey0AHKQHOmZC45KckZ12U=; b=d4HAiGkBdXJTvWlkzIsSnBRKd3Yg1Hf7EbMeZhQ80mLf1x+fOLfq5liQ8DGl7jQSlx fKSRrUc95BDWAY/2IIGmii8iJsQRRhpJTRlDwVwmu5pgBOhj1E9Zp8aqb7lpZfEjXnMD 6BWrAjmvlbYcun0ntQ872PL8/uTFPfcTJx0duc0iCpb11JY8LSTRg3Pvx/XxuxkahL4a 3pbldbcVnTkAsPLTZ5gKOMRhZunQ+IMZAqcsy51YkY1ENho6RLRLp9fNRuTfYBnm1cP7 bdloyJODF4j4hmRpQb6IljiCyVTBVGvZ9HdO+G9NtcmnZZUjhbMyx446SFF5C1d0l4Sa s5uA== 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=Ph1dZ6Non+5RdpNh22gFwrey0AHKQHOmZC45KckZ12U=; b=lzNR+1IN3uXosECJ1EN/yfh2WuMBysh+nJbofvNh8buvwNxpbdngx4UAYQNTGY5J/Y DSZkJ+J+jtw2WZHVFckMf/3f8NQXsYvlSeMBr/5t+/Wa+3CmzRyD9vLACn1y0FHEP28H E5fciI3q/Ec78uYkuG8KRNlLLHxu6bCCcPBBlSOh85mgbenm1ObylsWOFdLA2jRhwpD+ e3qk1c5nWfwu9qmO0yHeXhXHGi8Y17lt3wQVNW8WA9nBtoq6lIsBBYanDomUr5SV8r// XeIL9++dwZl8bW041ucdkWSgl3j/JGQiKcX5nlm2LFn44GrmbisqekI4DlbZbUkR10N6 gerg== X-Gm-Message-State: ABuFfohxlFq8W1oYdEmJQ6q9f1JVcStec4F0hGWkZbg+1aBxdlqpy4Lr 9d/xd1EhWY87pbg0D5rt4/RyxH/z2NU= X-Google-Smtp-Source: ACcGV61SAYs96fSlUuL6oSykj7wcpm1TdZQb/sJcx5RYfWSMUDVH1PAs4ovVZbzSflZaOVcs+YkL0w== X-Received: by 2002:a50:bc12:: with SMTP id j18-v6mr9094069edh.154.1539022519590; Mon, 08 Oct 2018 11:15:19 -0700 (PDT) Received: from stipakov.fi (stipakov.fi. [128.199.52.117]) by smtp.gmail.com with ESMTPSA id c27-v6sm5568721edc.4.2018.10.08.11.15.18 for <openvpn-devel@lists.sourceforge.net> (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Oct 2018 11:15:19 -0700 (PDT) From: Lev Stipakov <lstipakov@gmail.com> To: openvpn-devel@lists.sourceforge.net Date: Mon, 8 Oct 2018 21:12:58 +0300 Message-Id: <1539022378-24485-1-git-send-email-lstipakov@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20181008175242.GS962@greenie.muc.de> References: <20181008175242.GS962@greenie.muc.de> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 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.44 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.208.44 listed in list.dnswl.org] -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 0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1g9a3y-003OHj-HJ Subject: [Openvpn-devel] [PATCH v2] interactive.c: fix usage of potentially uninitialized variable X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: <openvpn-devel.lists.sourceforge.net> List-Unsubscribe: <https://lists.sourceforge.net/lists/options/openvpn-devel>, <mailto:openvpn-devel-request@lists.sourceforge.net?subject=unsubscribe> List-Archive: <http://sourceforge.net/mailarchive/forum.php?forum_name=openvpn-devel> List-Post: <mailto:openvpn-devel@lists.sourceforge.net> List-Help: <mailto:openvpn-devel-request@lists.sourceforge.net?subject=help> List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/openvpn-devel>, <mailto:openvpn-devel-request@lists.sourceforge.net?subject=subscribe> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox |
| Series |
[Openvpn-devel,v2] interactive.c: fix usage of potentially uninitialized variable
|
|
Commit Message
Lev Stipakov
Oct. 8, 2018, 7:12 a.m. UTC
From: Lev Stipakov <lev@openvpn.net> In function netsh_dns_cmd() it is possible to jump on a label and call free() on uninitialized pointer. Move pointer initialization above jump. To fix a few warnings which are treated as errors with SDL enabled, initialize pointers with NULL. Signed-off-by: Lev Stipakov <lev@openvpn.net> --- v2: - remove NULL check before free() call - remove unneeded NULL initializations in function body src/openvpnserv/interactive.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
Comments
Hi, Sorry I missed this patch cleaning up my mistake.. Gert has already reviewed and asked for this v2 so this may be redundant, but fwiw: On Mon, Oct 8, 2018 at 2:15 PM Lev Stipakov <lstipakov@gmail.com> wrote: > From: Lev Stipakov <lev@openvpn.net> > > In function netsh_dns_cmd() it is possible to jump on a label and > call free() on uninitialized pointer. Move pointer initialization > above jump. > > To fix a few warnings which are treated as errors with SDL enabled, > initialize pointers with NULL. > > Signed-off-by: Lev Stipakov <lev@openvpn.net> > --- > v2: > - remove NULL check before free() call > - remove unneeded NULL initializations in function body > > src/openvpnserv/interactive.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c > index 8f92c24..4a571f5 100644 > --- a/src/openvpnserv/interactive.c > +++ b/src/openvpnserv/interactive.c > @@ -1015,6 +1015,7 @@ netsh_dns_cmd(const wchar_t *action, const wchar_t > *proto, const wchar_t *if_nam > DWORD err = 0; > int timeout = 30000; /* in msec */ > wchar_t argv0[MAX_PATH]; > + wchar_t *cmdline = NULL; > Indeed this has to move up or the early jump to label out should be replaced by "return err". Is there a way to get gcc warn (or error) when jumping over unitialized variables that get referenced after the jump -- -Wjump-misses-init is noisy and does not catch all. > if (!addr) > { > @@ -1039,7 +1040,7 @@ netsh_dns_cmd(const wchar_t *action, const wchar_t > *proto, const wchar_t *if_nam > > /* max cmdline length in wchars -- include room for worst case and > some */ > size_t ncmdline = wcslen(fmt) + wcslen(if_name) + wcslen(addr) + 32 + > 1; > - wchar_t *cmdline = malloc(ncmdline*sizeof(wchar_t)); > + cmdline = malloc(ncmdline*sizeof(wchar_t)); > if (!cmdline) > { > err = ERROR_OUTOFMEMORY; > @@ -1350,7 +1351,7 @@ RunOpenvpn(LPVOID p) > { > HANDLE pipe = p; > HANDLE ovpn_pipe, svc_pipe; > - PTOKEN_USER svc_user, ovpn_user; > + PTOKEN_USER svc_user = NULL, ovpn_user = NULL; > Good catch -- these could get passed to free on errors. > HANDLE svc_token = NULL, imp_token = NULL, pri_token = NULL; > HANDLE stdin_read = NULL, stdin_write = NULL; > HANDLE stdout_write = NULL; > @@ -1403,7 +1404,6 @@ RunOpenvpn(LPVOID p) > goto out; > } > len = 0; > - svc_user = NULL; > while (!GetTokenInformation(svc_token, TokenUser, svc_user, len, > &len)) > { > if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) > @@ -1436,7 +1436,6 @@ RunOpenvpn(LPVOID p) > goto out; > } > len = 0; > - ovpn_user = NULL; > while (!GetTokenInformation(imp_token, TokenUser, ovpn_user, len, > &len)) > { > if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) > Thanks for the cleanup. Acked-by: selva.nair@gmail.com <div dir="ltr"><div><div>Hi,<br><br></div>Sorry I missed this patch cleaning up my mistake..<br><br>Gert has already reviewed and asked for this v2 so this may be redundant,<br></div>but fwiw:<br><br><div><div class="gmail_quote"><div dir="ltr">On Mon, Oct 8, 2018 at 2:15 PM Lev Stipakov <<a href="mailto:lstipakov@gmail.com" target="_blank">lstipakov@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Lev Stipakov <<a href="mailto:lev@openvpn.net" target="_blank">lev@openvpn.net</a>><br> <br> In function netsh_dns_cmd() it is possible to jump on a label and<br> call free() on uninitialized pointer. Move pointer initialization<br> above jump.<br> <br> To fix a few warnings which are treated as errors with SDL enabled,<br> initialize pointers with NULL.<br> <br> Signed-off-by: Lev Stipakov <<a href="mailto:lev@openvpn.net" target="_blank">lev@openvpn.net</a>><br> ---<br> v2:<br> - remove NULL check before free() call<br> - remove unneeded NULL initializations in function body<br> <br> src/openvpnserv/interactive.c | 7 +++----<br> 1 file changed, 3 insertions(+), 4 deletions(-)<br> <br> diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c<br> index 8f92c24..4a571f5 100644<br> --- a/src/openvpnserv/interactive.c<br> +++ b/src/openvpnserv/interactive.c<br> @@ -1015,6 +1015,7 @@ netsh_dns_cmd(const wchar_t *action, const wchar_t *proto, const wchar_t *if_nam<br> DWORD err = 0;<br> int timeout = 30000; /* in msec */<br> wchar_t argv0[MAX_PATH];<br> + wchar_t *cmdline = NULL;<br></blockquote><div><br></div><div>Indeed this has to move up or the early jump to label out should be <br>replaced by "return err".<br><br>Is there a way to get gcc warn (or error) when jumping over unitialized variables<br></div><div>that get referenced after the jump -- -Wjump-misses-init is noisy and <br></div><div>does not catch all.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br> if (!addr)<br> {<br> @@ -1039,7 +1040,7 @@ netsh_dns_cmd(const wchar_t *action, const wchar_t *proto, const wchar_t *if_nam<br> <br> /* max cmdline length in wchars -- include room for worst case and some */<br> size_t ncmdline = wcslen(fmt) + wcslen(if_name) + wcslen(addr) + 32 + 1;<br> - wchar_t *cmdline = malloc(ncmdline*sizeof(wchar_t));<br> + cmdline = malloc(ncmdline*sizeof(wchar_t));<br> if (!cmdline)<br> {<br> err = ERROR_OUTOFMEMORY;<br> @@ -1350,7 +1351,7 @@ RunOpenvpn(LPVOID p)<br> {<br> HANDLE pipe = p;<br> HANDLE ovpn_pipe, svc_pipe;<br> - PTOKEN_USER svc_user, ovpn_user;<br> + PTOKEN_USER svc_user = NULL, ovpn_user = NULL;<br></blockquote><div><br></div><div>Good catch -- these could get passed to free on errors.<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> HANDLE svc_token = NULL, imp_token = NULL, pri_token = NULL;<br> HANDLE stdin_read = NULL, stdin_write = NULL;<br> HANDLE stdout_write = NULL;<br> @@ -1403,7 +1404,6 @@ RunOpenvpn(LPVOID p)<br> goto out;<br> }<br> len = 0;<br> - svc_user = NULL;<br> while (!GetTokenInformation(svc_token, TokenUser, svc_user, len, &len))<br> {<br> if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)<br> @@ -1436,7 +1436,6 @@ RunOpenvpn(LPVOID p)<br> goto out;<br> }<br> len = 0;<br> - ovpn_user = NULL;<br> while (!GetTokenInformation(imp_token, TokenUser, ovpn_user, len, &len))<br> {<br> if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)<br></blockquote><div><br></div><div>Thanks for the cleanup.<br><br></div><div>Acked-by: <a href="mailto:selva.nair@gmail.com" target="_blank">selva.nair@gmail.com</a></div></div></div></div>
Your patch has been applied to the master and release/2.4 branch (bugfix).
Thanks, Selva, for the extra pair of eyes. I was fine with the v2, but
had hoped to see an extra review from you in case I overlooked something
("you know this code best").
Test built on ubuntu 16.04.
commit d1f0e2cf83c378b4064f316a2127c7a3d7c6ca21 (master)
commit 773c086367c8dd94d71a10bd2b32f09b4a0840ae (release/2.4)
Author: Lev Stipakov
Date: Mon Oct 8 21:12:58 2018 +0300
interactive.c: fix usage of potentially uninitialized variable
Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Selva Nair <selva.nair@gmail.com>
Message-Id: <1539022378-24485-1-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg17663.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
--
kind regards,
Gert Doering
diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index 8f92c24..4a571f5 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -1015,6 +1015,7 @@ netsh_dns_cmd(const wchar_t *action, const wchar_t *proto, const wchar_t *if_nam DWORD err = 0; int timeout = 30000; /* in msec */ wchar_t argv0[MAX_PATH]; + wchar_t *cmdline = NULL; if (!addr) { @@ -1039,7 +1040,7 @@ netsh_dns_cmd(const wchar_t *action, const wchar_t *proto, const wchar_t *if_nam /* max cmdline length in wchars -- include room for worst case and some */ size_t ncmdline = wcslen(fmt) + wcslen(if_name) + wcslen(addr) + 32 + 1; - wchar_t *cmdline = malloc(ncmdline*sizeof(wchar_t)); + cmdline = malloc(ncmdline*sizeof(wchar_t)); if (!cmdline) { err = ERROR_OUTOFMEMORY; @@ -1350,7 +1351,7 @@ RunOpenvpn(LPVOID p) { HANDLE pipe = p; HANDLE ovpn_pipe, svc_pipe; - PTOKEN_USER svc_user, ovpn_user; + PTOKEN_USER svc_user = NULL, ovpn_user = NULL; HANDLE svc_token = NULL, imp_token = NULL, pri_token = NULL; HANDLE stdin_read = NULL, stdin_write = NULL; HANDLE stdout_write = NULL; @@ -1403,7 +1404,6 @@ RunOpenvpn(LPVOID p) goto out; } len = 0; - svc_user = NULL; while (!GetTokenInformation(svc_token, TokenUser, svc_user, len, &len)) { if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) @@ -1436,7 +1436,6 @@ RunOpenvpn(LPVOID p) goto out; } len = 0; - ovpn_user = NULL; while (!GetTokenInformation(imp_token, TokenUser, ovpn_user, len, &len)) { if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)