Skip to content

gutils: Avoid segfault in g_get_user_database_entry

g_get_user_database_entry() uses variable pwd to store the contents of the call to getpwnam_r(), then capitalises the first letter of pw_name with g_ascii_toupper (pw->pw_name[0]).

However, as per the getpwnam manpage, the result of that call "may point to a static area". When this happens, GLib is trying to edit static memory which belongs to a shared library, so segfaults.

Instead, copy pw_name off to a temporary variable, set uppercase on that variable, and use the variable to join into the desired string. Free the new variable after it is no longer needed.

Signed-off-by: Jamie Bainbridge jamie.bainbridge@gmail.com

Merge request reports