Skip to content

Commit c252785

Browse files
peffgitster
authored andcommitted
fast-import: fix buffer overflow in dump_tags
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 <[email protected]> Reviewed-by: Michael Haggerty <[email protected]> Reviewed-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c078b9 commit c252785

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

fast-import.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,14 +1730,16 @@ static void dump_tags(void)
17301730
static const char *msg = "fast-import";
17311731
struct tag *t;
17321732
struct ref_lock *lock;
1733-
char ref_name[PATH_MAX];
1733+
struct strbuf ref_name = STRBUF_INIT;
17341734

17351735
for (t = first_tag; t; t = t->next_tag) {
1736-
sprintf(ref_name, "tags/%s", t->name);
1737-
lock = lock_ref_sha1(ref_name, NULL);
1736+
strbuf_reset(&ref_name);
1737+
strbuf_addf(&ref_name, "tags/%s", t->name);
1738+
lock = lock_ref_sha1(ref_name.buf, NULL);
17381739
if (!lock || write_ref_sha1(lock, t->sha1, msg) < 0)
1739-
failure |= error("Unable to update %s", ref_name);
1740+
failure |= error("Unable to update %s", ref_name.buf);
17401741
}
1742+
strbuf_release(&ref_name);
17411743
}
17421744

17431745
static void dump_marks_helper(FILE *f,

0 commit comments

Comments
 (0)