diff options
author | Jeff King <peff@peff.net> | 2015-09-24 17:06:42 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-09-25 10:18:18 -0700 |
commit | ef1286d3c0ba714c6c2ae87e14edf3c462aef114 (patch) | |
tree | b43b47b015c9a6bc479bb221ddc299996e336183 /fast-import.c | |
parent | f2f026752993054c1b712b6f4ae3ff167db38cbe (diff) | |
download | git-ef1286d3c0ba714c6c2ae87e14edf3c462aef114.tar.gz |
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'fast-import.c')
-rw-r--r-- | fast-import.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/fast-import.c b/fast-import.c index 6c7c3c9b66..d0c25024cd 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1035,8 +1035,8 @@ static int store_object( git_SHA_CTX c; git_zstream s; - hdrlen = sprintf((char *)hdr,"%s %lu", typename(type), - (unsigned long)dat->len) + 1; + hdrlen = xsnprintf((char *)hdr, sizeof(hdr), "%s %lu", + typename(type), (unsigned long)dat->len) + 1; git_SHA1_Init(&c); git_SHA1_Update(&c, hdr, hdrlen); git_SHA1_Update(&c, dat->buf, dat->len); |