Merge branch 'jk/ident-ai-canonname-could-be-null'
authorJunio C Hamano <gitster@pobox.com>
Thu, 29 Sep 2016 23:57:14 +0000 (16:57 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 29 Sep 2016 23:57:14 +0000 (16:57 -0700)
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

1  2 
ident.c
diff --combined ident.c
index 92c3cca510ab8bfb718e5a3cb07e5871d38ce055,28bc85491872704162c33fa7ac09460bc5b35a11..ac4ae02b485637002869b3fc7a78033d7a5b6aec
+++ 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  ||
@@@ -331,17 -328,17 +331,17 @@@ person_only
  }
  
  static const char *env_hint =
 -"\n"
 -"*** Please tell me who you are.\n"
 -"\n"
 -"Run\n"
 -"\n"
 -"  git config --global user.email \"you@example.com\"\n"
 -"  git config --global user.name \"Your Name\"\n"
 -"\n"
 -"to set your account\'s default identity.\n"
 -"Omit --global to set the identity only in this repository.\n"
 -"\n";
 +N_("\n"
 +   "*** Please tell me who you are.\n"
 +   "\n"
 +   "Run\n"
 +   "\n"
 +   "  git config --global user.email \"you@example.com\"\n"
 +   "  git config --global user.name \"Your Name\"\n"
 +   "\n"
 +   "to set your account\'s default identity.\n"
 +   "Omit --global to set the identity only in this repository.\n"
 +   "\n");
  
  const char *fmt_ident(const char *name, const char *email,
                      const char *date_str, int flag)
                if (!name) {
                        if (strict && ident_use_config_only
                            && !(ident_config_given & IDENT_NAME_GIVEN)) {
 -                              fputs(env_hint, stderr);
 +                              fputs(_(env_hint), stderr);
                                die("no name was given and auto-detection is disabled");
                        }
                        name = ident_default_name();
                        using_default = 1;
                        if (strict && default_name_is_bogus) {
 -                              fputs(env_hint, stderr);
 +                              fputs(_(env_hint), stderr);
                                die("unable to auto-detect name (got '%s')", name);
                        }
                }
                        struct passwd *pw;
                        if (strict) {
                                if (using_default)
 -                                      fputs(env_hint, stderr);
 +                                      fputs(_(env_hint), stderr);
                                die("empty ident name (for <%s>) not allowed", email);
                        }
                        pw = xgetpwuid_self(NULL);
        if (!email) {
                if (strict && ident_use_config_only
                    && !(ident_config_given & IDENT_MAIL_GIVEN)) {
 -                      fputs(env_hint, stderr);
 +                      fputs(_(env_hint), stderr);
                        die("no email was given and auto-detection is disabled");
                }
                email = ident_default_email();
                if (strict && default_email_is_bogus) {
 -                      fputs(env_hint, stderr);
 +                      fputs(_(env_hint), stderr);
                        die("unable to auto-detect email address (got '%s')", email);
                }
        }