From patchwork Fri May 5 03:58:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jianhong.Yin" X-Patchwork-Id: 9713043 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 79505602B9 for ; Fri, 5 May 2017 04:00:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56CB22869F for ; Fri, 5 May 2017 04:00:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 373462866D; Fri, 5 May 2017 04:00:04 +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=-6.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, 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 98ECD2866D for ; Fri, 5 May 2017 04:00:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752803AbdEEEAA (ORCPT ); Fri, 5 May 2017 00:00:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60324 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752224AbdEEEAA (ORCPT ); Fri, 5 May 2017 00:00:00 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 633134E4CD; Fri, 5 May 2017 03:59:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 633134E4CD Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=163.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=yin-jianhong@163.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 633134E4CD Received: from dhcp12-131.nay.redhat.com (dhcp-12-131.nay.redhat.com [10.66.12.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8756418C68; Fri, 5 May 2017 03:59:57 +0000 (UTC) From: "Jianhong.Yin" To: linux-nfs@vger.kernel.org Cc: Trond.Myklebust@netapp.com, bfields@redhat.com, steved@redhat.com, "Jianhong.Yin" Subject: [PATCH] fs/nfs: fix covscan error: FORWARD_NULL Date: Fri, 5 May 2017 11:58:55 +0800 Message-Id: <1493956735-3481-1-git-send-email-yin-jianhong@163.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 05 May 2017 03:59:59 +0000 (UTC) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ''' Error: FORWARD_NULL (CWE-476): [#def3702] .../fs/nfs/nfs4xdr.c:1085: var_compare_op: Comparing "label" to null implies that "label" might be null. .../fs/nfs/nfs4xdr.c:1129: var_deref_op: Dereferencing null pointer "label". 1127| } 1128| if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { 1129|-> *p++ = cpu_to_be32(label->lfs); 1130| *p++ = cpu_to_be32(label->pi); 1131| *p++ = cpu_to_be32(label->len); Error: FORWARD_NULL (CWE-476): [#def3703] .../fs/nfs/nfs4xdr.c:1027: var_compare_op: Comparing "umask" to null implies that "umask" might be null. .../fs/nfs/nfs4xdr.c:1136: var_deref_op: Dereferencing null pointer "umask". 1134| if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { 1135| *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1136|-> *p++ = cpu_to_be32(*umask); 1137| } ''' Signed-off-by: Jianhong Yin --- fs/nfs/nfs4xdr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index 80ce289..a86ed66 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c @@ -1124,7 +1124,7 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, } else *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); } - if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { + if (label && bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { *p++ = cpu_to_be32(label->lfs); *p++ = cpu_to_be32(label->pi); *p++ = cpu_to_be32(label->len); @@ -1132,7 +1132,8 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, } if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); - *p++ = cpu_to_be32(*umask); + if (umask != NULL) + *p++ = cpu_to_be32(*umask); } /* out: */