git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3] bugreport.c: fix a crash in `git bugreport` with `--no-suffix` option

From
JSJiamu Sun <baiorettohr@gmail.com>
Date
Mar 14, 2024, 22:34 UTC
Message-ID
<20240314223406.79283-1-barroit@linux.com>
In-Reply-To
<pull.1693.v2.git.1710388817.gitgitgadget@gmail.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().

By adding a NULL check, the `--no-suffix` option is now available. Using this option disables the suffix, and the file is just named `git-bugreport` without any disambiguation measure.

Signed-off-by: Jiamu Sun <barroit@linux.com>
---
Changes since v2:
- Squashed the previous patch series into a single patch for
  clarity
 Documentation/git-bugreport.txt |  6 +++++-
 builtin/bugreport.c             | 10 +++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt
index ca626f7fc6..112658b3c3 100644
--- a/Documentation/git-bugreport.txt
+++ b/Documentation/git-bugreport.txt
@@ -8,7 +8,8 @@ git-bugreport - Collect information for user to file a bug report
 SYNOPSIS
 --------
 [verse]
-'git bugreport' [(-o | --output-directory) <path>] [(-s | --suffix) <format>]
+'git bugreport' [(-o | --output-directory) <path>]
+		[(-s | --suffix) <format> | --no-suffix]
 		[--diagnose[=<mode>]]
 
 DESCRIPTION
@@ -51,9 +52,12 @@ OPTIONS
 
 -s <format>::
 --suffix <format>::
+--no-suffix::
 	Specify an alternate suffix for the bugreport name, to create a file
 	named 'git-bugreport-<formatted-suffix>'. This should take the form of a
 	strftime(3) format string; the current local time will be used.
+	`--no-suffix` disables the suffix and the file is just named
+	`git-bugreport` without any disambiguation measure.
 
 --no-diagnose::
 --diagnose[=<mode>]::
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index 3106e56a13..25f860a0d9 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -64,7 +64,8 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit)
 }
 
 static const char * const bugreport_usage[] = {
-	N_("git bugreport [(-o | --output-directory) <path>] [(-s | --suffix) <format>]\n"
+	N_("git bugreport [(-o | --output-directory) <path>]\n"
+	   "              [(-s | --suffix) <format> | --no-suffix]\n"
 	   "              [--diagnose[=<mode>]]"),
 	NULL
 };
@@ -138,8 +139,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)) {
-- 
2.44.GIT
Previous: Jiamu SunNext: Taylor Blau
Message 11 of 12 in “bugreport.c: fix a crash in `git bugreport` with `--no-suffix` option”
  1. bugreport.c: fix a crash in `git bugreport` with `--no-suffix` optionbarroit via GitGitGadget, Mar 12, 2024
  2. Junio C HamanoMar 13, 2024
  3. Junio C HamanoMar 13, 2024
  4. Taylor BlauMar 16, 2024
  5. 0/2 bugreport.c: fix a crash in git bugreport with --no-suffix optionbarroit via GitGitGadget, Mar 14, 2024
  6. 1/2 bugreport.c: fix a crash in `git bugreport` with `--no-suffix` optionJiamu Sun via GitGitGadget, Mar 14, 2024
  7. 2/2 doc: update doc file and usage for git-bugreportJiamu Sun via GitGitGadget, Mar 14, 2024
  8. Junio C HamanoMar 14, 2024
  9. Junio C HamanoMar 14, 2024
  10. Jiamu SunMar 15, 2024
  11. bugreport.c: fix a crash in `git bugreport` with `--no-suffix` optionJiamu Sun, Mar 14, 2024
  12. Taylor BlauMar 16, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.