From: nixiaoming <nixiaoming@huawei.com>
To: <davem@davemloft.net>, <dhowells@redhat.com>,
<manuel.schoelling@gmx.de>, <wang840925@gmail.com>
Cc: <nixiaoming@huawei.com>, <linux-kernel@vger.kernel.org>,
<netdev@vger.kernel.org>
Subject: [PATCH] net/dns_resolver: dns_query Modify parameter checking to avoid dead code
Date: Mon, 4 Jun 2018 14:40:31 +0800 [thread overview]
Message-ID: <20180604064031.116472-1-nixiaoming@huawei.com> (raw)
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
next reply other threads:[~2018-06-04 6:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-04 6:40 nixiaoming [this message]
2018-06-04 18:25 ` [PATCH] net/dns_resolver: dns_query Modify parameter checking to avoid dead code Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180604064031.116472-1-nixiaoming@huawei.com \
--to=nixiaoming@huawei.com \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=manuel.schoelling@gmx.de \
--cc=netdev@vger.kernel.org \
--cc=wang840925@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox