[PATCH net-next] net/dns_resolver: consolidate namelen checks in dns_query

Thorsten Blum posted 1 patch 2 weeks ago
net/dns_resolver/dns_query.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
[PATCH net-next] net/dns_resolver: consolidate namelen checks in dns_query
Posted by Thorsten Blum 2 weeks ago
Consolidate the namelen checks and return -EINVAL early if needed. Drop
the namelen == 0 check since it is covered by namelen < 3.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 net/dns_resolver/dns_query.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/net/dns_resolver/dns_query.c b/net/dns_resolver/dns_query.c
index e1c09d7b8200..c250d82cad96 100644
--- a/net/dns_resolver/dns_query.c
+++ b/net/dns_resolver/dns_query.c
@@ -73,7 +73,7 @@ int dns_query(struct net *net,
 	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;
 
 	/* construct the query key description as "[<type>:]<name>" */
@@ -86,8 +86,6 @@ int dns_query(struct net *net,
 		desclen += typelen + 1;
 	}
 
-	if (namelen < 3 || namelen > 255)
-		return -EINVAL;
 	desclen += namelen + 1;
 
 	desc = kmalloc(desclen, GFP_KERNEL);
Re: [PATCH net-next] net/dns_resolver: consolidate namelen checks in dns_query
Posted by Simon Horman 1 week, 5 days ago
On Mon, May 25, 2026 at 11:54:01AM +0200, Thorsten Blum wrote:
> Consolidate the namelen checks and return -EINVAL early if needed. Drop
> the namelen == 0 check since it is covered by namelen < 3.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>

Reviewed-by: Simon Horman <horms@kernel.org>