transport: use strbufs for status table "quickref" strings
We generate range strings like "1234abcd...5678efab" for use in the the fetch and push status tables. We use fixed-size buffers along with strcat to do so. These aren't buggy, as our manual size computation is correct, but there's nothing checking that this is so. Let's switch them to strbufs instead, which are obviously correct, and make it easier to audit the code base for problematic calls to strcat(). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
6c31c22ceb
commit
bd22d4ffbc
@ -528,36 +528,38 @@ static int update_local_ref(struct ref *ref,
|
||||
}
|
||||
|
||||
if (in_merge_bases(current, updated)) {
|
||||
char quickref[83];
|
||||
struct strbuf quickref = STRBUF_INIT;
|
||||
int r;
|
||||
strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
|
||||
strcat(quickref, "..");
|
||||
strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
|
||||
strbuf_add_unique_abbrev(&quickref, current->object.sha1, DEFAULT_ABBREV);
|
||||
strbuf_addstr(&quickref, "..");
|
||||
strbuf_add_unique_abbrev(&quickref, ref->new_sha1, DEFAULT_ABBREV);
|
||||
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
|
||||
(recurse_submodules != RECURSE_SUBMODULES_ON))
|
||||
check_for_new_submodule_commits(ref->new_sha1);
|
||||
r = s_update_ref("fast-forward", ref, 1);
|
||||
strbuf_addf(display, "%c %-*s %-*s -> %s%s",
|
||||
r ? '!' : ' ',
|
||||
TRANSPORT_SUMMARY_WIDTH, quickref,
|
||||
TRANSPORT_SUMMARY_WIDTH, quickref.buf,
|
||||
REFCOL_WIDTH, remote, pretty_ref,
|
||||
r ? _(" (unable to update local ref)") : "");
|
||||
strbuf_release(&quickref);
|
||||
return r;
|
||||
} else if (force || ref->force) {
|
||||
char quickref[84];
|
||||
struct strbuf quickref = STRBUF_INIT;
|
||||
int r;
|
||||
strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
|
||||
strcat(quickref, "...");
|
||||
strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
|
||||
strbuf_add_unique_abbrev(&quickref, current->object.sha1, DEFAULT_ABBREV);
|
||||
strbuf_addstr(&quickref, "...");
|
||||
strbuf_add_unique_abbrev(&quickref, ref->new_sha1, DEFAULT_ABBREV);
|
||||
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
|
||||
(recurse_submodules != RECURSE_SUBMODULES_ON))
|
||||
check_for_new_submodule_commits(ref->new_sha1);
|
||||
r = s_update_ref("forced-update", ref, 1);
|
||||
strbuf_addf(display, "%c %-*s %-*s -> %s (%s)",
|
||||
r ? '!' : '+',
|
||||
TRANSPORT_SUMMARY_WIDTH, quickref,
|
||||
TRANSPORT_SUMMARY_WIDTH, quickref.buf,
|
||||
REFCOL_WIDTH, remote, pretty_ref,
|
||||
r ? _("unable to update local ref") : _("forced update"));
|
||||
strbuf_release(&quickref);
|
||||
return r;
|
||||
} else {
|
||||
strbuf_addf(display, "! %-*s %-*s -> %s %s",
|
||||
|
13
transport.c
13
transport.c
@ -654,23 +654,24 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
|
||||
"[new branch]"),
|
||||
ref, ref->peer_ref, NULL, porcelain);
|
||||
else {
|
||||
char quickref[84];
|
||||
struct strbuf quickref = STRBUF_INIT;
|
||||
char type;
|
||||
const char *msg;
|
||||
|
||||
strcpy(quickref, status_abbrev(ref->old_sha1));
|
||||
strbuf_addstr(&quickref, status_abbrev(ref->old_sha1));
|
||||
if (ref->forced_update) {
|
||||
strcat(quickref, "...");
|
||||
strbuf_addstr(&quickref, "...");
|
||||
type = '+';
|
||||
msg = "forced update";
|
||||
} else {
|
||||
strcat(quickref, "..");
|
||||
strbuf_addstr(&quickref, "..");
|
||||
type = ' ';
|
||||
msg = NULL;
|
||||
}
|
||||
strcat(quickref, status_abbrev(ref->new_sha1));
|
||||
strbuf_addstr(&quickref, status_abbrev(ref->new_sha1));
|
||||
|
||||
print_ref_status(type, quickref, ref, ref->peer_ref, msg, porcelain);
|
||||
print_ref_status(type, quickref.buf, ref, ref->peer_ref, msg, porcelain);
|
||||
strbuf_release(&quickref);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user