From bdf2583fbd19a4d95bb29f836ae3dd559bbaaad8 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 19 Feb 2019 14:09:22 +0000 Subject: [PATCH] glocalvfs: Use thread-safe getpwnam_r() rather than getpwnam() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s possible that one VFS operation will happen from a worker thread at the same time as another is happening from the main thread, in which case the static buffer which getpwnam() uses will be overwritten. There’s a chance this will corrupt the results that one of the threads receives. Fix that by using the thread-safe getpwnam_r() version, via the new g_unix_get_passwd_entry() function. Fix the indentation of the surrounding block while we’re there. Signed-off-by: Philip Withnall Fixes: #1687 --- gio/glocalvfs.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/gio/glocalvfs.c b/gio/glocalvfs.c index c29d071b7..f8d85e458 100644 --- a/gio/glocalvfs.c +++ b/gio/glocalvfs.c @@ -27,6 +27,7 @@ #include #include #ifdef G_OS_UNIX +#include "glib-unix.h" #include #endif #include @@ -160,15 +161,17 @@ g_local_vfs_parse_name (GVfs *vfs, struct passwd *passwd_file_entry; char *user_name; - user_name = g_strndup (user_start, user_end - user_start); - passwd_file_entry = getpwnam (user_name); - g_free (user_name); - - if (passwd_file_entry != NULL && - passwd_file_entry->pw_dir != NULL) - user_prefix = g_strdup (passwd_file_entry->pw_dir); - else - user_prefix = g_strdup (g_get_home_dir ()); + user_name = g_strndup (user_start, user_end - user_start); + passwd_file_entry = g_unix_get_passwd_entry (user_name, NULL); + g_free (user_name); + + if (passwd_file_entry != NULL && + passwd_file_entry->pw_dir != NULL) + user_prefix = g_strdup (passwd_file_entry->pw_dir); + else + user_prefix = g_strdup (g_get_home_dir ()); + + g_free (passwd_file_entry); } #else user_prefix = g_strdup (g_get_home_dir ());