diff options
author | Robert C. Helling <helling@atdotde.de> | 2019-01-12 10:04:05 +0100 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2019-01-16 02:38:30 +0100 |
commit | 5f04fecd005f6566f9931ba7b692bd6ca109bc87 (patch) | |
tree | 95391fc1b57ab0a59f405f31292ecb9d5d6bd467 /core | |
parent | 2c794348c1060c8f6ce55c598c0a20690c4967f2 (diff) | |
download | subsurface-5f04fecd005f6566f9931ba7b692bd6ca109bc87.tar.gz |
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>
Diffstat (limited to 'core')
-rw-r--r-- | core/save-git.c | 2 | ||||
-rw-r--r-- | core/unix.c | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/core/save-git.c b/core/save-git.c index 33c01ab83..67a9cb55b 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -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"); 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; } |