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