Skip to content

Commit

Permalink
fast-import: fix buffer overflow in dump_tags
Browse files Browse the repository at this point in the history
When creating a new annotated tag, we sprintf the refname
into a static-sized buffer. If we have an absurdly long
tagname, like:

  git init repo &&
  cd repo &&
  git commit --allow-empty -m foo &&
  git tag -m message mytag &&
  git fast-export mytag |
  perl -lpe '/^tag/ and s/mytag/"a" x 8192/e' |
  git fast-import <input

we'll overflow the buffer. We can fix it by using a strbuf.

Signed-off-by: Jeff King <peff@peff.net>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Reviewed-by: Ronnie Sahlberg <sahlberg@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Aug 25, 2014
1 parent 3c078b9 commit c252785
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1730,14 +1730,16 @@ static void dump_tags(void)
static const char *msg = "fast-import";
struct tag *t;
struct ref_lock *lock;
char ref_name[PATH_MAX];
struct strbuf ref_name = STRBUF_INIT;

for (t = first_tag; t; t = t->next_tag) {
sprintf(ref_name, "tags/%s", t->name);
lock = lock_ref_sha1(ref_name, NULL);
strbuf_reset(&ref_name);
strbuf_addf(&ref_name, "tags/%s", t->name);
lock = lock_ref_sha1(ref_name.buf, NULL);
if (!lock || write_ref_sha1(lock, t->sha1, msg) < 0)
failure |= error("Unable to update %s", ref_name);
failure |= error("Unable to update %s", ref_name.buf);
}
strbuf_release(&ref_name);
}

static void dump_marks_helper(FILE *f,
Expand Down

0 comments on commit c252785

Please sign in to comment.