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: 10585355 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 51E8B180E for ; Mon, 3 Sep 2018 03:16:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 403EA292E5 for ; Mon, 3 Sep 2018 03:16:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34129292EA; Mon, 3 Sep 2018 03:16:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FE3D292E5 for ; Mon, 3 Sep 2018 03:16:04 +0000 (UTC) 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 X-Virus-Scanned: ClamAV using ClamSMTP 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);