Merge branch 'jk/format-person-part-buffer-limit'
authorJunio C Hamano <gitster@pobox.com>
Fri, 25 May 2012 19:06:16 +0000 (12:06 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 25 May 2012 19:06:16 +0000 (12:06 -0700)
Avoid buffer overflow in format_person_part() function

1  2 
pretty.c
diff --combined pretty.c
index dc57e5b3296b0e580d6db62c3556f0ff3d52307f,2c1417fe56118b406e1278440beff97df2ed227f..8b1ea9ffad2a0b5c5cb5c15cc5057a8a7132da07
+++ b/pretty.c
@@@ -439,14 -439,12 +439,14 @@@ static char *get_header(const struct co
        int key_len = strlen(key);
        const char *line = commit->buffer;
  
 -      for (;;) {
 +      while (line) {
                const char *eol = strchr(line, '\n'), *next;
  
                if (line == eol)
                        return NULL;
                if (!eol) {
 +                      warning("malformed commit (header is missing newline): %s",
 +                              sha1_to_hex(commit->object.sha1));
                        eol = line + strlen(line);
                        next = NULL;
                } else
                }
                line = next;
        }
 +      return NULL;
  }
  
  static char *replace_encoding_header(char *buf, const char *encoding)
@@@ -550,8 -547,10 +550,10 @@@ static size_t format_person_part(struc
        mail_end = s.mail_end;
  
        if (part == 'N' || part == 'E') { /* mailmap lookup */
-               strlcpy(person_name, name_start, name_end - name_start + 1);
-               strlcpy(person_mail, mail_start, mail_end - mail_start + 1);
+               snprintf(person_name, sizeof(person_name), "%.*s",
+                        (int)(name_end - name_start), name_start);
+               snprintf(person_mail, sizeof(person_mail), "%.*s",
+                        (int)(mail_end - mail_start), mail_start);
                mailmap_name(person_mail, sizeof(person_mail), person_name, sizeof(person_name));
                name_start = person_name;
                name_end = name_start + strlen(person_name);
@@@ -1013,7 -1012,6 +1015,7 @@@ static size_t format_commit_one(struct 
                                get_reflog_selector(sb,
                                                    c->pretty_ctx->reflog_info,
                                                    c->pretty_ctx->date_mode,
 +                                                  c->pretty_ctx->date_mode_explicit,
                                                    (placeholder[1] == 'd'));
                        return 2;
                case 's':       /* reflog message */