All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Chuck Lever <chuck.lever@oracle.com>
Cc: linux-nfs@vger.kernel.org
Subject: Re: [PATCH] NFS: fix nfs_parse_ip_address() corner case
Date: Thu, 4 Sep 2008 16:23:02 -0400	[thread overview]
Message-ID: <20080904202302.GD13981@fieldses.org> (raw)
In-Reply-To: <20080903203414.3322.97607.stgit-lQeC5l55kZ7wdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>

On Wed, Sep 03, 2008 at 04:35:57PM -0400, Chuck Lever wrote:
> Bruce observed that nfs_parse_ip_address() will successfully parse an
> IPv6 address that looks like this:
> 
>   "::1%"
> 
> A scope delimiter is present, but there is no scope ID following it.
> This is harmless, as it would simply set the scope ID to zero.  However,
> in some cases we would like to flag this as an improperly formed
> address.
> 
> We are now also careful to reject addresses where garbage follows the
> address (up to the length of the string), instead of ignoring the
> non-address characters; and where the scope ID is nonsense (not a valid
> device name, but also not numeric).  Before, both of these cases would
> result in a harmless zero scope ID.

Slightly irrelevant, but same comment as before--wouldn't it be easier
to follow the logic if instead of:

	p = kstrndup(...)
	if (p) {
		do stuff for successful case
		....
		return 1;
	}

	return 0;

it were:

	p = kstrndup(...)
	if (!p)
		return 0;
	do stuff for successful case
	...
	return 1;

e.g., the below, on top of yours. (Untested.)

Might also combine the two final exits in the usual way:

	out:
		kfree(p);
		return ret;

--b.

diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index a9f5a12..fcee897 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -733,6 +733,8 @@ static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
 {
 	size_t len = (string + str_len) - delim - 1;
 	char *p;
+	unsigned long scope_id = 0;
+	struct net_device *dev;
 
 	if (len == 0)
 		return 1;
@@ -744,29 +746,25 @@ static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
 		return 0;
 
 	p = kstrndup(delim + 1, len, GFP_KERNEL);
-	if (p) {
-		unsigned long scope_id = 0;
-		struct net_device *dev;
-
-		dev = dev_get_by_name(&init_net, p);
-		if (dev != NULL) {
-			scope_id = dev->ifindex;
-			dev_put(dev);
-		} else {
-			if (strict_strtoul(p, 10, &scope_id) == 0) {
-				kfree(p);
-				return 0;
-			}
-		}
-
-		kfree(p);
+	if (!p)
+		return 0;
 
-		sin6->sin6_scope_id = scope_id;
-		dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
-		return 1;
+	dev = dev_get_by_name(&init_net, p);
+	if (dev != NULL) {
+		scope_id = dev->ifindex;
+		dev_put(dev);
+	} else {
+		if (strict_strtoul(p, 10, &scope_id) == 0) {
+			kfree(p);
+			return 0;
+		}
 	}
 
-	return 0;
+	kfree(p);
+
+	sin6->sin6_scope_id = scope_id;
+	dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
+	return 1;
 }
 
 static void nfs_parse_ipv6_address(char *string, size_t str_len,

  parent reply	other threads:[~2008-09-04 20:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-03 20:35 [PATCH] NFS: fix nfs_parse_ip_address() corner case Chuck Lever
     [not found] ` <20080903203414.3322.97607.stgit-lQeC5l55kZ7wdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-09-04 20:23   ` J. Bruce Fields [this message]
2008-09-04 21:36     ` Chuck Lever
     [not found]       ` <76bd70e30809041436y4a8fc1d2hb8230cb7aba17f26-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-09-05 21:58         ` J. Bruce Fields
  -- strict thread matches above, loose matches on Subject: below --
2008-08-22 18:24 Chuck Lever
     [not found] ` <20080822182419.19572.34705.stgit-meopP2rzCrTwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-08-26 18:39   ` J. Bruce Fields
2008-08-26 20:24     ` Chuck Lever
2008-08-26 20:28       ` J. Bruce Fields
2008-08-26 20:36         ` Chuck Lever
2008-08-26 20:45           ` J. Bruce Fields

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=20080904202302.GD13981@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.