Skip to contentSkip to conversation

ksmbd: missing check for NULL in convert_to_nt_pathname()

PATCH In review Dan Carpenter 3 participants 3 messages Sep 30, 2021 – Oct 1, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ksmbd: missing check for NULL in convert_to_nt_pathname()

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")
---
 fs/ksmbd/misc.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
fs/ksmbd/misc.c +7 -10
index 6a19f4bc692d..60e7ac62c917 100644
@@ -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;
 }
 
Signature · 1 line
2.20.1
#2 lore raw

Added the acked-bys and pushed to ksmbd-for-next

Quoted 11 lines · Namjae Jeon

2021-09-30 21:24 GMT+09:00, Dan Carpenter <[email protected]>:

Quoted 6 lines

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")

Thanks for your patch!

Signature · 3 lines
Thanks,

Steve