From patchwork Thu Feb 28 07:51:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 698 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director12.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id CNwLJAEueFyuLQAAIUCqbw for ; Thu, 28 Feb 2019 13:52:49 -0500 Received: from proxy11.mail.iad3b.rsapps.net ([172.31.255.6]) by director12.mail.ord1d.rsapps.net with LMTP id 4IkQIQEueFyLJAAAIasKDg ; Thu, 28 Feb 2019 13:52:49 -0500 Received: from smtp26.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy11.mail.iad3b.rsapps.net with LMTP id YCFBGgEueFxqCwAARNREpw ; Thu, 28 Feb 2019 13:52:49 -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: smtp26.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; dmarc=none (p=nil; dis=none) header.from=greenie.muc.de X-Suspicious-Flag: YES X-Classification-ID: 0a97ba5c-3b8a-11e9-8359-5254001088d3-1-1 Received: from [216.105.38.7] ([216.105.38.7:19786] helo=lists.sourceforge.net) by smtp26.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 98/E0-24817-00E287C5; Thu, 28 Feb 2019 13:52:48 -0500 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 ) id 1gzQmR-0001wB-VM; Thu, 28 Feb 2019 18:51:39 +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 ) id 1gzQmQ-0001w3-6n for openvpn-devel@lists.sourceforge.net; Thu, 28 Feb 2019 18:51:38 +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=YFmXlE8UUMDjN+boprbN4HtSFwYpWaSJL32knwtGdh8=; b=ZgwLpRnBTYNQtKR1YkkpB3D3Fm mJny4yLcRPFoPSvJ0xVTKBqcmJai+MiBra1UbvAzdCBgaMg0ndY2ODjhwPA2GgL0XCkFyHpRjiWBd NT774C0LiemAKhBIk6BjXMyyhlY7Xg/G8wdcUS6kMm7hGwJzyqImgMcQQj0Rg6TXDaXQ=; 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=YFmXlE8UUMDjN+boprbN4HtSFwYpWaSJL32knwtGdh8=; b=kqLp6UkC8EWTq4IQmtFFJ/GGIp I3sr/TnP35waS2RbxSTiOXVYp8Jf9C3MDjSdU9W/toKgEx3EmpnNc1kE/tBRVanT+4Gy74a5Xv0kf w5cX7O8by/SKHJXi7gN/gqSUpIRDLGxWcxU6CoRsXvGelBZCf2vebgJI+5uSRRSmdmjU=; Received: from chekov.greenie.muc.de ([193.149.48.178]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1gzQmN-00ErRK-SE for openvpn-devel@lists.sourceforge.net; Thu, 28 Feb 2019 18:51:38 +0000 Received: from chekov.greenie.muc.de (localhost [127.0.0.1]) by chekov.greenie.muc.de (8.15.2/8.15.2) with ESMTPS id x1SIpS5r044026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 28 Feb 2019 19:51:28 +0100 (CET) (envelope-from gert@chekov.greenie.muc.de) Received: (from gert@localhost) by chekov.greenie.muc.de (8.15.2/8.15.2/Submit) id x1SIpShx044025 for openvpn-devel@lists.sourceforge.net; Thu, 28 Feb 2019 19:51:28 +0100 (CET) (envelope-from gert) From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Thu, 28 Feb 2019 19:51:28 +0100 Message-Id: <20190228185128.43982-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.18.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: muc.de] X-Headers-End: 1gzQmN-00ErRK-SE Subject: [Openvpn-devel] [PATCH] Copy one byte less in strncpynt() 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 While the existing code is not wrong and will never cause an overflow, it will copy (on a too-long source string) "maxlen" bytes to dest, and then overwrite the last byte just copied with "0" - which causes a warning in gcc 9 about filling the target buffer "up to the end, with no room for a trailing 0 anymore". Reducing the maximum bytes-to-be-copied to "maxlen -1", because the last byte will be stamped with 0 anyway. Signed-off-by: Gert Doering --- src/openvpn/buffer.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index a4fe6f9b..52de5a2b 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -347,7 +347,8 @@ buf_set_read(struct buffer *buf, const uint8_t *data, int size) static inline void strncpynt(char *dest, const char *src, size_t maxlen) { - strncpy(dest, src, maxlen); + ASSERT(maxlen>0); + strncpy(dest, src, maxlen-1); if (maxlen > 0) { dest[maxlen - 1] = 0;