index-pack: fix buffer overflow caused by translations

The translation of "completed with %d local objects" is put in a 48-byte buffer, which may be enough for English but not true for any translations. Convert it to use strbuf (i.e. no hard limit on translation length). Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Mar 16, 2013 at 08:25 UTC 5c3459fc61c035420c90b7d73e23242493be6cbd
1 file changed +5 -4
builtin/index-pack.c
+5 -4
@@ -1099,7 +1099,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
1099 if (fix_thin_pack) {
1100 struct sha1file *f;
1101 unsigned char read_sha1[20], tail_sha1[20];
1102 - char msg[48];
1102 + struct strbuf msg = STRBUF_INIT;
1103 int nr_unresolved = nr_deltas - nr_resolved_deltas;
1104 int nr_objects_initial = nr_objects;
1105 if (nr_unresolved <= 0)
@@ -1109,9 +1109,10 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
1109 * sizeof(*objects));
1110 f = sha1fd(output_fd, curr_pack);
1111 fix_unresolved_deltas(f, nr_unresolved);
1112 - sprintf(msg, _("completed with %d local objects"),
1113 - nr_objects - nr_objects_initial);
1114 - stop_progress_msg(&progress, msg);
1112 + strbuf_addf(&msg, _("completed with %d local objects"),
1113 + nr_objects - nr_objects_initial);
1114 + stop_progress_msg(&progress, msg.buf);
1115 + strbuf_release(&msg);
1116 sha1close(f, tail_sha1, 0);
1117 hashcpy(read_sha1, pack_sha1);
1118 fixup_pack_header_footer(output_fd, pack_sha1,