]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
ksmbd: missing check for NULL in convert_to_nt_pathname()
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 30 Sep 2021 12:24:56 +0000 (15:24 +0300)
committerSteve French <stfrench@microsoft.com>
Fri, 1 Oct 2021 01:00:05 +0000 (20:00 -0500)
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>
Acked-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/ksmbd/misc.c

index 6a19f4bc692d3008f47e1d49a4de46f7312def28..60e7ac62c9172f5cac831b677f184f045a4a0245 100644 (file)
@@ -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;
 }