From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 1/4] fast-import: use xsnprintf for writing sha1s
Date: Fri, 24 Mar 2017 13:25:22 -0400 [thread overview]
Message-ID: <20170324172522.l4sawf2u42mrnswk@sigill.intra.peff.net> (raw)
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
next prev parent reply other threads:[~2017-03-24 17:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-24 17:22 [PATCH 0/4] a few minor buffer cleanups in fast-import Jeff King
2017-03-24 17:25 ` Jeff King [this message]
2017-03-24 17:26 ` [PATCH 2/4] fast-import: use xsnprintf for formatting headers Jeff King
2017-03-24 17:26 ` [PATCH 3/4] encode_in_pack_object_header: respect output buffer length Jeff King
2017-03-24 17:26 ` [PATCH 4/4] pack.h: define largest possible encoded object size Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170324172522.l4sawf2u42mrnswk@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).