Skip to content

Commit 8a3152c

Browse files
p1-gddphillipwood
authored andcommitted
show-branch: fix SEGFAULT when --current and --reflog together
If run `show-branch` with `--current` and `--reflog` simultaneously, a SEGFAULT appears. The bug is that we read over the end of the `reflog_msg` array after having `append_one_rev()` for the current branch without supplying a convenient message to it. It seems that it has been introduced in: Commit 1aa68d6 (show-branch: --current includes the current branch., 2006-01-11) Signed-off-by: Gregory DAVID <[email protected]> Thanks-to: Ævar Arnfjörð Bjarmason <[email protected]>
1 parent 34b2b12 commit 8a3152c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

builtin/show-branch.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,26 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
813813
}
814814
if (!has_head) {
815815
const char *name = head;
816+
struct object_id oid;
817+
char *ref;
818+
unsigned int flags = 0;
819+
char *log_msg;
820+
char *end_log_msg;
821+
timestamp_t timestamp;
822+
int tz;
823+
824+
if (!dwim_ref(*av, strlen(*av), &oid, &ref, 0))
825+
die(_("no such ref %s"), *av);
826+
if(read_ref_at(get_main_ref_store(the_repository),
827+
ref, flags, 0, i, &oid, &log_msg,
828+
&timestamp, &tz, NULL)) {
829+
end_log_msg = strchr(log_msg, '\n');
830+
if (end_log_msg)
831+
*end_log_msg = '\0';
832+
}
833+
if(log_msg == 0 || *log_msg == '\0')
834+
log_msg = xstrfmt("(none)");
835+
reflog_msg[ref_name_cnt] = xstrfmt("(%s) (current) %s", show_date(timestamp, tz, DATE_MODE(RELATIVE)), log_msg);
816836
skip_prefix(name, "refs/heads/", &name);
817837
append_one_rev(name);
818838
}

0 commit comments

Comments
 (0)