From b5a6f7a23a368ffb31fbf48cdffe95541166d3fa Mon Sep 17 00:00:00 2001 From: Isaac Jurado Date: Sat, 8 Nov 2014 18:06:45 +0100 Subject: [PATCH] Properly catch and report getaddrinfo() errors The getaddrinfo() function does not behave like a system call. In particular, the only successful return value is zero; any other value should be considered a failure, not only -1. This commit fixes a segfault caused by an invalid value of the "-l" command line option. Closes #254 and fixes #253. --- net.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net.c b/net.c index 6ccae17..cfa42db 100644 --- a/net.c +++ b/net.c @@ -48,8 +48,10 @@ make_server_socket(char *host, char *port) hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; r = getaddrinfo(host, port, &hints, &airoot); - if (r == -1) - return twarn("getaddrinfo()"), -1; + if (r != 0) { + twarnx("getaddrinfo(): %s", gai_strerror(r)); + return -1; + } for(ai = airoot; ai; ai = ai->ai_next) { fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); -- 2.11.4.GIT