diff options
author | Paul Jakma <paul.jakma@sun.com> | 2008-01-29 17:26:34 +0000 |
---|---|---|
committer | Paul Jakma <paul.jakma@sun.com> | 2008-01-29 17:26:34 +0000 |
commit | 90b68769a1a1d7623cae02be71b7a8e4094455ad (patch) | |
tree | f114b7a33eec1cde1fefcb3cadf89d68fa73b005 /bgpd/bgp_network.c | |
parent | 75f043990f9e3fe76a59605df8b0c1283a5b2ec6 (diff) |
[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.
Diffstat (limited to 'bgpd/bgp_network.c')
-rw-r--r-- | bgpd/bgp_network.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index 6b8c8a44..8452545d 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -296,7 +296,7 @@ bgp_socket (struct bgp *bgp, unsigned short port, char *address) 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 @@ bgp_socket (struct bgp *bgp, unsigned short port, char *address) 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 |