Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3918401imm; Mon, 4 Jun 2018 11:26:14 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLJ6+ipEyPppzadfu5qHxJgHiF0TSbM8/NOvPNn1Qa5TU4ohyCmzDNUWf4qooKoIGuzFZm+ X-Received: by 2002:a17:902:2f84:: with SMTP id t4-v6mr23529786plb.24.1528136774802; Mon, 04 Jun 2018 11:26:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528136774; cv=none; d=google.com; s=arc-20160816; b=zUC0D+7a+LelPZdLF9/0vPuAzQGkIFEGXjqQXSQYt9V75Cuysm33CKClpJ2f3uXc2m TrJwebjwN8Qm1ANq+70wb9BipJ9zuMGi2bNxbOztmK2O+XpcypmSt4SHNCYCOFkyq0zz 08X8dR5ty7+FtWp4fB+hMHdtabefbWG010o2AQm8vX5fTJ7FVcj+3BdPAWU99An90yW7 I8jVAhV0H03CnGLbjTTnyKK0wzBTcUaR5btWQ6z9H57K1NX61GFKkMWN/Lh4vLEbKwZn 7tFUYVD9Q2BdqMelVPj0hNX9BH+cAtjWK7X0sab3HhDCUYCknJ9yWveXF4h6r8DJlbSi ddBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=ldtTksMBIr7OQDPFabPi9Tp16OwlMYUghioisouh8rk=; b=lO4j6b7I7CQ02DzsY7H/vROT66WRULwGnFbyZw247fymVUxVWZqMcjo3/+VRRxYREz l8QPjPp4FaI3oZUw30yXDv7eAeIYSO0G9Pe0QGAxVEzxr+JT5X8Kq8/lVuzgK87evYFa kBmRPhLoIxAEDf3XonKnh78uCffA72qtQIkZRviH25pGgVD42hmdUIzp3FvyZuLsvw3u d8bTkD7lTWR5KAVgzemTfG60mV4qhpkmp4xiCWcvs3QYuQ1sB6BnrzGLZATx7VbUnpBw 3rAncNA7q4n9cxuxadwi5ykVASN/8wRDzK27rD9OsXqZuLgoEz9pOaiegH+X1dcbXIzB bRDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=N8SmEPsM; 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 m37-v6si47236825pla.148.2018.06.04.11.26.00; Mon, 04 Jun 2018 11:26:14 -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; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=N8SmEPsM; 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 S1751510AbeFDSZN (ORCPT + 99 others); Mon, 4 Jun 2018 14:25:13 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:38322 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751332AbeFDSZM (ORCPT ); Mon, 4 Jun 2018 14:25:12 -0400 Received: by mail-wm0-f65.google.com with SMTP id m129-v6so150669wmb.3 for ; Mon, 04 Jun 2018 11:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ldtTksMBIr7OQDPFabPi9Tp16OwlMYUghioisouh8rk=; b=N8SmEPsMq/XbpE2dCiApFHlABKdyBDUK6JWt+CJg+q2VC2DOHVn2emTwcchXEiJYVR gj+kGvToNdGZUUcKdsPMvyEq9hIsLUCU4/utBT3Oegg25bic1nPqMbNf1Yy8Ksd3glIK nCg8xgz4NZMhno/25CqiudmYl8xfZWh6mIqKdjyG5rVhjJH8TLOvb8zFBHVlmVFjhpnC H2ngDJj/W92O44Ojf/025fBAPvlYtA4NowTyBozApa6pfhLaDvSlhoOdCeQvZPgLZbVG K172Y3Ft1nH9XRrXJBH6bAUd58wc9K0ruPtMACbQj60k9N82wajS1/A9+cnKx53xbVxt fRVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ldtTksMBIr7OQDPFabPi9Tp16OwlMYUghioisouh8rk=; b=g3ioAi+rTDkXjiGOg1q+Mn2UaVvUcYsWA6KU0JwRiI7tUCGMuz8JnIKzh+dOX6vENy KzYrbg6KCsSerjAuU/eQf2+Yo4CpQLqeCIo+EJ1HBEgcOAJZgOEufoM4a0kDwjA0g4g4 iQQgBmSzHl4qKZ0JrCMA7YWDhnTn9a6tRIToU4e1GOosFMB8l2BYmtiJ+hyPF2Vx5Ig3 Yvrz1LB6qzDrRJR0ea27KKhEo0TlGKrVAMAnGypDbpgmbXokqgEd/u5wRmzFUSNs0S9G 7Koymmx2zjX/qMUpnGjOONNGhRlJ2JqWyQlN0jRKgWpFNabF1O8wHKDBwdQGbGJPfhte tmEA== X-Gm-Message-State: ALKqPwevfjVck39UaUvoVdq8te/QRdpXlDX5beou4bcTcbz4gVo7gCdG E9ZdM/eqon8wdEm2AM3GW8JvRw== X-Received: by 2002:a50:ac53:: with SMTP id w19-v6mr24829603edc.51.1528136711088; Mon, 04 Jun 2018 11:25:11 -0700 (PDT) Received: from netronome.com (penelope-musen.amstelveen.horms.nl. [2001:470:7eb3:404:c685:8ff:fe7c:9971]) by smtp.gmail.com with ESMTPSA id n30-v6sm14903678edd.36.2018.06.04.11.25.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Jun 2018 11:25:10 -0700 (PDT) Date: Mon, 4 Jun 2018 20:25:09 +0200 From: Simon Horman To: nixiaoming Cc: davem@davemloft.net, dhowells@redhat.com, manuel.schoelling@gmx.de, wang840925@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH] net/dns_resolver: dns_query Modify parameter checking to avoid dead code Message-ID: <20180604182508.273hg4nnsykqo3zl@netronome.com> References: <20180604064031.116472-1-nixiaoming@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180604064031.116472-1-nixiaoming@huawei.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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 "[:]" */ > @@ -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 >