[glib/glib-2-42] gresolver.c: Windows: Fix IPv6 Address Handling



commit 4421d927639973e9b7afad820722521d8d557446
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Jan 19 11:03:57 2015 +0800

    gresolver.c: Windows: Fix IPv6 Address Handling
    
    Check the IPv6 addresses on Windows, as we need to reject those that have
    brackets/ports around them as valid addresses in this form would have been
    accepted during the call to g_inet_address_new_from_string ().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=730352

 gio/gresolver.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/gio/gresolver.c b/gio/gresolver.c
index e73ef0e..a6b12d6 100644
--- a/gio/gresolver.c
+++ b/gio/gresolver.c
@@ -294,6 +294,7 @@ handle_ip_address (const char  *hostname,
                    GError     **error)
 {
   GInetAddress *addr;
+
 #ifndef G_OS_WIN32
   struct in_addr ip4addr;
 #endif
@@ -307,21 +308,30 @@ handle_ip_address (const char  *hostname,
 
   *addrs = NULL;
 
+#ifdef G_OS_WIN32
+
+  /* Reject IPv6 addresses that have brackets ('[' or ']') and/or port numbers,
+   * as no valid addresses should contain these at this point.
+   * Non-standard IPv4 addresses would be rejected during the call to
+   * getaddrinfo() later.
+   */
+  if (strrchr (hostname, '[') != NULL ||
+      strrchr (hostname, ']') != NULL)
+#else
+
   /* Reject non-standard IPv4 numbers-and-dots addresses.
    * g_inet_address_new_from_string() will have accepted any "real" IP
    * address, so if inet_aton() succeeds, then it's an address we want
-   * to reject.  This check is not necessary for Windows, as getaddrinfo()
-   * already rejects such IPv4 addresses on Windows.
+   * to reject.
    */
-#ifndef G_OS_WIN32
   if (inet_aton (hostname, &ip4addr))
+#endif
     {
       g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND,
                    _("Error resolving '%s': %s"),
                    hostname, gai_strerror (EAI_NONAME));
       return TRUE;
     }
-#endif
 
   return FALSE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]