All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix non-IPv6 host name lookups (5.0.6)
@ 2011-06-29 14:39 Leonardo Chiquitto
  2011-06-30  6:37 ` Ian Kent
  0 siblings, 1 reply; 3+ messages in thread
From: Leonardo Chiquitto @ 2011-06-29 14:39 UTC (permalink / raw)
  To: autofs

Fix non-IPv6 host name lookups

Commit 5b083026 ("fix ipv6 name for lookup") causes a regression
in regular (non-IPv6) host name lookups: it trims the first host
name character even when it's not a "[". This patch fixes the issue.

---
 modules/replicated.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Index: autofs/modules/replicated.c
===================================================================
--- autofs.orig/modules/replicated.c
+++ autofs/modules/replicated.c
@@ -1125,15 +1125,17 @@ static int add_host_addrs(struct host **
 	}
 	len = strlen(name);
 
-	if (name[0] == '[' && name[--len] == ']')
+	if (name[0] == '[' && name[--len] == ']') {
 		name[len] = '\0';
+		memmove(name, name + 1, len);
+	}
 
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_flags = AI_NUMERICHOST;
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_socktype = SOCK_DGRAM;
 
-	ret = getaddrinfo(name + 1, NULL, &hints, &ni);
+	ret = getaddrinfo(name, NULL, &hints, &ni);
 	if (ret)
 		goto try_name;
 
@@ -1153,7 +1155,7 @@ try_name:
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_socktype = SOCK_DGRAM;
 
-	ret = getaddrinfo(name + 1, NULL, &hints, &ni);
+	ret = getaddrinfo(name, NULL, &hints, &ni);
 	if (ret) {
 		error(LOGOPT_ANY, "hostname lookup failed: %s",
 		      gai_strerror(ret));

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix non-IPv6 host name lookups (5.0.6)
  2011-06-29 14:39 [PATCH] Fix non-IPv6 host name lookups (5.0.6) Leonardo Chiquitto
@ 2011-06-30  6:37 ` Ian Kent
  2011-06-30  7:18   ` Ian Kent
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Kent @ 2011-06-30  6:37 UTC (permalink / raw)
  To: Leonardo Chiquitto; +Cc: autofs

On Wed, 2011-06-29 at 11:39 -0300, Leonardo Chiquitto wrote:
> Fix non-IPv6 host name lookups
> 
> Commit 5b083026 ("fix ipv6 name for lookup") causes a regression
> in regular (non-IPv6) host name lookups: it trims the first host
> name character even when it's not a "[". This patch fixes the issue.

Gaah .... yep.

> 
> ---
>  modules/replicated.c |    8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> Index: autofs/modules/replicated.c
> ===================================================================
> --- autofs.orig/modules/replicated.c
> +++ autofs/modules/replicated.c
> @@ -1125,15 +1125,17 @@ static int add_host_addrs(struct host **
>  	}
>  	len = strlen(name);
>  
> -	if (name[0] == '[' && name[--len] == ']')
> +	if (name[0] == '[' && name[--len] == ']') {
>  		name[len] = '\0';
> +		memmove(name, name + 1, len);
> +	}
>  
>  	memset(&hints, 0, sizeof(hints));
>  	hints.ai_flags = AI_NUMERICHOST;
>  	hints.ai_family = AF_UNSPEC;
>  	hints.ai_socktype = SOCK_DGRAM;
>  
> -	ret = getaddrinfo(name + 1, NULL, &hints, &ni);
> +	ret = getaddrinfo(name, NULL, &hints, &ni);
>  	if (ret)
>  		goto try_name;
>  
> @@ -1153,7 +1155,7 @@ try_name:
>  	hints.ai_family = AF_UNSPEC;
>  	hints.ai_socktype = SOCK_DGRAM;
>  
> -	ret = getaddrinfo(name + 1, NULL, &hints, &ni);
> +	ret = getaddrinfo(name, NULL, &hints, &ni);
>  	if (ret) {
>  		error(LOGOPT_ANY, "hostname lookup failed: %s",
>  		      gai_strerror(ret));
> 
> _______________________________________________
> autofs mailing list
> autofs@linux.kernel.org
> http://linux.kernel.org/mailman/listinfo/autofs

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix non-IPv6 host name lookups (5.0.6)
  2011-06-30  6:37 ` Ian Kent
@ 2011-06-30  7:18   ` Ian Kent
  0 siblings, 0 replies; 3+ messages in thread
From: Ian Kent @ 2011-06-30  7:18 UTC (permalink / raw)
  To: Leonardo Chiquitto; +Cc: autofs

On Thu, 2011-06-30 at 14:37 +0800, Ian Kent wrote:
> On Wed, 2011-06-29 at 11:39 -0300, Leonardo Chiquitto wrote:
> > Fix non-IPv6 host name lookups
> > 
> > Commit 5b083026 ("fix ipv6 name for lookup") causes a regression
> > in regular (non-IPv6) host name lookups: it trims the first host
> > name character even when it's not a "[". This patch fixes the issue.
> 
> Gaah .... yep.
> 
> > 
> > ---
> >  modules/replicated.c |    8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> > 
> > Index: autofs/modules/replicated.c
> > ===================================================================
> > --- autofs.orig/modules/replicated.c
> > +++ autofs/modules/replicated.c
> > @@ -1125,15 +1125,17 @@ static int add_host_addrs(struct host **
> >  	}
> >  	len = strlen(name);
> >  
> > -	if (name[0] == '[' && name[--len] == ']')
> > +	if (name[0] == '[' && name[--len] == ']') {
> >  		name[len] = '\0';
> > +		memmove(name, name + 1, len);
> > +	}
> >  
> >  	memset(&hints, 0, sizeof(hints));
> >  	hints.ai_flags = AI_NUMERICHOST;
> >  	hints.ai_family = AF_UNSPEC;
> >  	hints.ai_socktype = SOCK_DGRAM;
> >  
> > -	ret = getaddrinfo(name + 1, NULL, &hints, &ni);
> > +	ret = getaddrinfo(name, NULL, &hints, &ni);
> >  	if (ret)
> >  		goto try_name;
> >  
> > @@ -1153,7 +1155,7 @@ try_name:
> >  	hints.ai_family = AF_UNSPEC;
> >  	hints.ai_socktype = SOCK_DGRAM;
> >  
> > -	ret = getaddrinfo(name + 1, NULL, &hints, &ni);
> > +	ret = getaddrinfo(name, NULL, &hints, &ni);
> >  	if (ret) {
> >  		error(LOGOPT_ANY, "hostname lookup failed: %s",
> >  		      gai_strerror(ret));
> > 

I'd prefer to avoid the use of memmove(3) though so I think this will
also fix it.

autofs-5.0.6 - fix ipv6 name for lookup fix

From: Ian Kent <ikent@redhat.com>

Fix an error in the recent ipv6 name for lookup patch.
---

 modules/replicated.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)


diff --git a/modules/replicated.c b/modules/replicated.c
index 7f2b892..a10a817 100644
--- a/modules/replicated.c
+++ b/modules/replicated.c
@@ -1111,7 +1111,8 @@ static int add_host_addrs(struct host **list, const char *host,
 			  unsigned int weight, unsigned int options)
 {
 	struct addrinfo hints, *ni, *this;
-	char *name = strdup(host);
+	char *n_ptr;
+	char *name = n_ptr = strdup(host);
 	int len;
 	char buf[MAX_ERR_BUF];
 	int rr = 0;
@@ -1125,15 +1126,17 @@ static int add_host_addrs(struct host **list, const char *host,
 	}
 	len = strlen(name);
 
-	if (name[0] == '[' && name[--len] == ']')
+	if (name[0] == '[' && name[--len] == ']') {
 		name[len] = '\0';
+		name++;
+	}
 
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_flags = AI_NUMERICHOST;
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_socktype = SOCK_DGRAM;
 
-	ret = getaddrinfo(name + 1, NULL, &hints, &ni);
+	ret = getaddrinfo(name, NULL, &hints, &ni);
 	if (ret)
 		goto try_name;
 
@@ -1153,7 +1156,7 @@ try_name:
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_socktype = SOCK_DGRAM;
 
-	ret = getaddrinfo(name + 1, NULL, &hints, &ni);
+	ret = getaddrinfo(name, NULL, &hints, &ni);
 	if (ret) {
 		error(LOGOPT_ANY, "hostname lookup failed: %s",
 		      gai_strerror(ret));
@@ -1172,7 +1175,7 @@ try_name:
 	}
 	freeaddrinfo(ni);
 done:
-	free(name);
+	free(n_ptr);
 	return ret;
 }

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-30  7:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-29 14:39 [PATCH] Fix non-IPv6 host name lookups (5.0.6) Leonardo Chiquitto
2011-06-30  6:37 ` Ian Kent
2011-06-30  7:18   ` Ian Kent

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.