Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3270617imm; Mon, 4 Jun 2018 00:06:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIy4QElVLhPmU4nFWkZuGFYfSi541Vfh7c+bwlObeWu3mCTk3Ekhv0WJeU4tPcJyuM2k/wG X-Received: by 2002:a62:5841:: with SMTP id m62-v6mr19943336pfb.116.1528095990005; Mon, 04 Jun 2018 00:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528095989; cv=none; d=google.com; s=arc-20160816; b=F+/1S4G2I2q7EpSHkZSGkdDMP5/kQrm4JhjzZo/G076W8M+K3NfK15wRK7PjWrC7MT UUEaM3LT5r6kMM0v8viLG16KToORXDFVfy/W6BDHaSceyxbkDzgqwaA8i9SV4rrW8kpj Beqrtp4+98C0sUDfoLHzWh7QqhMcfgOgqKWmCUYge4lGtc6MiBAscvqVwgFb135DoCvd FiDBAKAheYjSppEbPxscXULX4nWV3pVtRufumHEJAXj/ZfWsiYV48xPXRN/KKH421C8l M8LMN5slTk6hmPAgHADYM5nV9LU1F3J2JyCfKkkO7yemlUE/n/WzdfgMh0kvjPdBd62T axXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=Sip+gPV6VNUKwS590wULfsTVX/MA9Nf1k0rYfOHvFKM=; b=0ViBOgZXSHzd71LZdR+Qe3qwMlWycSsxEmq8Oy5+iu3d+gJFjQefSpqnXYQFJji4kN ENfu3y6VScoRfbSTgKFakCRL4q86mglca7i5VKA6ZkT6/8Un/F1U5tvDEdCYxwheMdpX wSVA2R/tuEUr8sZ38yjNoObbBVGxy30GV8LSIHF9s03Qx1vNKR4x3RqwPrTO1yTzHZh6 v3cHHStrEU5Q3F4VHLkHrVMB+GhXn/zCRmBXYIM36Syo5ASJMbLCKl5KTx5rxnVZyOkU jsG8WnwWS4F7YZMF5EJ/61H0l1FmPgKlFwXcyjmRx/gnKPSjMLl5EZwzQZaTAF8Zb9RS noAA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h26-v6si5015192pfd.253.2018.06.04.00.06.15; Mon, 04 Jun 2018 00:06:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753949AbeFDHF3 (ORCPT + 99 others); Mon, 4 Jun 2018 03:05:29 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:8630 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751796AbeFDHF1 (ORCPT ); Mon, 4 Jun 2018 03:05:27 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 39091BD1AC3E7; Mon, 4 Jun 2018 15:05:12 +0800 (CST) Received: from linux-work.huawei.com (10.67.189.174) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.382.0; Mon, 4 Jun 2018 15:05:06 +0800 From: nixiaoming To: , , , CC: , , Subject: [PATCH] net/dns_resolver: dns_query Modify parameter checking to avoid dead code Date: Mon, 4 Jun 2018 14:40:31 +0800 Message-ID: <20180604064031.116472-1-nixiaoming@huawei.com> X-Mailer: git-send-email 2.10.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.189.174] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 "[:]" */ @@ -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