summaryrefslogtreecommitdiff
path: root/fast-import.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2014-09-19 14:05:12 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2014-09-19 14:05:12 -0700
commit04481347eccbd797bc9f3dc49e731e3ed7d639df (patch)
tree4334d7c0c45f3044272d823b04bb4291409b6e39 /fast-import.c
parentMerge branch 'jn/unpack-trees-checkout-m-carry-deletion' into maint (diff)
parentfast-import: fix buffer overflow in dump_tags (diff)
downloadtgif-04481347eccbd797bc9f3dc49e731e3ed7d639df.tar.xz
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
Diffstat (limited to 'fast-import.c')
-rw-r--r--fast-import.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/fast-import.c b/fast-import.c
index d73f58cbe3..a1479e980d 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -946,10 +946,12 @@ static void unkeep_all_packs(void)
static void end_packfile(void)
{
- struct packed_git *old_p = pack_data, *new_p;
+ if (!pack_data)
+ return;
clear_delta_base_cache();
if (object_count) {
+ struct packed_git *new_p;
unsigned char cur_pack_sha1[20];
char *idx_name;
int i;
@@ -991,10 +993,11 @@ static void end_packfile(void)
pack_id++;
}
else {
- close(old_p->pack_fd);
- unlink_or_warn(old_p->pack_name);
+ close(pack_data->pack_fd);
+ unlink_or_warn(pack_data->pack_name);
}
- free(old_p);
+ free(pack_data);
+ pack_data = NULL;
/* We can't carry a delta across packfiles. */
strbuf_release(&last_blob.data);
@@ -1731,14 +1734,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,