Skip to content

Commit

Permalink
bugreport.c: fix a crash in git bugreport with --no-suffix option
Browse files Browse the repository at this point in the history
executing `git bugreport --no-suffix` led to a segmentation fault
due to strbuf_addftime() being called with a NULL option_suffix
variable. This occurs because negating the "--[no-]suffix" option
causes the parser to set option_suffix to NULL, which is not
handled prior to calling strbuf_addftime().

Signed-off-by: Jiamu Sun <barroit@linux.com>
  • Loading branch information
barroit committed Mar 12, 2024
1 parent 9451150 commit 9c6f3f5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions builtin/bugreport.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,11 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
strbuf_complete(&report_path, '/');
output_path_len = report_path.len;

strbuf_addstr(&report_path, "git-bugreport-");
strbuf_addftime(&report_path, option_suffix, localtime_r(&now, &tm), 0, 0);
strbuf_addstr(&report_path, "git-bugreport");
if (option_suffix) {
strbuf_addch(&report_path, '-');
strbuf_addftime(&report_path, option_suffix, localtime_r(&now, &tm), 0, 0);
}
strbuf_addstr(&report_path, ".txt");

switch (safe_create_leading_directories(report_path.buf)) {
Expand Down

0 comments on commit 9c6f3f5

Please sign in to comment.