mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: yuehaibing@huawei.com
Cc: kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH] ipv4: fib_rules: Fix possible infinite loop in fib_empty_table
Date: Fri, 28 Dec 2018 21:15:03 -0800 (PST)	[thread overview]
Message-ID: <20181228.211503.1983080144355610600.davem@davemloft.net> (raw)
In-Reply-To: <20181226083420.20436-1-yuehaibing@huawei.com>

From: YueHaibing <yuehaibing@huawei.com>
Date: Wed, 26 Dec 2018 16:34:20 +0800

> diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
> index f8eb78d..1567e12 100644
> --- a/net/ipv4/fib_rules.c
> +++ b/net/ipv4/fib_rules.c
> @@ -200,9 +200,13 @@ static struct fib_table *fib_empty_table(struct net *net)
>  {
>  	u32 id;
>  
> -	for (id = 1; id <= RT_TABLE_MAX; id++)
> +	for (id = 1; id <= RT_TABLE_MAX; id++) {
>  		if (!fib_get_table(net, id))
>  			return fib_new_table(net, id);
> +
> +		if (id == RT_TABLE_MAX)
> +			break;
> +	}
>  	return NULL;
>  }

The loop now has two exit conditions, one of which (by your analysis
is completely impossible).

Please clean this up into a loop with better structure and no
impossible tests.  One approach could be simply:

	id = 1;
	while (1) {
	...
		if (id++ == RT_TABLE_MAX)
			break;
	}

Or even:

	id = 0;
	while (++id) {
	...
	}

  reply	other threads:[~2018-12-29  5:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-26  8:34 YueHaibing
2018-12-29  5:15 ` David Miller [this message]
2018-12-29  6:46   ` YueHaibing

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=20181228.211503.1983080144355610600.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=yoshfuji@linux-ipv6.org \
    --cc=yuehaibing@huawei.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

all inboxes | Powered by JetHome®