diff mbox series

[3/4] NFS: Use kmemdup_nul() in nfs_readdir_make_qstr()

Message ID 20200202225356.995080-4-trond.myklebust@hammerspace.com (mailing list archive)
State New, archived
Headers show
Series Readdir fixes | expand

Commit Message

Trond Myklebust Feb. 2, 2020, 10:53 p.m. UTC
The directory strings stored in the readdir cache may be used with
printk(), so it is better to ensure they are nul-terminated.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 fs/nfs/dir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Benjamin Coddington Feb. 3, 2020, 2:22 p.m. UTC | #1
On 2 Feb 2020, at 17:53, Trond Myklebust wrote:

> The directory strings stored in the readdir cache may be used with
> printk(), so it is better to ensure they are nul-terminated.
>
> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> ---
>  fs/nfs/dir.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
> index 90467b44ec13..60387dec9032 100644
> --- a/fs/nfs/dir.c
> +++ b/fs/nfs/dir.c
> @@ -199,7 +199,7 @@ static
>  int nfs_readdir_make_qstr(struct qstr *string, const char *name, 
> unsigned int len)
>  {
>  	string->len = len;
> -	string->name = kmemdup(name, len, GFP_KERNEL);
> +	string->name = kmemdup_nul(name, len, GFP_KERNEL);
>  	if (string->name == NULL)
>  		return -ENOMEM;
>  	/*

Reviewed-by: Benjamin Coddington <bcodding@redhat.com>

Ben
diff mbox series

Patch

diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 90467b44ec13..60387dec9032 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -199,7 +199,7 @@  static
 int nfs_readdir_make_qstr(struct qstr *string, const char *name, unsigned int len)
 {
 	string->len = len;
-	string->name = kmemdup(name, len, GFP_KERNEL);
+	string->name = kmemdup_nul(name, len, GFP_KERNEL);
 	if (string->name == NULL)
 		return -ENOMEM;
 	/*