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