From: Junio C Hamano Date: Mon, 3 Oct 2016 20:22:32 +0000 (-0700) Subject: Merge branch 'jk/ident-ai-canonname-could-be-null' into maint X-Git-Tag: v2.10.1~1 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/11738ddf4885c5bd02bdd3587c8765df70c3270e?ds=inline;hp=-c Merge branch 'jk/ident-ai-canonname-could-be-null' into maint In the codepath that comes up with the hostname to be used in an e-mail when the user didn't tell us, we looked at ai_canonname field in struct addrinfo without making sure it is not NULL first. * jk/ident-ai-canonname-could-be-null: ident: handle NULL ai_canonname --- 11738ddf4885c5bd02bdd3587c8765df70c3270e diff --combined ident.c index e20a772dde,28bc854918..d17b5bd341 --- a/ident.c +++ b/ident.c @@@ -75,12 -75,14 +75,12 @@@ static int add_mailname_host(struct str mailname = fopen("/etc/mailname", "r"); if (!mailname) { if (errno != ENOENT) - warning("cannot open /etc/mailname: %s", - strerror(errno)); + warning_errno("cannot open /etc/mailname"); return -1; } if (strbuf_getline(&mailnamebuf, mailname) == EOF) { if (ferror(mailname)) - warning("cannot read /etc/mailname: %s", - strerror(errno)); + warning_errno("cannot read /etc/mailname"); strbuf_release(&mailnamebuf); fclose(mailname); return -1; @@@ -101,7 -103,7 +101,7 @@@ static int canonical_name(const char *h memset (&hints, '\0', sizeof (hints)); hints.ai_flags = AI_CANONNAME; if (!getaddrinfo(host, NULL, &hints, &ai)) { - if (ai && strchr(ai->ai_canonname, '.')) { + if (ai && ai->ai_canonname && strchr(ai->ai_canonname, '.')) { strbuf_addstr(out, ai->ai_canonname); status = 0; } @@@ -123,7 -125,7 +123,7 @@@ static void add_domainname(struct strbu char buf[1024]; if (gethostname(buf, sizeof(buf))) { - warning("cannot get host name: %s", strerror(errno)); + warning_errno("cannot get host name"); strbuf_addstr(out, "(none)"); *is_bogus = 1; return; @@@ -184,11 -186,6 +184,11 @@@ static const char *ident_default_date(v return git_default_date.buf; } +void reset_ident_date(void) +{ + strbuf_reset(&git_default_date); +} + static int crud(unsigned char c) { return c <= 32 ||