mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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 <helling@atdotde.de>
This commit is contained in:
parent
2c794348c1
commit
5f04fecd00
2 changed files with 12 additions and 2 deletions
|
@ -1034,7 +1034,7 @@ static int get_authorship(git_repository *repo, git_signature **authorp)
|
|||
/* try to fetch the user info from the OS, otherwise use default values. */
|
||||
struct user_info user = { .name = NULL, .email = NULL };
|
||||
subsurface_user_info(&user);
|
||||
if (!user.name)
|
||||
if (!user.name || !*user.name)
|
||||
user.name = strdup("Subsurface");
|
||||
if (!user.email)
|
||||
user.email = strdup("subsurface-app-account@subsurface-divelog.org");
|
||||
|
|
12
core/unix.c
12
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue