From fc66c767fbf552743c13ecec4141a4c153490cd5 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Sat, 12 Jan 2019 10:04:05 +0100 Subject: Don't allow empty username for git When no real name is set in /etc/passwd the username ends up being ",,,". Git does not like that. Actually, only the part before the first comma is the name, the rest is office and phone number. We don't want those. Before we only testing for the username being a NULL pointer. Reported-by: Keith Grimes Signed-off-by: Robert C. Helling --- core/unix.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'core/unix.c') diff --git a/core/unix.c b/core/unix.c index 1d92a1ad3..5b1cc3720 100644 --- a/core/unix.c +++ b/core/unix.c @@ -38,8 +38,18 @@ void subsurface_user_info(struct user_info *user) const char *username = getenv("USER"); if (pwd) { - if (!empty_string(pwd->pw_gecos)) + if (!empty_string(pwd->pw_gecos)) { user->name = strdup(pwd->pw_gecos); + // We only want the name, not the office or phone number + char *c = user->name; + while (*c) { + if (*c == ',') { + *c = '\0'; + break; + } + ++c; + } + } if (!username) username = pwd->pw_name; } -- cgit v1.2.3-70-g09d2