[bgpd] fix crash on startup if compiled IPv4-only

2008-01-29 Jorge Boncompte <jorge@dti2.net>

	* bgp_network.c: (bgp_socket) IPv4-only version crashes if -l is not
	  used as address will be null.
diff --git a/bgpd/ChangeLog b/bgpd/ChangeLog
index 70bcc0f..777801c 100644
--- a/bgpd/ChangeLog
+++ b/bgpd/ChangeLog
@@ -1,3 +1,8 @@
+2008-01-29 Jorge Boncompte <jorge@dti2.net>
+
+	* bgp_network.c: (bgp_socket) IPv4-only version crashes if -l is not
+	  used as address will be null.
+
 2007-12-22 Paul Jakma <paul.jakma@sun.com>
 
 	* Fix series of vulnerabilities reported by "Mu Security
diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c
index 6b8c8a4..8452545 100644
--- a/bgpd/bgp_network.c
+++ b/bgpd/bgp_network.c
@@ -296,7 +296,7 @@
   req.ai_flags = AI_PASSIVE;
   req.ai_family = AF_UNSPEC;
   req.ai_socktype = SOCK_STREAM;
-  sprintf (port_str, "%d", port);
+  snprintf (port_str, sizeof(port_str), "%d", port);
   port_str[sizeof (port_str) - 1] = '\0';
 
   ret = getaddrinfo (address, port_str, &req, &ainfo);
@@ -380,11 +380,10 @@
   sin.sin_port = htons (port);
   socklen = sizeof (struct sockaddr_in);
 
-  ret = inet_aton(address, &sin.sin_addr);
-
-  if (ret < 1)
+  if (address && ((ret = inet_aton(address, &sin.sin_addr)) < 1))
     {
-      zlog_err("bgp_socket: could not parse ip address %s: ", address, safe_strerror (errno));
+      zlog_err("bgp_socket: could not parse ip address %s: %s",
+                address, safe_strerror (errno));
       return ret;
     }
 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN