[Spice-devel] [spice-common 1/2] ssl-verify: Handle NULL return from g_inet_address_new_from_string()

Christophe Fergeau cfergeau at redhat.com
Fri Oct 23 02:45:55 PDT 2015


It will return NULL if the string we pass it cannot be parsed.
---
 common/ssl_verify.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/common/ssl_verify.c b/common/ssl_verify.c
index 867c54f..817cf7b 100644
--- a/common/ssl_verify.c
+++ b/common/ssl_verify.c
@@ -200,8 +200,12 @@ static int verify_hostname(X509* cert, const char *hostname)
                 found_dns_name = 1;
 
                 ip = g_inet_address_new_from_string(hostname);
-                ip_len = g_inet_address_get_native_size(ip);
-                ip_binary = g_inet_address_to_bytes(ip);
+                if (ip != NULL) {
+                    ip_len = g_inet_address_get_native_size(ip);
+                    ip_binary = g_inet_address_to_bytes(ip);
+                } else {
+                    spice_warning("Could not parse hostname: %s", hostname);
+                }
 
                 alt_ip_len = ASN1_STRING_length(name->d.iPAddress);
 
-- 
2.5.0



More information about the Spice-devel mailing list