diff mbox series

ksmbd: missing check for NULL in convert_to_nt_pathname()

Message ID 20210930122456.GA10068@kili (mailing list archive)
State New, archived
Headers show
Series ksmbd: missing check for NULL in convert_to_nt_pathname() | expand

Commit Message

Dan Carpenter Sept. 30, 2021, 12:24 p.m. UTC
The kmalloc() does not have a NULL check.  This code can be re-written
slightly cleaner to just use the kstrdup().

Fixes: 265fd1991c1d ("ksmbd: use LOOKUP_BENEATH to prevent the out of share access")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 fs/ksmbd/misc.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

Comments

Namjae Jeon Sept. 30, 2021, 11:21 p.m. UTC | #1
2021-09-30 21:24 GMT+09:00, Dan Carpenter <dan.carpenter@oracle.com>:
> The kmalloc() does not have a NULL check.  This code can be re-written
> slightly cleaner to just use the kstrdup().
>
> Fixes: 265fd1991c1d ("ksmbd: use LOOKUP_BENEATH to prevent the out of share
> access")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>

Thanks for your patch!
Steve French Oct. 1, 2021, 1:01 a.m. UTC | #2
Added the acked-bys and pushed to ksmbd-for-next

On Thu, Sep 30, 2021 at 6:23 PM Namjae Jeon <linkinjeon@kernel.org> wrote:
>
> 2021-09-30 21:24 GMT+09:00, Dan Carpenter <dan.carpenter@oracle.com>:
> > The kmalloc() does not have a NULL check.  This code can be re-written
> > slightly cleaner to just use the kstrdup().
> >
> > Fixes: 265fd1991c1d ("ksmbd: use LOOKUP_BENEATH to prevent the out of share
> > access")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> Acked-by: Namjae Jeon <linkinjeon@kernel.org>
>
> Thanks for your patch!
diff mbox series

Patch

diff --git a/fs/ksmbd/misc.c b/fs/ksmbd/misc.c
index 6a19f4bc692d..60e7ac62c917 100644
--- a/fs/ksmbd/misc.c
+++ b/fs/ksmbd/misc.c
@@ -162,17 +162,14 @@  char *convert_to_nt_pathname(char *filename)
 {
 	char *ab_pathname;
 
-	if (strlen(filename) == 0) {
-		ab_pathname = kmalloc(2, GFP_KERNEL);
-		ab_pathname[0] = '\\';
-		ab_pathname[1] = '\0';
-	} else {
-		ab_pathname = kstrdup(filename, GFP_KERNEL);
-		if (!ab_pathname)
-			return NULL;
+	if (strlen(filename) == 0)
+		filename = "\\";
 
-		ksmbd_conv_path_to_windows(ab_pathname);
-	}
+	ab_pathname = kstrdup(filename, GFP_KERNEL);
+	if (!ab_pathname)
+		return NULL;
+
+	ksmbd_conv_path_to_windows(ab_pathname);
 	return ab_pathname;
 }