linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steve French <smfrench@gmail.com>
To: CIFS <linux-cifs@vger.kernel.org>
Subject: [PATCH][CIFS] missing null check for newinode pointer
Date: Tue, 22 Jun 2021 20:03:45 -0500	[thread overview]
Message-ID: <CAH2r5mtN+0MLW3e_xhqEP3R_EFULWjrzScuyYZgZ2AE9ukERRA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 797 bytes --]

in cifs_do_create we check if newinode is valid before referencing it
but are missing the check in one place in fs/cifs/dir.c

Addresses-Coverity: 1357292 ("Dereference after null check")
Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/cifs/dir.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 912333082b18..aca6ed58cc44 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -384,10 +384,11 @@ cifs_do_create(struct inode *inode, struct
dentry *direntry, unsigned int xid,
  goto out_err;
  }

- if (S_ISDIR(newinode->i_mode)) {
- rc = -EISDIR;
- goto out_err;
- }
+ if (newinode)
+ if (S_ISDIR(newinode->i_mode)) {
+ rc = -EISDIR;
+ goto out_err;
+ }

  d_drop(direntry);
  d_add(direntry, newinode);

-- 
Thanks,

Steve

[-- Attachment #2: 0001-cifs-missing-null-check-for-newinode-pointer.patch --]
[-- Type: text/x-patch, Size: 1017 bytes --]

From 8252c0bc73cad73a8f4f76e90c2381ee34ffbc0f Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@microsoft.com>
Date: Tue, 22 Jun 2021 19:53:08 -0500
Subject: [PATCH] cifs: missing null check for newinode pointer

in cifs_do_create we check if newinode is valid before referencing it
but are missing the check in one place in fs/cifs/dir.c

Addresses-Coverity: 1357292 ("Dereference after null check")
Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/cifs/dir.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 912333082b18..aca6ed58cc44 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -384,10 +384,11 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
 		goto out_err;
 	}
 
-	if (S_ISDIR(newinode->i_mode)) {
-		rc = -EISDIR;
-		goto out_err;
-	}
+	if (newinode)
+		if (S_ISDIR(newinode->i_mode)) {
+			rc = -EISDIR;
+			goto out_err;
+		}
 
 	d_drop(direntry);
 	d_add(direntry, newinode);
-- 
2.30.2


             reply	other threads:[~2021-06-23  1:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-23  1:03 Steve French [this message]
2021-06-23 11:15 ` [PATCH][CIFS] missing null check for newinode pointer Sachin Prabhu

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=CAH2r5mtN+0MLW3e_xhqEP3R_EFULWjrzScuyYZgZ2AE9ukERRA@mail.gmail.com \
    --to=smfrench@gmail.com \
    --cc=linux-cifs@vger.kernel.org \
    /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).