git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bugreport.c: fix a crash in `git bugreport` with `--no-suffix` option
@ 2024-03-12 16:26 barroit via GitGitGadget
  2024-03-13 15:59 ` Junio C Hamano
  2024-03-14  4:00 ` [PATCH v2 0/2] bugreport.c: fix a crash in git bugreport with --no-suffix option barroit via GitGitGadget
  0 siblings, 2 replies; 12+ messages in thread
From: barroit via GitGitGadget @ 2024-03-12 16:26 UTC (permalink / raw)
  To: git; +Cc: barroit, Jiamu Sun

From: Jiamu Sun <barroit@linux.com>

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>
---
    bugreport.c: fix a crash in git bugreport with --no-suffix option
    
    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().

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1693%2Fbarroit%2Ffix-bugreport-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1693/barroit/fix-bugreport-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1693

 builtin/bugreport.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index 3106e56a130..32281815b77 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -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)) {

base-commit: 945115026aa63df4ab849ab14a04da31623abece
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-03-16  1:56 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-12 16:26 [PATCH] bugreport.c: fix a crash in `git bugreport` with `--no-suffix` option barroit via GitGitGadget
2024-03-13 15:59 ` Junio C Hamano
2024-03-13 17:42   ` Junio C Hamano
2024-03-16  1:55   ` Taylor Blau
2024-03-14  4:00 ` [PATCH v2 0/2] bugreport.c: fix a crash in git bugreport with --no-suffix option barroit via GitGitGadget
2024-03-14  4:00   ` [PATCH v2 1/2] bugreport.c: fix a crash in `git bugreport` with `--no-suffix` option Jiamu Sun via GitGitGadget
2024-03-14  4:00   ` [PATCH v2 2/2] doc: update doc file and usage for git-bugreport Jiamu Sun via GitGitGadget
2024-03-14 16:27   ` [PATCH v2 0/2] bugreport.c: fix a crash in git bugreport with --no-suffix option Junio C Hamano
2024-03-14 16:33     ` Junio C Hamano
2024-03-15 22:42       ` [PATCH v3] " Jiamu Sun
2024-03-14 22:34   ` [PATCH v3] bugreport.c: fix a crash in `git bugreport` with `--no-suffix` option Jiamu Sun
2024-03-16  1:56     ` Taylor Blau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).