[glib: 2/3] glocalvfs: Use thread-safe getpwnam_r() rather than getpwnam()
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 2/3] glocalvfs: Use thread-safe getpwnam_r() rather than getpwnam()
- Date: Wed, 27 Nov 2019 11:59:25 +0000 (UTC)
commit bdf2583fbd19a4d95bb29f836ae3dd559bbaaad8
Author: Philip Withnall <withnall endlessm com>
Date: Tue Feb 19 14:09:22 2019 +0000
glocalvfs: Use thread-safe getpwnam_r() rather than getpwnam()
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 <withnall endlessm com>
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 <gio/gdummyfile.h>
#include <sys/types.h>
#ifdef G_OS_UNIX
+#include "glib-unix.h"
#include <pwd.h>
#endif
#include <string.h>
@@ -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 ());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]