From patchwork Fri Jun 7 21:56:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 741 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id QIZuESNv+1y4BwAAIUCqbw for ; Sat, 08 Jun 2019 04:17:39 -0400 Received: from proxy11.mail.iad3b.rsapps.net ([172.31.255.6]) by director10.mail.ord1d.rsapps.net with LMTP id 0G9rDiNv+1zieQAApN4f7A ; Sat, 08 Jun 2019 04:17:39 -0400 Received: from smtp11.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 oCHNByNv+1zjfwAARNREpw ; Sat, 08 Jun 2019 04:17:39 -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: smtp11.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: e076f7d0-89c5-11e9-941a-52540070b5bb-1-1 Received: from [216.105.38.7] ([216.105.38.7:43222] helo=lists.sourceforge.net) by smtp11.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id B3/54-01483-22F6BFC5; Sat, 08 Jun 2019 04:17:38 -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 ) id 1hZWWb-0003jI-2k; Sat, 08 Jun 2019 08:16: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 ) id 1hZWWX-0003iL-6f for openvpn-devel@lists.sourceforge.net; Sat, 08 Jun 2019 08:16:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: 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=2YoGuOzvfWFEP2tFdbCTSzZ/WfsFfJhxu2EmDTMHNTM=; b=GIJYO2Ehx8ramW9aQSogLvcOXQ VLx+dZ4mqqQjBNWja9vF+aM6MO7fwSBOaRGQwUMvFSM3Vzd5Xno+DTmTnoJXxGOHN+1bOmM3xALE6 V+42lKwAh2tqjIm0yha0TvAmaL6HiHRYHt5Lpjn3ofEdxta2PBCd6tC5CNKI9rW0EHtI=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: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=2YoGuOzvfWFEP2tFdbCTSzZ/WfsFfJhxu2EmDTMHNTM=; b=FCthLs6Vc41YGs1Pkhna5fE9FL hUBStiBgmxOqFv9d0wOt9pWrLdxZ7EdrjH3T3ORACK5TVYy+CUwkBtE3XFs/zXKd5mdb3NDgV+vYh 0YHfP6U74H/0PMEvN/vuoBZbbxf8KNN0n3uqvJDZ2BWSQC5iv+F6iz6o+XLvHE745uzE=; Received: from dhcp-174.greenie.muc.de ([193.149.48.174] helo=blue.greenie.muc.de) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1hZWWU-0015kU-VV for openvpn-devel@lists.sourceforge.net; Sat, 08 Jun 2019 08:16:25 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.14.9/8.14.9) with ESMTP id x587uPNp011658 for ; Sat, 8 Jun 2019 09:56:25 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.14.9/8.14.9/Submit) id x587uPR9011654 for openvpn-devel@lists.sourceforge.net; Sat, 8 Jun 2019 09:56:25 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Sat, 8 Jun 2019 09:56:22 +0200 Message-Id: <20190608075622.11589-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190228185128.43982-1-gert@greenie.muc.de> References: <20190228185128.43982-1-gert@greenie.muc.de> MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1hZWWU-0015kU-VV Subject: [Openvpn-devel] [PATCH v2] 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: , 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. v2: do not ASSERT() on "maxlen == 0", but move the strncpy() call inside the if() clause - so "just do nothing" on maxlen == 0, as before. Signed-off-by: Gert Doering Acked-by: Antonio Quartulli --- src/openvpn/buffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index a4fe6f9b..e8b83a5e 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -347,9 +347,9 @@ 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); if (maxlen > 0) { + strncpy(dest, src, maxlen-1); dest[maxlen - 1] = 0; } }