diff options
author | Sun He <sunheehnus@gmail.com> | 2014-03-03 17:24:29 +0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-03-03 12:15:10 -0800 |
commit | 5889271114a25b6750bb6137784ae5a93df22b39 (patch) | |
tree | 3f95ef844f90b9c35229cccf4d56c9ac3bcca9d0 /builtin/pack-objects.c | |
parent | 2156a98045f83dd88386b2d4d3241d66bf722ade (diff) | |
download | git-5889271114a25b6750bb6137784ae5a93df22b39.tar.gz git-5889271114a25b6750bb6137784ae5a93df22b39.tar.xz |
finish_tmp_packfile():use strbuf for pathname construction
The old version fixes a maximum length on the buffer, which could be a problem
if one is not certain of the length of get_object_directory().
Using strbuf can avoid the protential bug.
Helped-by: Michael Haggerty <mhagger@alum.mit.edu>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Sun He <sunheehnus@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/pack-objects.c')
-rw-r--r-- | builtin/pack-objects.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 4922ce5e2..3f427b4e4 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -803,7 +803,7 @@ static void write_pack_file(void) if (!pack_to_stdout) { struct stat st; - char tmpname[PATH_MAX]; + struct strbuf tmpname = STRBUF_INIT; /* * Packs are runtime accessed in their mtime @@ -826,23 +826,19 @@ static void write_pack_file(void) pack_tmp_name, strerror(errno)); } - /* Enough space for "-<sha-1>.pack"? */ - if (sizeof(tmpname) <= strlen(base_name) + 50) - die("pack base name '%s' too long", base_name); - snprintf(tmpname, sizeof(tmpname), "%s-", base_name); + strbuf_addf(&tmpname, "%s-", base_name); if (write_bitmap_index) { bitmap_writer_set_checksum(sha1); bitmap_writer_build_type_index(written_list, nr_written); } - finish_tmp_packfile(tmpname, pack_tmp_name, + finish_tmp_packfile(&tmpname, pack_tmp_name, written_list, nr_written, &pack_idx_opts, sha1); if (write_bitmap_index) { - char *end_of_name_prefix = strrchr(tmpname, 0); - sprintf(end_of_name_prefix, "%s.bitmap", sha1_to_hex(sha1)); + strbuf_addf(&tmpname, "%s.bitmap", sha1_to_hex(sha1)); stop_progress(&progress_state); @@ -851,10 +847,11 @@ static void write_pack_file(void) bitmap_writer_select_commits(indexed_commits, indexed_commits_nr, -1); bitmap_writer_build(&to_pack); bitmap_writer_finish(written_list, nr_written, - tmpname, write_bitmap_options); + tmpname.buf, write_bitmap_options); write_bitmap_index = 0; } + strbuf_release(&tmpname); free(pack_tmp_name); puts(sha1_to_hex(sha1)); } |