glocalvfs.c uses non-thread-safe getpwnam()
g_local_vfs_parse_name
contains the following code:
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);
Although its manpage is not explicit on this point, I believe getpwnam
is not safe to use in multi-threaded applications. Its implementation in glibc (template, instantiation) is in terms of a static
buffer. So it is possible that the memory pointed to by passwd_file_entry
will be modified by another thread at any point after the call to getpwnam
in the above code; in fact, the pointer could be freed if another thread's call to getpwnam
needs to allocate a bigger buffer.
As far as I know, g_vfs_*
is meant to be usable in multi-threaded applications, so I think it should use getpwnam_r
. This is one of these annoying functions that you have to call in a loop, growing the buffer each time. Such a loop already exists in glib/gutils.c, albeit convoluted by trying to respect $LOGNAME
.