Merge branch 'fix_pw_name_segfault' into 'main'

gutils: Avoid segfault in g_get_user_database_entry

See merge request GNOME/glib!2244
This commit is contained in:
Michael Catanzaro 2021-09-22 12:46:00 +00:00
commit 969a26378b

View File

@ -692,14 +692,17 @@ g_get_user_database_entry (void)
{ {
gchar **gecos_fields; gchar **gecos_fields;
gchar **name_parts; gchar **name_parts;
gchar *uppercase_pw_name;
/* split the gecos field and substitute '&' */ /* split the gecos field and substitute '&' */
gecos_fields = g_strsplit (pw->pw_gecos, ",", 0); gecos_fields = g_strsplit (pw->pw_gecos, ",", 0);
name_parts = g_strsplit (gecos_fields[0], "&", 0); name_parts = g_strsplit (gecos_fields[0], "&", 0);
pw->pw_name[0] = g_ascii_toupper (pw->pw_name[0]); uppercase_pw_name = g_strdup (pw->pw_name);
e.real_name = g_strjoinv (pw->pw_name, name_parts); uppercase_pw_name[0] = g_ascii_toupper (uppercase_pw_name[0]);
e.real_name = g_strjoinv (uppercase_pw_name, name_parts);
g_strfreev (gecos_fields); g_strfreev (gecos_fields);
g_strfreev (name_parts); g_strfreev (name_parts);
g_free (uppercase_pw_name);
} }
#endif #endif