From patchwork Mon Sep 3 03:15:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Rothwell X-Patchwork-Id: 965179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=canb.auug.org.au Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=canb.auug.org.au header.i=@canb.auug.org.au header.b="qfXXCB49"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 423ZqS3b0dz9s2P for ; Mon, 3 Sep 2018 13:16:04 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725782AbeICHeL (ORCPT ); Mon, 3 Sep 2018 03:34:11 -0400 Received: from ozlabs.org ([203.11.71.1]:55151 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725780AbeICHeK (ORCPT ); Mon, 3 Sep 2018 03:34:10 -0400 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 423ZqM2pLfz9ryn; Mon, 3 Sep 2018 13:15:59 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=canb.auug.org.au DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=canb.auug.org.au; s=201702; t=1535944559; bh=9kW81LkgZFxpI4ok7PWkE8hHULnnv09l1SkoeQ/ZzRs=; h=Date:From:To:Cc:Subject:From; b=qfXXCB49WNlRlKoWiRbcwTuJCzbXuYA2YmNl7A1ffdSvN6Zc/pu+lZ/Gwmtd9mfTO Rp3isplgP+ozp5U9uGyTKk/SuHGaoP46I/JjTJcyB8UtfpV+MoxTEcKZSEcopP2SFb Vh7+39noQSUo9R+9XgwZ0NZAcuzf5eq6JVEPQlsZ+8nhwoYEq2nytFoOjRGiQA7pvv tWnPNKcGh7jBXCPKHP1ZWp6nIBvSSrpM/Lvc5aDfiNHRHKzcRmVwgYtlSL0oFI7BW+ lr/Pmy/2pIEwK6nC+I36xYtyOK6JGBGRzbkCleKtE75ePXet2SMMig3Q0W9j3B0lZV s3PxRVdZH5I2g== Date: Mon, 3 Sep 2018 13:15:58 +1000 From: Stephen Rothwell To: Steve French Cc: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, Linux-kernel Mailing List Subject: [PATCH] fs/cifs: suppress a string overflow warning Message-ID: <20180903131558.21cdeb35@canb.auug.org.au> MIME-Version: 1.0 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org A powerpc build of cifs with gcc v8.2.0 produces this warning: fs/cifs/cifssmb.c: In function ‘CIFSSMBNegotiate’: fs/cifs/cifssmb.c:605:3: warning: ‘strncpy’ writing 16 bytes into a region of size 1 overflows the destination [-Wstringop-overflow=] strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Since we are already doing a strlen() on the source, change the strncpy to a memcpy(). Signed-off-by: Stephen Rothwell --- fs/cifs/cifssmb.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index dc2f4cf08fe9..dcf939cb9d2f 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -601,10 +601,14 @@ CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses) } count = 0; + /* + * We know that all the name entries in the protocols array + * are short (< 16 bytes anyway) and are NUL terminated. + */ for (i = 0; i < CIFS_NUM_PROT; i++) { - strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); - count += strlen(protocols[i].name) + 1; - /* null at end of source and target buffers anyway */ + size_t len = strlen(protocols[i].name) + 1; + memcpy(pSMB->DialectsArray+count, protocols[i].name, len); + count += len; } inc_rfc1001_len(pSMB, count); pSMB->ByteCount = cpu_to_le16(count);