mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 14:36:13 +01:00
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
This commit is contained in:
parent
94a800fb9d
commit
bdf2583fbd
@ -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 ());
|
||||
|
Loading…
Reference in New Issue
Block a user