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>
This commit is contained in:

committed by
Junio C Hamano

parent
f2f0267529
commit
ef1286d3c0
@ -361,7 +361,7 @@ static void start_put(struct transfer_request *request)
|
||||
git_zstream stream;
|
||||
|
||||
unpacked = read_sha1_file(request->obj->sha1, &type, &len);
|
||||
hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1;
|
||||
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1;
|
||||
|
||||
/* Set it up */
|
||||
git_deflate_init(&stream, zlib_compression_level);
|
||||
|
Reference in New Issue
Block a user