summaryrefslogtreecommitdiff
path: root/ident.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2013-01-24 23:21:46 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-01-25 18:41:49 (GMT)
commitdc342a25d1b48cb53448fe0e5dde578edce3122c (patch)
tree0d066af74121e09b9443fc3bbde4292b2f635dde /ident.c
parent7e2010537e96d0a1144520222f20ba1dc3d61441 (diff)
downloadgit-dc342a25d1b48cb53448fe0e5dde578edce3122c.zip
git-dc342a25d1b48cb53448fe0e5dde578edce3122c.tar.gz
git-dc342a25d1b48cb53448fe0e5dde578edce3122c.tar.bz2
ident: do not drop username when reading from /etc/mailname
An earlier conversion from fgets() to strbuf_getline() in the codepath to read from /etc/mailname to learn the default host-part of the ident e-mail address forgot that strbuf_getline() stores the line at the beginning of the buffer just like fgets(). The "username@" the caller has prepared in the strbuf, expecting the function to append the host-part to it, was lost because of this. Reported-by: Mihai Rusu <dizzy@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ident.c')
-rw-r--r--ident.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/ident.c b/ident.c
index 484e0a9..fb4cc72 100644
--- a/ident.c
+++ b/ident.c
@@ -41,6 +41,7 @@ static void copy_gecos(const struct passwd *w, struct strbuf *name)
static int add_mailname_host(struct strbuf *buf)
{
FILE *mailname;
+ struct strbuf mailnamebuf = STRBUF_INIT;
mailname = fopen("/etc/mailname", "r");
if (!mailname) {
@@ -49,14 +50,17 @@ static int add_mailname_host(struct strbuf *buf)
strerror(errno));
return -1;
}
- if (strbuf_getline(buf, mailname, '\n') == EOF) {
+ if (strbuf_getline(&mailnamebuf, mailname, '\n') == EOF) {
if (ferror(mailname))
warning("cannot read /etc/mailname: %s",
strerror(errno));
+ strbuf_release(&mailnamebuf);
fclose(mailname);
return -1;
}
/* success! */
+ strbuf_addbuf(buf, &mailnamebuf);
+ strbuf_release(&mailnamebuf);
fclose(mailname);
return 0;
}