]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net/dns_resolver: consolidate namelen checks in dns_query
authorThorsten Blum <thorsten.blum@linux.dev>
Mon, 25 May 2026 09:54:01 +0000 (11:54 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 28 May 2026 00:00:44 +0000 (17:00 -0700)
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>
Link: https://patch.msgid.link/20260525095400.821912-3-thorsten.blum@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/dns_resolver/dns_query.c

index e1c09d7b8200774d39c9b9b83cd058706d022248..c250d82cad9650cecc2fe79e8667a97d663d3363 100644 (file)
@@ -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);