mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] nfsroot: Fix missing check for return value of strsep()
@ 2023-06-14 14:30 Chenyuan Mi
  2023-06-14 15:19 ` Trond Myklebust
  2023-06-14 15:23 ` Benjamin Coddington
  0 siblings, 2 replies; 3+ messages in thread
From: Chenyuan Mi @ 2023-06-14 14:30 UTC (permalink / raw)
  To: trond.myklebust; +Cc: anna, linux-nfs, linux-kernel, Chenyuan Mi

The strsep() function in root_nfs_parse_options() may return NULL 
if argument 'incoming' is NULL. Since 'incoming' has Null check in 
this function, it is also need to add Null check for return value
 of strsep().

Found by our static analysis tool.

Signed-off-by: Chenyuan Mi <cymi20@fudan.edu.cn>
---
 fs/nfs/nfsroot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/nfs/nfsroot.c b/fs/nfs/nfsroot.c
index 620329b7e6ae..55c594dede9f 100644
--- a/fs/nfs/nfsroot.c
+++ b/fs/nfs/nfsroot.c
@@ -198,7 +198,7 @@ static int __init root_nfs_parse_options(char *incoming, char *exppath,
 	 * Set the NFS remote path
 	 */
 	p = strsep(&incoming, ",");
-	if (*p != '\0' && strcmp(p, "default") != 0)
+	if (p != NULL && *p != '\0' && strcmp(p, "default") != 0)
 		if (root_nfs_copy(exppath, p, exppathlen))
 			return -1;
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] nfsroot: Fix missing check for return value of strsep()
  2023-06-14 14:30 [PATCH] nfsroot: Fix missing check for return value of strsep() Chenyuan Mi
@ 2023-06-14 15:19 ` Trond Myklebust
  2023-06-14 15:23 ` Benjamin Coddington
  1 sibling, 0 replies; 3+ messages in thread
From: Trond Myklebust @ 2023-06-14 15:19 UTC (permalink / raw)
  To: cymi20; +Cc: anna, linux-nfs, linux-kernel

On Wed, 2023-06-14 at 07:30 -0700, Chenyuan Mi wrote:
> [You don't often get email from cymi20@fudan.edu.cn. Learn why this
> is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> The strsep() function in root_nfs_parse_options() may return NULL
> if argument 'incoming' is NULL. Since 'incoming' has Null check in
> this function, it is also need to add Null check for return value
>  of strsep().
> 
> Found by our static analysis tool.
> 
> Signed-off-by: Chenyuan Mi <cymi20@fudan.edu.cn>
> ---
>  fs/nfs/nfsroot.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/nfs/nfsroot.c b/fs/nfs/nfsroot.c
> index 620329b7e6ae..55c594dede9f 100644
> --- a/fs/nfs/nfsroot.c
> +++ b/fs/nfs/nfsroot.c
> @@ -198,7 +198,7 @@ static int __init root_nfs_parse_options(char
> *incoming, char *exppath,
>          * Set the NFS remote path
>          */
>         p = strsep(&incoming, ",");
> -       if (*p != '\0' && strcmp(p, "default") != 0)
> +       if (p != NULL && *p != '\0' && strcmp(p, "default") != 0)
>                 if (root_nfs_copy(exppath, p, exppathlen))
>                         return -1;
> 

Huh? root_nfs_parse_options() is called from exactly two callsites, and
in both cases 'incoming' is guaranteed to be non-NULL.

NACKed
-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@hammerspace.com



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] nfsroot: Fix missing check for return value of strsep()
  2023-06-14 14:30 [PATCH] nfsroot: Fix missing check for return value of strsep() Chenyuan Mi
  2023-06-14 15:19 ` Trond Myklebust
@ 2023-06-14 15:23 ` Benjamin Coddington
  1 sibling, 0 replies; 3+ messages in thread
From: Benjamin Coddington @ 2023-06-14 15:23 UTC (permalink / raw)
  To: Chenyuan Mi; +Cc: trond.myklebust, anna, linux-nfs, linux-kernel

On 14 Jun 2023, at 10:30, Chenyuan Mi wrote:

> The strsep() function in root_nfs_parse_options() may return NULL
> if argument 'incoming' is NULL. Since 'incoming' has Null check in
> this function, it is also need to add Null check for return value
>  of strsep().

Incoming is checked to be non-NULL *before* sending it to strsep() here.

> Found by our static analysis tool.

The tool must be noticing that it is checked for NULL *after* strsep(),
which wouldn't matter to strsep() at all.

Ben


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-14 15:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-14 14:30 [PATCH] nfsroot: Fix missing check for return value of strsep() Chenyuan Mi
2023-06-14 15:19 ` Trond Myklebust
2023-06-14 15:23 ` Benjamin Coddington

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®