path: root/builtin/index-pack.c
diff options
authorJeff King <>2015-09-24 21:06:42 (GMT)
committerJunio C Hamano <>2015-09-25 17:18:18 (GMT)
commitef1286d3c0ba714c6c2ae87e14edf3c462aef114 (patch)
treeb43b47b015c9a6bc479bb221ddc299996e336183 /builtin/index-pack.c
parentf2f026752993054c1b712b6f4ae3ff167db38cbe (diff)
use xsnprintf for generating git object headers
We generally use 32-byte buffers to format git's "type size" header fields. These should not generally overflow unless you can produce some truly gigantic objects (and our types come from our internal array of constant strings). But it is a good idea to use xsnprintf to make sure this is the case. Note that we slightly modify the interface to write_sha1_file_prepare, which nows uses "hdrlen" as an "in" parameter as well as an "out" (on the way in it stores the allocated size of the header, and on the way out it returns the ultimate size of the header). Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/index-pack.c')
1 files changed, 1 insertions, 1 deletions
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 3431de2..1ad1bde 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -441,7 +441,7 @@ static void *unpack_entry_data(unsigned long offset, unsigned long size,
int hdrlen;
if (!is_delta_type(type)) {
- hdrlen = sprintf(hdr, "%s %lu", typename(type), size) + 1;
+ hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), size) + 1;
git_SHA1_Update(&c, hdr, hdrlen);
} else