From patchwork Tue Jan 22 00:02:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lev Stipakov X-Patchwork-Id: 668 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director7.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id qPVGDKb4RlzoawAAIUCqbw for ; Tue, 22 Jan 2019 06:04:06 -0500 Received: from proxy12.mail.iad3b.rsapps.net ([172.31.255.6]) by director7.mail.ord1d.rsapps.net with LMTP id UJQ0Cqb4Rlx1eAAAovjBpQ ; Tue, 22 Jan 2019 06:04:06 -0500 Received: from smtp32.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy12.mail.iad3b.rsapps.net with LMTP id sPiSBab4RlwSBwAAEsW3lA ; Tue, 22 Jan 2019 06:04:06 -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: smtp32.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: 6eb1ca9a-1e35-11e9-941b-5254006a2e70-1-1 Received: from [216.105.38.7] ([216.105.38.7:62325] helo=lists.sourceforge.net) by smtp32.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 50/1A-08428-5A8F64C5; Tue, 22 Jan 2019 06:04:05 -0500 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 1gltpi-0003d0-Cg; Tue, 22 Jan 2019 11:03:06 +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 1gltph-0003ct-6c for openvpn-devel@lists.sourceforge.net; Tue, 22 Jan 2019 11:03:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=IDpVpRHaIrLO6AuFxgdxMebFOfxIgWcaT9aV8g9vCYk=; b=JN/UzOcQHF8GXqca8r0QeB4J2C z4AwlL1WHRObnIMsHLelu7yRSL1Hd0+a1oA/Leqwxsb+CgEWTdTUcFXKrwhD6dlidEy/HpHDxcfxV Y5FOHuq8Io5kIV7//oTffaPY+bjnZrD7nmzqAXIxOBMXHDvZl3vHmi88fzV0mN+ZKz4A=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=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: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=IDpVpRHaIrLO6AuFxgdxMebFOfxIgWcaT9aV8g9vCYk=; b=MgR6aQO0YmJ58cYuYml3JZiC8X L0iIlf5D1ayNezCfsWncahNfxNpOFeMG2Iuu1sp8f4l35TNtjHFxFcEy48w+8q/f2B2lHnHSgligm ekZ41PJTgbnbvPC646zNmTy6bA6Pjl9H6OjsN4qVBE1Tc8O6pqc4ijYAtrZNBBgdKbGY=; Received: from mail-ed1-f65.google.com ([209.85.208.65]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) id 1gltpb-008y2b-OS for openvpn-devel@lists.sourceforge.net; Tue, 22 Jan 2019 11:03:05 +0000 Received: by mail-ed1-f65.google.com with SMTP id f23so18959176edb.3 for ; Tue, 22 Jan 2019 03:02:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=IDpVpRHaIrLO6AuFxgdxMebFOfxIgWcaT9aV8g9vCYk=; b=PlRqfjbbgaOBAcGgEymJ3oZBJqReueKmELwKK6uhlijIuYxbEc6fyH39oEWw2oiLyR htZ+RhUI1UlB3PFHdHasB5rXSTBh2qEMYKLUdXxn+YQVCEVvF4zf2+BfdIBqQqmjhS0c l1BXXTsaqawPXS4ICadK0yXW4cllOKDbOWyXplHbgBSxkipnbW0sqP6EM/m166CCaCnd Wpm9RtvV/icI6iI4V44dHuSpDoy33qwkYQT9M3iw9JEETt4ZCD/03tp2Sh4dUyqbH2IP gJBzkSYUDzbarr/K0ulCJ84JzP3chgn3x8OGT+YkiWgMvmybIoizv9iaXPEBN8hK43Il UVyw== 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; bh=IDpVpRHaIrLO6AuFxgdxMebFOfxIgWcaT9aV8g9vCYk=; b=eaTcm+ZAN99FxQAL3iRQ7YqI27p+kTJ2a4uduDiDDKENz5uuGHj9FKvd2IcqmesnCj hFY7n8i6a3tSi3MwdFcFH4vPcVGehAuc+DJNd+ovlaM3/yT1gAn9Ipe8fgwl7XR3+YKK ocRLNeHzV+kY5O/na6vOwAo3FhPwIyYRhLSosHJWmGFKpOklYAM/agh91cquGRcZwk08 xjd0H53nzrdkpWns45wycjBheseHklLxt+lJ+5ueZDFrZMUoSoXmldzenjSXe5sTLiIg mIc36Tm5+1N3XuNc5Qmc21V8eq2CBtUcxQmKO9dc9fgxrWEhDuvl2nN0+0hINsMWm6Xk ZCEg== X-Gm-Message-State: AJcUukeSteLl0ETJqKQ4bMjoPRCyLuM+SCqNj5vD63fFamRfwSlEv4/q 1SIMATwe0RCsBwn7QbljJ1PJJW9/Hhk= X-Google-Smtp-Source: ALg8bN57bKzn1Z/pMzvXGkmd1LLFYuOzo+fvYBvDXEHJHy+gMA3DALFAnczJ2DSygtJgrTDWJvNdbg== X-Received: by 2002:a50:924e:: with SMTP id j14mr30767828eda.142.1548154972740; Tue, 22 Jan 2019 03:02:52 -0800 (PST) Received: from stipakov.fi (stipakov.fi. [128.199.52.117]) by smtp.gmail.com with ESMTPSA id o37sm9513421edc.32.2019.01.22.03.02.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Jan 2019 03:02:52 -0800 (PST) From: Lev Stipakov To: openvpn-devel@lists.sourceforge.net Date: Tue, 22 Jan 2019 13:02:47 +0200 Message-Id: <1548154968-13019-1-git-send-email-lstipakov@gmail.com> X-Mailer: git-send-email 2.7.4 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.65 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (lstipakov[at]gmail.com) -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 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.208.65 listed in wl.mailspike.net] X-Headers-End: 1gltpb-008y2b-OS Subject: [Openvpn-devel] [PATCH 1/2] 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 --- 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..6a49067 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)); + *BEND(dst) = '\0'; ret = true; cleanup: