linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jianhong.Yin" <jiyin@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: trond.myklebust@primarydata.com, bfields@redhat.com,
	steved@redhat.com, "Jianhong.Yin" <yin-jianhong@163.com>
Subject: [PATCH] fs/nfs: fix covscan error: FORWARD_NULL
Date: Fri,  5 May 2017 18:26:51 +0800	[thread overview]
Message-ID: <1493980011-24395-1-git-send-email-jiyin@redhat.com> (raw)

From: "Jianhong.Yin" <yin-jianhong@163.com>

fs/nfs/nfs4xdr.c: encode_attrs()
'''
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 <yin-jianhong@163.com>
---
 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: */
-- 
1.8.3.1


             reply	other threads:[~2017-05-05 10:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-05 10:26 Jianhong.Yin [this message]
     [not found] ` <b100e3a6-c59b-9729-7129-6c7ca163dacf@Netapp.com>
2017-05-06  7:42   ` [PATCH] fs/nfs: fix covscan error: FORWARD_NULL Jianhong Yin
  -- strict thread matches above, loose matches on Subject: below --
2017-05-05  3:58 Jianhong.Yin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1493980011-24395-1-git-send-email-jiyin@redhat.com \
    --to=jiyin@redhat.com \
    --cc=bfields@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    --cc=trond.myklebust@primarydata.com \
    --cc=yin-jianhong@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).