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>
Jonathan Nieder committed
Jan 24, 2013 at 15:21 UTC
dc342a25d1b48cb53448fe0e5dde578edce3122c
1 file changed
+5
-1
ident.c
+5
-1
@@ -41,6 +41,7 @@ static void copy_gecos(const struct passwd *w, struct strbuf *name)
41
static int add_mailname_host(struct strbuf *buf)
42
{
43
FILE *mailname;
44
+ struct strbuf mailnamebuf = STRBUF_INIT;
45
46
mailname = fopen("/etc/mailname", "r");
47
if (!mailname) {
@@ -49,14 +50,17 @@ static int add_mailname_host(struct strbuf *buf)
50
strerror(errno));
51
return -1;
52
}
52
- if (strbuf_getline(buf, mailname, '\n') == EOF) {
53
+ if (strbuf_getline(&mailnamebuf, mailname, '\n') == EOF) {
54
if (ferror(mailname))
55
warning("cannot read /etc/mailname: %s",
56
strerror(errno));
57
+ strbuf_release(&mailnamebuf);
58
fclose(mailname);
59
return -1;
60
}
61
/* success! */
62
+ strbuf_addbuf(buf, &mailnamebuf);
63
+ strbuf_release(&mailnamebuf);
64
fclose(mailname);
65
return 0;
66
}