about summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2013-10-25 14:25:38 +1000
committerAllan McRae <allan@archlinux.org>2013-10-25 14:28:32 +1000
commit894f3f1049135dcbeaab8f18690973663ef3147c (patch)
tree5be512d821ae330cb5cc88fb44f74b6184a34626 /sysdeps
parentb85545a67110b236676aec8000f52d8385465660 (diff)
downloadglibc-894f3f1049135dcbeaab8f18690973663ef3147c.tar.gz
glibc-894f3f1049135dcbeaab8f18690973663ef3147c.tar.xz
glibc-894f3f1049135dcbeaab8f18690973663ef3147c.zip
Fix incorrect getaddrinfo assertion trigger
[BZ #9954]

With the following /etc/hosts:
127.0.0.1       www.my-domain.es
127.0.1.1       www.my-domain.es
192.168.0.1     www.my-domain.es

Using getaddrinfo() on www.my-domain.es, trigger the following assertion:
../sysdeps/posix/getaddrinfo.c:1473: rfc3484_sort: Assertion
`src->results[i].native == -1 || src->results[i].native == a1_native' failed.

This is due to two different bugs:
- In rfc3484_sort() rule 7, src->results[i].native is assigned even if
src->results[i].index is -1, meaning that no interface is associated.
- In getaddrinfo() the source IP address used with the lo interface needs a
special case, as it can be any IP within 127.X.Y.Z.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/posix/getaddrinfo.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 0f4b88514f..e6ce4cfd63 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -1666,13 +1666,13 @@ rfc3484_sort (const void *p1, const void *p2, void *arg)
 
 	      /* Fill in the results in all the records.  */
 	      for (int i = 0; i < src->nresults; ++i)
-		if (src->results[i].index == a1_index)
+		if (a1_index != -1 && src->results[i].index == a1_index)
 		  {
 		    assert (src->results[i].native == -1
 			    || src->results[i].native == a1_native);
 		    src->results[i].native = a1_native;
 		  }
-		else if (src->results[i].index == a2_index)
+		else if (a2_index != -1 && src->results[i].index == a2_index)
 		  {
 		    assert (src->results[i].native == -1
 			    || src->results[i].native == a2_native);
@@ -2532,7 +2532,14 @@ getaddrinfo (const char *name, const char *service,
 			  tmp.addr[0] = 0;
 			  tmp.addr[1] = 0;
 			  tmp.addr[2] = htonl (0xffff);
-			  tmp.addr[3] = sinp->sin_addr.s_addr;
+			  /* Special case for lo interface, the source address
+			     being possibly different than the interface
+			     address. */
+			  if ((ntohl(sinp->sin_addr.s_addr) & 0xff000000)
+			      == 0x7f000000)
+			    tmp.addr[3] = htonl(0x7f000001);
+			  else
+			    tmp.addr[3] = sinp->sin_addr.s_addr;
 			}
 		      else
 			{