Fixes SVACE issue with thread-unsafe calls to strerror 09/204009/3 accepted/tizen/unified/20190425.014541 submit/tizen/20190424.060632 submit/tizen/20190424.080239
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Thu, 18 Apr 2019 10:26:46 +0000 (12:26 +0200)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Fri, 19 Apr 2019 07:37:27 +0000 (09:37 +0200)
Calls to strerror were replaced with calls to strerror_r, which
is thread-safe.

Change-Id: I6ee4908672118248b96590f375005ee424daea85

bus/at-spi-bus-launcher.c

index e42a26d..65bb0b1 100644 (file)
@@ -349,7 +349,11 @@ ensure_a11y_bus_daemon (A11yBusLauncher *app, char *config_path)
   argv[1] = (char*)config_path;
 
   if (pipe (app->pipefd) < 0)
-    g_error ("Failed to create pipe: %s", strerror (errno));
+    {
+      char buf[4096] = { 0 };
+      strerror_r (errno, buf, sizeof(buf));
+      g_error ("Failed to create pipe: %s", buf);
+    }
 
   g_clear_pointer (&app->a11y_launch_error_message, g_free);
 
@@ -378,7 +382,9 @@ ensure_a11y_bus_daemon (A11yBusLauncher *app, char *config_path)
   LOGD("Launched a11y bus, child is %ld", (long) pid);
   if (!unix_read_all_fd_to_string (app->pipefd[0], addr_buf, sizeof (addr_buf)))
     {
-      app->a11y_launch_error_message = g_strdup_printf ("Failed to read address: %s", strerror (errno));
+      char buf[4096] = { 0 };
+      strerror_r (errno, buf, sizeof(buf));
+      app->a11y_launch_error_message = g_strdup_printf ("Failed to read address: %s", buf);
       kill (app->a11y_bus_pid, SIGTERM);
       goto error;
     }
@@ -437,16 +443,32 @@ ensure_a11y_bus_broker (A11yBusLauncher *app, char *config_path)
   GError *error = NULL;
 
   if ((app->listenfd = socket (PF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0)) < 0)
-    g_error ("Failed to create listening socket: %s", strerror (errno));
+    {
+      char buf[4096] = { 0 };
+      strerror_r (errno, buf, sizeof(buf));
+      g_error ("Failed to create listening socket: %s", buf);
+    }
 
   if (bind (app->listenfd, (struct sockaddr *)&addr, sizeof(sa_family_t)) < 0)
-    g_error ("Failed to bind listening socket: %s", strerror (errno));
+    {
+      char buf[4096] = { 0 };
+      strerror_r (errno, buf, sizeof(buf));
+      g_error ("Failed to bind listening socket: %s", buf);
+    }
 
   if (getsockname (app->listenfd, (struct sockaddr *)&addr, &addr_len) < 0)
-    g_error ("Failed to get socket name for listening socket: %s", strerror(errno));
+    {
+      char buf[4096] = { 0 };
+      strerror_r (errno, buf, sizeof(buf));
+      g_error ("Failed to get socket name for listening socket: %s", buf);
+    }
 
   if (listen (app->listenfd, 1024) < 0)
-    g_error ("Failed to listen on socket: %s", strerror(errno));
+    {
+      char buf[4096] = { 0 };
+      strerror_r (errno, buf, sizeof(buf));
+      g_error ("Failed to listen on socket: %s", buf);
+    }
 
   g_clear_pointer (&app->a11y_launch_error_message, g_free);
 
@@ -870,7 +892,11 @@ init_sigterm_handling (A11yBusLauncher *app)
   GIOChannel *sigterm_channel;
 
   if (pipe (sigterm_pipefd) < 0)
-    g_error ("Failed to create pipe: %s", strerror (errno));
+    {
+      char buf[4096] = { 0 };
+      strerror_r (errno, buf, sizeof(buf));
+      g_error ("Failed to create pipe: %s", buf);
+    }
   signal (SIGTERM, sigterm_handler);
 
   sigterm_channel = g_io_channel_unix_new (sigterm_pipefd[0]);