[PATCH 1/4] fast-import: use xsnprintf for writing sha1s
- From
Jeff King <peff@peff.net>
- Date
- Mar 24, 2017, 17:25 UTC
- Message-ID
- <20170324172522.l4sawf2u42mrnswk@sigill.intra.peff.net>
- In-Reply-To
- <20170324172246.fy5drvhzqxghu44a@sigill.intra.peff.net>
When we have to write a sha1 with a newline, we do so by copying both into a single buffer, so that we can issue a single write() call.
We use snprintf but don't bother to check the output, since we know it will fit. However, we should use xsnprintf() in such a case so that we're notified if our assumption turns out to be wrong (and to make it easier to audit for unchecked snprintf calls).
Signed-off-by: Jeff King <peff@peff.net> --- This is ready for conversion to oid_to_hex, too, but I avoided that here. The buffer would need to be allocated with the new GIT_MAX_HEXSZ, which is not yet available. So I figured it was better to leave it than half-convert it and leave brian wondering whether it's really supposed to be GIT_MAX_HEXSZ or GIT_SHA1_HEXSZ.
fast-import.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fast-import.c b/fast-import.c index 41a539f97..4e0f3f5dd 100644 --- a/fast-import.c +++ b/fast-import.c @@ -3003,7 +3003,7 @@ static void parse_get_mark(const char *p) if (!oe) die("Unknown mark: %s", command_buf.buf); - snprintf(output, sizeof(output), "%s\n", sha1_to_hex(oe->idx.sha1)); + xsnprintf(output, sizeof(output), "%s\n", sha1_to_hex(oe->idx.sha1)); cat_blob_write(output, 41); }
-- 2.12.1.843.g1937c56c2