LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] net/dns_resolver: dns_query Modify parameter checking to avoid dead code
@ 2018-06-04  6:40 nixiaoming
  2018-06-04 18:25 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: nixiaoming @ 2018-06-04  6:40 UTC (permalink / raw)
  To: davem, dhowells, manuel.schoelling, wang840925
  Cc: nixiaoming, linux-kernel, netdev

After commit 1a4240f4764a ("DNS: Separate out CIFS DNS Resolver code")
a dead code exists in function dns_query

code show as below:
	if (!name || namelen == 0)
		return -EINVAL;
	/*Now the value of "namelen" cannot be equal to 0*/
	....
	if (!namelen) /*The condition "!namelen"" cannot be true*/
		namelen = strnlen(name, 256); /*deadcode*/

Modify parameter checking to avoid dead code

Signed-off-by: nixiaoming <nixiaoming@huawei.com>
---
 net/dns_resolver/dns_query.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/net/dns_resolver/dns_query.c b/net/dns_resolver/dns_query.c
index 49da670..f2acee2 100644
--- a/net/dns_resolver/dns_query.c
+++ b/net/dns_resolver/dns_query.c
@@ -81,7 +81,9 @@ int dns_query(const char *type, const char *name, size_t namelen,
 	kenter("%s,%*.*s,%zu,%s",
 	       type, (int)namelen, (int)namelen, name, namelen, options);
 
-	if (!name || namelen == 0)
+	if (!name || namelen < 3 || namelen > 255)
+		return -EINVAL;
+	if (namelen > strnlen(name, 256)) /*maybe only need part of name*/
 		return -EINVAL;
 
 	/* construct the query key description as "[<type>:]<name>" */
@@ -94,10 +96,6 @@ int dns_query(const char *type, const char *name, size_t namelen,
 		desclen += typelen + 1;
 	}
 
-	if (!namelen)
-		namelen = strnlen(name, 256);
-	if (namelen < 3 || namelen > 255)
-		return -EINVAL;
 	desclen += namelen + 1;
 
 	desc = kmalloc(desclen, GFP_KERNEL);
-- 
2.10.1

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

* Re: [PATCH] net/dns_resolver: dns_query Modify parameter checking to avoid dead code
  2018-06-04  6:40 [PATCH] net/dns_resolver: dns_query Modify parameter checking to avoid dead code nixiaoming
@ 2018-06-04 18:25 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2018-06-04 18:25 UTC (permalink / raw)
  To: nixiaoming
  Cc: davem, dhowells, manuel.schoelling, wang840925, linux-kernel, netdev

On Mon, Jun 04, 2018 at 02:40:31PM +0800, nixiaoming wrote:
> After commit 1a4240f4764a ("DNS: Separate out CIFS DNS Resolver code")
> a dead code exists in function dns_query
> 
> code show as below:
> 	if (!name || namelen == 0)
> 		return -EINVAL;
> 	/*Now the value of "namelen" cannot be equal to 0*/
> 	....
> 	if (!namelen) /*The condition "!namelen"" cannot be true*/
> 		namelen = strnlen(name, 256); /*deadcode*/
> 
> Modify parameter checking to avoid dead code
> 
> Signed-off-by: nixiaoming <nixiaoming@huawei.com>
> ---
>  net/dns_resolver/dns_query.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/net/dns_resolver/dns_query.c b/net/dns_resolver/dns_query.c
> index 49da670..f2acee2 100644
> --- a/net/dns_resolver/dns_query.c
> +++ b/net/dns_resolver/dns_query.c
> @@ -81,7 +81,9 @@ int dns_query(const char *type, const char *name, size_t namelen,
>  	kenter("%s,%*.*s,%zu,%s",
>  	       type, (int)namelen, (int)namelen, name, namelen, options);
>  
> -	if (!name || namelen == 0)
> +	if (!name || namelen < 3 || namelen > 255)
> +		return -EINVAL;
> +	if (namelen > strnlen(name, 256)) /*maybe only need part of name*/

The line above seems to change the behaviour of this function.
I think it and the previous line can be dropped.

>  		return -EINVAL;
>  
>  	/* construct the query key description as "[<type>:]<name>" */
> @@ -94,10 +96,6 @@ int dns_query(const char *type, const char *name, size_t namelen,
>  		desclen += typelen + 1;
>  	}
>  
> -	if (!namelen)
> -		namelen = strnlen(name, 256);
> -	if (namelen < 3 || namelen > 255)
> -		return -EINVAL;
>  	desclen += namelen + 1;

I think the initialisation of desclen can be changed
to include namelen + 1 without changing the behaviour of this function.

>  
>  	desc = kmalloc(desclen, GFP_KERNEL);
> -- 
> 2.10.1
> 

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

end of thread, other threads:[~2018-06-04 18:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-04  6:40 [PATCH] net/dns_resolver: dns_query Modify parameter checking to avoid dead code nixiaoming
2018-06-04 18:25 ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).