Skip to content

Commit bf4baf1

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 735e417 commit bf4baf1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

refs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,8 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
11321132
for (i = 0; i < nr_rules; i++) {
11331133
assert(offset < total_len);
11341134
scanf_fmts[i] = (char *)&scanf_fmts[nr_rules] + offset;
1135-
offset += snprintf(scanf_fmts[i], total_len - offset,
1136-
ref_rev_parse_rules[i], 2, "%s") + 1;
1135+
offset += xsnprintf(scanf_fmts[i], total_len - offset,
1136+
ref_rev_parse_rules[i], 2, "%s") + 1;
11371137
}
11381138
}
11391139

0 commit comments

Comments
 (0)