Blame SOURCES/vsftpd-3.0.5-repalce-old-network-addr-functions.patch

9b0ebb
diff -urN vsftpd-3.0.5-orig/postlogin.c vsftpd-3.0.5/postlogin.c
9b0ebb
--- vsftpd-3.0.5-orig/postlogin.c	2015-07-22 21:03:22.000000000 +0200
9b0ebb
+++ vsftpd-3.0.5/postlogin.c	2023-02-13 16:34:05.244467476 +0100
9b0ebb
@@ -27,4 +27,6 @@
9b0ebb
 #include "ssl.h"
9b0ebb
 #include "vsftpver.h"
9b0ebb
+#include <netdb.h>
9b0ebb
+#include <arpa/inet.h>
9b0ebb
 #include "opts.h"
9b0ebb
9b0ebb
@@ -628,9 +629,10 @@
9b0ebb
   else
9b0ebb
   {
9b0ebb
     const void* p_v4addr = vsf_sysutil_sockaddr_ipv6_v4(s_p_sockaddr);
9b0ebb
+    static char result[INET_ADDRSTRLEN];
9b0ebb
     if (p_v4addr)
9b0ebb
     {
9b0ebb
-      str_append_text(&s_pasv_res_str, vsf_sysutil_inet_ntoa(p_v4addr));
9b0ebb
+      str_append_text(&s_pasv_res_str, inet_ntop(AF_INET, p_v4addr, result, INET_ADDRSTRLEN));
9b0ebb
     }
9b0ebb
     else
9b0ebb
     {
9b0ebb
diff -urN vsftpd-3.0.5-orig/sysutil.c vsftpd-3.0.5/sysutil.c
9b0ebb
--- vsftpd-3.0.5-orig/sysutil.c	2012-09-16 09:07:38.000000000 +0200
9b0ebb
+++ vsftpd-3.0.5/sysutil.c	2023-02-13 16:08:58.557153109 +0100
9b0ebb
@@ -2205,20 +2205,13 @@
9b0ebb
   const struct sockaddr* p_sockaddr = &p_sockptr->u.u_sockaddr;
9b0ebb
   if (p_sockaddr->sa_family == AF_INET)
9b0ebb
   {
9b0ebb
-    return inet_ntoa(p_sockptr->u.u_sockaddr_in.sin_addr);
9b0ebb
+    static char result[INET_ADDRSTRLEN];
9b0ebb
+    return inet_ntop(AF_INET, &p_sockptr->u.u_sockaddr_in.sin_addr, result, INET_ADDRSTRLEN);
9b0ebb
   }
9b0ebb
   else if (p_sockaddr->sa_family == AF_INET6)
9b0ebb
   {
9b0ebb
-    static char inaddr_buf[64];
9b0ebb
-    const char* p_ret = inet_ntop(AF_INET6,
9b0ebb
-                                  &p_sockptr->u.u_sockaddr_in6.sin6_addr,
9b0ebb
-                                  inaddr_buf, sizeof(inaddr_buf));
9b0ebb
-    inaddr_buf[sizeof(inaddr_buf) - 1] = '\0';
9b0ebb
-    if (p_ret == NULL)
9b0ebb
-    {
9b0ebb
-      inaddr_buf[0] = '\0';
9b0ebb
-    }
9b0ebb
-    return inaddr_buf;
9b0ebb
+    static char result[INET6_ADDRSTRLEN];
9b0ebb
+    return inet_ntop(AF_INET6, &p_sockptr->u.u_sockaddr_in6.sin6_addr, result, INET6_ADDRSTRLEN);
9b0ebb
   }
9b0ebb
   else
9b0ebb
   {
9b0ebb
@@ -2227,12 +2220,6 @@
9b0ebb
   }
9b0ebb
 }
9b0ebb
 
9b0ebb
-const char*
9b0ebb
-vsf_sysutil_inet_ntoa(const void* p_raw_addr)
9b0ebb
-{
9b0ebb
-  return inet_ntoa(*((struct in_addr*)p_raw_addr));
9b0ebb
-}
9b0ebb
-
9b0ebb
 int
9b0ebb
 vsf_sysutil_inet_aton(const char* p_text, struct vsf_sysutil_sockaddr* p_addr)
9b0ebb
 {
9b0ebb
@@ -2241,7 +2228,7 @@
9b0ebb
   {
9b0ebb
     bug("bad family");
9b0ebb
   }
9b0ebb
-  if (inet_aton(p_text, &sin_addr))
9b0ebb
+  if (inet_pton(AF_INET, p_text, &sin_addr))
9b0ebb
   {
9b0ebb
     vsf_sysutil_memcpy(&p_addr->u.u_sockaddr_in.sin_addr,
9b0ebb
                        &sin_addr, sizeof(p_addr->u.u_sockaddr_in.sin_addr));
9b0ebb
@@ -2257,37 +2244,46 @@
9b0ebb
 vsf_sysutil_dns_resolve(struct vsf_sysutil_sockaddr** p_sockptr,
9b0ebb
                         const char* p_name)
9b0ebb
 {
9b0ebb
-  struct hostent* hent = gethostbyname(p_name);
9b0ebb
-  if (hent == NULL)
9b0ebb
+  struct addrinfo *result;
9b0ebb
+  struct addrinfo hints;
9b0ebb
+  int ret;
9b0ebb
+
9b0ebb
+  memset(&hints, 0, sizeof(struct addrinfo));
9b0ebb
+  hints.ai_family = AF_UNSPEC;
9b0ebb
+
9b0ebb
+  if ((ret = getaddrinfo(p_name, NULL, &hints, &result)) != 0)
9b0ebb
   {
9b0ebb
+    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(ret));
9b0ebb
     die2("cannot resolve host:", p_name);
9b0ebb
   }
9b0ebb
   vsf_sysutil_sockaddr_clear(p_sockptr);
9b0ebb
-  if (hent->h_addrtype == AF_INET)
9b0ebb
+  if (result->ai_family == AF_INET)
9b0ebb
   {
9b0ebb
-    unsigned int len = hent->h_length;
9b0ebb
+    unsigned int len = result->ai_addrlen;
9b0ebb
     if (len > sizeof((*p_sockptr)->u.u_sockaddr_in.sin_addr))
9b0ebb
     {
9b0ebb
       len = sizeof((*p_sockptr)->u.u_sockaddr_in.sin_addr);
9b0ebb
     }
9b0ebb
     vsf_sysutil_sockaddr_alloc_ipv4(p_sockptr);
9b0ebb
     vsf_sysutil_memcpy(&(*p_sockptr)->u.u_sockaddr_in.sin_addr,
9b0ebb
-                       hent->h_addr_list[0], len);
9b0ebb
+                       &result->ai_addrlen, len);
9b0ebb
   }
9b0ebb
-  else if (hent->h_addrtype == AF_INET6)
9b0ebb
+  else if (result->ai_family == AF_INET6)
9b0ebb
   {
9b0ebb
-    unsigned int len = hent->h_length;
9b0ebb
+    unsigned int len = result->ai_addrlen;
9b0ebb
     if (len > sizeof((*p_sockptr)->u.u_sockaddr_in6.sin6_addr))
9b0ebb
     {
9b0ebb
       len = sizeof((*p_sockptr)->u.u_sockaddr_in6.sin6_addr);
9b0ebb
     }
9b0ebb
     vsf_sysutil_sockaddr_alloc_ipv6(p_sockptr);
9b0ebb
     vsf_sysutil_memcpy(&(*p_sockptr)->u.u_sockaddr_in6.sin6_addr,
9b0ebb
-                       hent->h_addr_list[0], len);
9b0ebb
+                       &result->ai_addrlen, len);
9b0ebb
   }
9b0ebb
   else
9b0ebb
   {
9b0ebb
-    die("gethostbyname(): neither IPv4 nor IPv6");
9b0ebb
+    freeaddrinfo(result);
9b0ebb
+    die("getaddrinfo(): neither IPv4 nor IPv6");
9b0ebb
   }
9b0ebb
+  freeaddrinfo(result);
9b0ebb
 }
9b0ebb
 
9b0ebb
diff -urN vsftpd-3.0.5-orig/sysutil.h vsftpd-3.0.5/sysutil.h
9b0ebb
--- vsftpd-3.0.5-orig/sysutil.h	2021-05-18 08:50:21.000000000 +0200
9b0ebb
+++ vsftpd-3.0.5/sysutil.h	2023-02-13 15:59:22.088331075 +0100
9b0ebb
@@ -277,7 +277,6 @@
9b0ebb
 
9b0ebb
 const char* vsf_sysutil_inet_ntop(
9b0ebb
   const struct vsf_sysutil_sockaddr* p_sockptr);
9b0ebb
-const char* vsf_sysutil_inet_ntoa(const void* p_raw_addr);
9b0ebb
 int vsf_sysutil_inet_aton(
9b0ebb
   const char* p_text, struct vsf_sysutil_sockaddr* p_addr);
9b0ebb