From: Timo Sirainen Date: Tue, 6 Aug 2013 11:53:23 +0000 (+0300) Subject: net_ip2addr() changed to return "" instead of NULL on failure. X-Git-Tag: 2.2.6~158 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=91a58087aa77d102ede3960fe99f78afe42d09eb;p=thirdparty%2Fdovecot%2Fcore.git net_ip2addr() changed to return "" instead of NULL on failure. Pretty much everything in the code assumed that it would never fail, which it normally doesn't except if the ip_addr was created for UNIX sockets. --- diff --git a/src/auth/auth-request.c b/src/auth/auth-request.c index 8cbe7a2ad0..9ce62fc3ad 100644 --- a/src/auth/auth-request.c +++ b/src/auth/auth-request.c @@ -2021,7 +2021,7 @@ static void get_log_prefix(string_t *str, struct auth_request *auth_request, } ip = net_ip2addr(&auth_request->remote_ip); - if (ip != NULL) { + if (ip[0] != '\0') { str_append_c(str, ','); str_append(str, ip); } diff --git a/src/auth/passdb-pam.c b/src/auth/passdb-pam.c index 0b0ff1c0b4..0c15bf86fc 100644 --- a/src/auth/passdb-pam.c +++ b/src/auth/passdb-pam.c @@ -238,7 +238,7 @@ static void set_pam_items(struct auth_request *request, pam_handle_t *pamh) /* These shouldn't fail, and we don't really care if they do. */ host = net_ip2addr(&request->remote_ip); - if (host != NULL) + if (host[0] != '\0') (void)pam_set_item(pamh, PAM_RHOST, host); (void)pam_set_item(pamh, PAM_RUSER, request->user); /* TTY is needed by eg. pam_access module */ diff --git a/src/auth/passdb-vpopmail.c b/src/auth/passdb-vpopmail.c index 37b3ff5ac7..1124132e7b 100644 --- a/src/auth/passdb-vpopmail.c +++ b/src/auth/passdb-vpopmail.c @@ -153,7 +153,7 @@ vpopmail_verify_plain(struct auth_request *request, const char *password, strcasecmp(request->service, "IMAP") == 0) { const char *host = net_ip2addr(&request->remote_ip); /* vpopmail 5.4 does not understand IPv6 */ - if (host != NULL && IPADDR_IS_V4(&request->remote_ip)) { + if (host[0] != '\0' && IPADDR_IS_V4(&request->remote_ip)) { /* use putenv() directly rather than env_put() which would leak memory every time we got here. use a static buffer for putenv() as SUSv2 requirements diff --git a/src/lib/net.c b/src/lib/net.c index e3623b16ea..b2e9a09c9a 100644 --- a/src/lib/net.c +++ b/src/lib/net.c @@ -870,14 +870,14 @@ const char *net_ip2addr(const struct ip_addr *ip) addr[MAX_IP_LEN] = '\0'; if (inet_ntop(ip->family, &ip->u.ip6, addr, MAX_IP_LEN) == NULL) - return NULL; + return ""; return t_strdup(addr); #else unsigned long ip4; if (ip->family != AF_INET) - return NULL; + return ""; ip4 = ntohl(ip->u.ip4.s_addr); return t_strdup_printf("%lu.%lu.%lu.%lu", diff --git a/src/lib/net.h b/src/lib/net.h index 276285db8b..2b21bde8fa 100644 --- a/src/lib/net.h +++ b/src/lib/net.h @@ -133,7 +133,7 @@ int net_getunixname(int fd, const char **name_r); unavailable. */ int net_getunixcred(int fd, struct net_unix_cred *cred_r); -/* Returns ip_addr as string, or NULL if ip is invalid. */ +/* Returns ip_addr as string, or "" if ip isn't valid IPv4 or IPv6 address. */ const char *net_ip2addr(const struct ip_addr *ip); /* char* -> struct ip_addr translation. */ int net_addr2ip(const char *addr, struct ip_addr *ip); diff --git a/src/lib/uri-util.c b/src/lib/uri-util.c index b0fd3ecf07..7b224c2ac4 100644 --- a/src/lib/uri-util.c +++ b/src/lib/uri-util.c @@ -799,8 +799,6 @@ void uri_append_host_ip(string_t *out, const struct ip_addr *host_ip) { const char *addr = net_ip2addr(host_ip); - i_assert(addr != NULL); - if (host_ip->family == AF_INET) { str_append(out, addr); return; diff --git a/src/lmtp/client.c b/src/lmtp/client.c index 67c3685339..3b63758d7d 100644 --- a/src/lmtp/client.c +++ b/src/lmtp/client.c @@ -195,7 +195,7 @@ const char *client_remote_id(struct client *client) const char *addr; addr = net_ip2addr(&client->remote_ip); - if (addr == NULL) + if (addr[0] == '\0') addr = "local"; return addr; } diff --git a/src/login-common/main.c b/src/login-common/main.c index 9711b5fcb9..0ab48cbcd4 100644 --- a/src/login-common/main.c +++ b/src/login-common/main.c @@ -64,11 +64,14 @@ void login_refresh_proctitle(void) } else if (clients_get_count() > 1 || client == NULL) { process_title_set(t_strdup_printf("[%u connections (%u TLS)]", clients_get_count(), ssl_proxy_get_count())); - } else if ((addr = net_ip2addr(&client->ip)) != NULL) { - process_title_set(t_strdup_printf(client->tls ? - "[%s TLS]" : "[%s]", addr)); } else { - process_title_set(client->tls ? "[TLS]" : ""); + addr = net_ip2addr(&client->ip); + if (addr[0] != '\0') { + process_title_set(t_strdup_printf(client->tls ? + "[%s TLS]" : "[%s]", addr)); + } else { + process_title_set(client->tls ? "[TLS]" : ""); + } } }