96c14e
From 103cf5a3f83406f4a22b8d1899518e5fa4a351d8 Mon Sep 17 00:00:00 2001
96c14e
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
96c14e
Date: Tue, 15 Feb 2022 11:46:06 +0400
96c14e
Subject: [PATCH] Replace deprecated inet_ntoa with safer inet_ntop
96c14e
MIME-Version: 1.0
96c14e
Content-Type: text/plain; charset=UTF-8
96c14e
Content-Transfer-Encoding: 8bit
96c14e
96c14e
inet_ntoa() is a legacy API with MT issues. Use the recommended
96c14e
alternative instead. This makes some code checkers happy, and could
96c14e
potentially fix issues if other parts of the process were to use
96c14e
inet_ntoa() at the same time..
96c14e
96c14e
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
96c14e
---
96c14e
 main.c | 20 ++++++++++----------
96c14e
 1 file changed, 10 insertions(+), 10 deletions(-)
96c14e
96c14e
diff --git a/main.c b/main.c
96c14e
index c79508e10f4d..2c38dc0da1af 100644
96c14e
--- a/main.c
96c14e
+++ b/main.c
96c14e
@@ -257,6 +257,7 @@ static int recvfd(int sock)
96c14e
 static int parent(int sock, int ready_fd, int exit_fd, const char *api_socket,
96c14e
                   struct slirp4netns_config *cfg, pid_t target_pid)
96c14e
 {
96c14e
+    char str[INET6_ADDRSTRLEN];
96c14e
     int rc, tapfd;
96c14e
     if ((tapfd = recvfd(sock)) < 0) {
96c14e
         return tapfd;
96c14e
@@ -265,23 +266,22 @@ static int parent(int sock, int ready_fd, int exit_fd, const char *api_socket,
96c14e
     close(sock);
96c14e
     printf("Starting slirp\n");
96c14e
     printf("* MTU:             %d\n", cfg->mtu);
96c14e
-    printf("* Network:         %s\n", inet_ntoa(cfg->vnetwork));
96c14e
-    printf("* Netmask:         %s\n", inet_ntoa(cfg->vnetmask));
96c14e
-    printf("* Gateway:         %s\n", inet_ntoa(cfg->vhost));
96c14e
-    printf("* DNS:             %s\n", inet_ntoa(cfg->vnameserver));
96c14e
-    printf("* Recommended IP:  %s\n", inet_ntoa(cfg->recommended_vguest));
96c14e
+    printf("* Network:         %s\n", inet_ntop(AF_INET, &cfg->vnetwork, str, sizeof(str)));
96c14e
+    printf("* Netmask:         %s\n", inet_ntop(AF_INET, &cfg->vnetmask, str, sizeof(str)));
96c14e
+    printf("* Gateway:         %s\n", inet_ntop(AF_INET, &cfg->vhost, str, sizeof(str)));
96c14e
+    printf("* DNS:             %s\n", inet_ntop(AF_INET, &cfg->vnameserver, str, sizeof(str)));
96c14e
+    printf("* Recommended IP:  %s\n", inet_ntop(AF_INET, &cfg->recommended_vguest, str, sizeof(str)));
96c14e
     if (api_socket != NULL) {
96c14e
         printf("* API Socket:      %s\n", api_socket);
96c14e
     }
96c14e
 #if SLIRP_CONFIG_VERSION_MAX >= 2
96c14e
     if (cfg->enable_outbound_addr) {
96c14e
         printf("* Outbound IPv4:    %s\n",
96c14e
-               inet_ntoa(cfg->outbound_addr.sin_addr));
96c14e
+               inet_ntop(AF_INET, &cfg->outbound_addr.sin_addr, str, sizeof(str)));
96c14e
     }
96c14e
     if (cfg->enable_outbound_addr6) {
96c14e
-        char str[INET6_ADDRSTRLEN];
96c14e
-        if (inet_ntop(AF_INET6, &cfg->outbound_addr6.sin6_addr, str,
96c14e
-                      INET6_ADDRSTRLEN) != NULL) {
96c14e
+        if (inet_ntop(AF_INET6, &cfg->outbound_addr6.sin6_addr,
96c14e
+                      str, sizeof(str)) != NULL) {
96c14e
             printf("* Outbound IPv6:    %s\n", str);
96c14e
         }
96c14e
     }
96c14e
@@ -290,7 +290,7 @@ static int parent(int sock, int ready_fd, int exit_fd, const char *api_socket,
96c14e
         printf(
96c14e
             "WARNING: 127.0.0.1:* on the host is accessible as %s (set "
96c14e
             "--disable-host-loopback to prohibit connecting to 127.0.0.1:*)\n",
96c14e
-            inet_ntoa(cfg->vhost));
96c14e
+            inet_ntop(AF_INET, &cfg->vhost, str, sizeof(str)));
96c14e
     }
96c14e
     if (cfg->enable_sandbox && geteuid() != 0) {
96c14e
         if ((rc = nsenter(target_pid, NULL, NULL, true)) < 0) {
96c14e
-- 
96c14e
2.34.1.428.gdcc0cd074f0c
96c14e