summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-05-19 01:58:20 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-05-21 00:59:03 (GMT)
commitbf4baf1fed7916ed10f2759a6f30a38990a83cae (patch)
tree628870d63e3bd54eda71a2f0b6fb971f995585cd /refs.c
parent735e4173b3feba0cc495bbb2dd85341b6378f628 (diff)
downloadgit-bf4baf1fed7916ed10f2759a6f30a38990a83cae.zip
git-bf4baf1fed7916ed10f2759a6f30a38990a83cae.tar.gz
git-bf4baf1fed7916ed10f2759a6f30a38990a83cae.tar.bz2
shorten_unambiguous_ref: use xsnprintf
We convert the ref_rev_parse_rules array into scanf formats on the fly, and use snprintf() to write into each string. We should have enough memory to hold everything because of the earlier total_len computation. Let's use xsnprintf() to give runtime confirmation that this is the case, and to make it easy for people auditing the code to know there's no truncation bug. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/refs.c b/refs.c
index 20ba82b..bd7ac72 100644
--- a/refs.c
+++ b/refs.c
@@ -1132,8 +1132,8 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
for (i = 0; i < nr_rules; i++) {
assert(offset < total_len);
scanf_fmts[i] = (char *)&scanf_fmts[nr_rules] + offset;
- offset += snprintf(scanf_fmts[i], total_len - offset,
- ref_rev_parse_rules[i], 2, "%s") + 1;
+ offset += xsnprintf(scanf_fmts[i], total_len - offset,
+ ref_rev_parse_rules[i], 2, "%s") + 1;
}
}