From patchwork Tue Jan 22 02:41:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lev Stipakov X-Patchwork-Id: 670 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director9.mail.ord1d.rsapps.net ([172.27.255.56]) by backend30.mail.ord1d.rsapps.net with LMTP id 0NsGB70dR1ynLgAAIUCqbw for ; Tue, 22 Jan 2019 08:42:21 -0500 Received: from proxy16.mail.iad3a.rsapps.net ([172.27.255.56]) by director9.mail.ord1d.rsapps.net with LMTP id 0OICBL0dR1waKgAAalYnBA ; Tue, 22 Jan 2019 08:42:21 -0500 Received: from smtp10.gate.iad3a ([172.27.255.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy16.mail.iad3a.rsapps.net with LMTP id qNvjOLwdR1zrfAAADc5QwQ ; Tue, 22 Jan 2019 08:42:20 -0500 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: smtp10.gate.iad3a.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: 8a05fa76-1e4b-11e9-9fc8-525400a8203f-1-1 Received: from [216.105.38.7] ([216.105.38.7:64357] helo=lists.sourceforge.net) by smtp10.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 68/30-16695-CBD174C5; Tue, 22 Jan 2019 08:42:20 -0500 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1glwIv-0001kW-AP; Tue, 22 Jan 2019 13:41:25 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1glwIt-0001kO-7N for openvpn-devel@lists.sourceforge.net; Tue, 22 Jan 2019 13:41:23 +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=39zGr9cNiExPbPETcvjid+OrdTPy4ZdoDPxsQsr7cn0=; b=C+uVhkNdbQRPitXamxg8gqp/lj nyjleU3JUO+LehGitFqztgcdpVZdt/Mx6IrfgD08AE+cNW1ezNWPZZ7IgXeV0pXLYslMY12zNBa9c hRs//1zwpANanUT2VayrIew6hkcxQlGKv7ozWNZBzJ1pEC7KiQrrkO4B7wsa8XWNa5EE=; 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=39zGr9cNiExPbPETcvjid+OrdTPy4ZdoDPxsQsr7cn0=; b=UE6oIb4OAGEwgRCO5pDtbV72L8 HpLd6Bc26/ay7Ib4BHMQDCNX8nccpUV3UlwP485afvd/fRH0oThIYrjo8OJB7WmemIYvsBOYe9MX+ 4nuocEbetLB7O7z97hSYnMeLPpomIgyQkysQMb+Q6KYnQekMZCdtNNNdrWE+s3W2KR8o=; Received: from mail-ed1-f67.google.com ([209.85.208.67]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) id 1glwIr-005DpR-NC for openvpn-devel@lists.sourceforge.net; Tue, 22 Jan 2019 13:41:23 +0000 Received: by mail-ed1-f67.google.com with SMTP id f9so19299377eds.10 for ; Tue, 22 Jan 2019 05:41:21 -0800 (PST) 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=39zGr9cNiExPbPETcvjid+OrdTPy4ZdoDPxsQsr7cn0=; b=NNrUBVUzQkrNNgwADjBMlOyyIP1FuyjFLR3Es1kwhrUbmXDqSLJcWDZMWotVk16s7C ihSe55pMJjWvPdkz57SOv5znMikuZSc4vBwv80xls+RxmZNKro8Vs6HRZROmsocVZsyc 4xB/anRca8GWm33/KOqr/Bxj+K+w4jHQ7g2EJ40S1RLYhNqHKIEh9yQ7inN1PMOM7klc lu7erW+ZWCvxGCs6PZq07PxZ3w9WWTD9XE9JLYtLeeBOcKUSbAKklvYhM1R1pcodLJH3 RyNvpLKEbvxLkGVKAWKsprPlUyqRACbrCSnFBkV7kVuluz8NeDSTXlunVKhP0DvWVQEM uKGQ== 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=39zGr9cNiExPbPETcvjid+OrdTPy4ZdoDPxsQsr7cn0=; b=dC2bIAZ3NfwM5H6tgX1mUI+wl6IyJ4Yj1IvVDQNJWr+7m5ZiSA7uEYXVNs1P6L8/Dp z8I1SO5NM0CuqnTjNHPvAAkcbwEBjCYOE1L4rQatLCil1NEepylYHBdSKDxdZtMDWinU 9otQKxYrFuBRBr/LrtcNLdmnhkj/6iQS+HLgWuyYkD/Bxp+xfPUypvOxO3UTYBLgJmgI p6I66JpzQX/qJOSqsvW9otdMsvcLjAhRYwJksgVMRYfGBpvbzp1wxnGz0tYCVavALTjT gOhbVF3EEojxYrGsd1BSD/y6iv1y/1hPB4lE7+eJJPyVJiplV2ZcYwGqzKNHRMWX049e wEpQ== X-Gm-Message-State: AJcUukfefh9zs+64R+XeW40UCF8fOQqAKFgpN+ewS14pv33VnizpSdzC gdQ++uLSbYIqcr2RWsPc0tNzMeZvQVk= X-Google-Smtp-Source: ALg8bN7egmdXJ1S7AOvepBzth4g906+ecPlEtHqDNnJUrJRHPRS2UIFtQQaxJg1Yz9DK5oUYmLrEug== X-Received: by 2002:a17:906:4e14:: with SMTP id z20-v6mr27919509eju.187.1548164474725; Tue, 22 Jan 2019 05:41:14 -0800 (PST) Received: from stipakov.fi (stipakov.fi. [128.199.52.117]) by smtp.gmail.com with ESMTPSA id y16sm9686395edb.41.2019.01.22.05.41.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Jan 2019 05:41:14 -0800 (PST) From: Lev Stipakov To: openvpn-devel@lists.sourceforge.net Date: Tue, 22 Jan 2019 15:41:03 +0200 Message-Id: <1548164463-13366-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 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (lstipakov[at]gmail.com) -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.208.67 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.208.67 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: 1glwIr-005DpR-NC Subject: [Openvpn-devel] [PATCH v2] crypto_openssl.c: fix heap-buffer-overflow found by AddressSanitizer 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 OpenSSL's version of crypto_pem_encode() uses PEM_write_bio() function to write PEM-encoded data to BIO object. That method doesn't add NUL termanator, unlike its mbedTLS counterpart mbedtls_pem_write_buffer(). The code which uses PEM data treats it as a string, so missing NUL terminator makes sanitizer to compain. Fix by adding a NUL terminator. Signed-off-by: Lev Stipakov Acked-By: Arne Schwabe --- v2: use a dedivcated function to add a nul terminator src/openvpn/crypto_openssl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index 9691ce0..c049e52 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -400,8 +400,9 @@ crypto_pem_encode(const char *name, struct buffer *dst, BUF_MEM *bptr; BIO_get_mem_ptr(bio, &bptr); - *dst = alloc_buf_gc(bptr->length, gc); + *dst = alloc_buf_gc(bptr->length + 1, gc); ASSERT(buf_write(dst, bptr->data, bptr->length)); + buf_null_terminate(dst); ret = true; cleanup: