Skip to content

Commit 87ffb31

Browse files
Dan Carpentersmfrench
authored andcommitted
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: 265fd19 ("ksmbd: use LOOKUP_BENEATH to prevent the out of share access") Signed-off-by: Dan Carpenter <[email protected]> Acked-by: Namjae Jeon <[email protected]> Acked-by: Hyunchul Lee <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 4227f81 commit 87ffb31

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

fs/ksmbd/misc.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,14 @@ char *convert_to_nt_pathname(char *filename)
162162
{
163163
char *ab_pathname;
164164

165-
if (strlen(filename) == 0) {
166-
ab_pathname = kmalloc(2, GFP_KERNEL);
167-
ab_pathname[0] = '\\';
168-
ab_pathname[1] = '\0';
169-
} else {
170-
ab_pathname = kstrdup(filename, GFP_KERNEL);
171-
if (!ab_pathname)
172-
return NULL;
165+
if (strlen(filename) == 0)
166+
filename = "\\";
173167

174-
ksmbd_conv_path_to_windows(ab_pathname);
175-
}
168+
ab_pathname = kstrdup(filename, GFP_KERNEL);
169+
if (!ab_pathname)
170+
return NULL;
171+
172+
ksmbd_conv_path_to_windows(ab_pathname);
176173
return ab_pathname;
177174
}
178175

0 commit comments

Comments
 (0)