Skip to content

Commit 0448134

Browse files
committed
Merge branch 'jk/fast-import-fixes' into maint
* jk/fast-import-fixes: fast-import: fix buffer overflow in dump_tags fast-import: clean up pack_data pointer in end_packfile
2 parents a28e876 + c252785 commit 0448134

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

fast-import.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -946,10 +946,12 @@ static void unkeep_all_packs(void)
946946

947947
static void end_packfile(void)
948948
{
949-
struct packed_git *old_p = pack_data, *new_p;
949+
if (!pack_data)
950+
return;
950951

951952
clear_delta_base_cache();
952953
if (object_count) {
954+
struct packed_git *new_p;
953955
unsigned char cur_pack_sha1[20];
954956
char *idx_name;
955957
int i;
@@ -991,10 +993,11 @@ static void end_packfile(void)
991993
pack_id++;
992994
}
993995
else {
994-
close(old_p->pack_fd);
995-
unlink_or_warn(old_p->pack_name);
996+
close(pack_data->pack_fd);
997+
unlink_or_warn(pack_data->pack_name);
996998
}
997-
free(old_p);
999+
free(pack_data);
1000+
pack_data = NULL;
9981001

9991002
/* We can't carry a delta across packfiles. */
10001003
strbuf_release(&last_blob.data);
@@ -1731,14 +1734,16 @@ static void dump_tags(void)
17311734
static const char *msg = "fast-import";
17321735
struct tag *t;
17331736
struct ref_lock *lock;
1734-
char ref_name[PATH_MAX];
1737+
struct strbuf ref_name = STRBUF_INIT;
17351738

17361739
for (t = first_tag; t; t = t->next_tag) {
1737-
sprintf(ref_name, "tags/%s", t->name);
1738-
lock = lock_ref_sha1(ref_name, NULL);
1740+
strbuf_reset(&ref_name);
1741+
strbuf_addf(&ref_name, "tags/%s", t->name);
1742+
lock = lock_ref_sha1(ref_name.buf, NULL);
17391743
if (!lock || write_ref_sha1(lock, t->sha1, msg) < 0)
1740-
failure |= error("Unable to update %s", ref_name);
1744+
failure |= error("Unable to update %s", ref_name.buf);
17411745
}
1746+
strbuf_release(&ref_name);
17421747
}
17431748

17441749
static void dump_marks_helper(FILE *f,

0 commit comments

Comments
 (0)