Skip to content

Commit dc342a2

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7e20105 commit dc342a2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ident.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static void copy_gecos(const struct passwd *w, struct strbuf *name)
4141
static int add_mailname_host(struct strbuf *buf)
4242
{
4343
FILE *mailname;
44+
struct strbuf mailnamebuf = STRBUF_INIT;
4445

4546
mailname = fopen("/etc/mailname", "r");
4647
if (!mailname) {
@@ -49,14 +50,17 @@ static int add_mailname_host(struct strbuf *buf)
4950
strerror(errno));
5051
return -1;
5152
}
52-
if (strbuf_getline(buf, mailname, '\n') == EOF) {
53+
if (strbuf_getline(&mailnamebuf, mailname, '\n') == EOF) {
5354
if (ferror(mailname))
5455
warning("cannot read /etc/mailname: %s",
5556
strerror(errno));
57+
strbuf_release(&mailnamebuf);
5658
fclose(mailname);
5759
return -1;
5860
}
5961
/* success! */
62+
strbuf_addbuf(buf, &mailnamebuf);
63+
strbuf_release(&mailnamebuf);
6064
fclose(mailname);
6165
return 0;
6266
}

0 commit comments

Comments
 (0)