Thread (7 messages) flat view 7 messages, 3 authors, 2d ago

Re: [PATCH] git: avoid segfault on "git --shallow-file" without a value

From: Patrick Steinhardt <hidden>
Date: 2026-08-12 11:22:30

On Tue, Aug 11, 2026 at 02:14:46PM +0200, Christian Couder wrote:
quoted hunk ↗ jump to hunk
diff --git a/git.c b/git.c
index e5f1811b6b..96df15b5cd 100644
--- a/git.c
+++ b/git.c
@@ -304,11 +304,15 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 			if (envchanged)
 				*envchanged = 1;
 		} else if (!strcmp(cmd, "--shallow-file")) {
-			(*argv)++;
-			(*argc)--;
-			setenv(GIT_SHALLOW_FILE_ENVIRONMENT, (*argv)[0], 1);
+			if (*argc < 2) {
+				fprintf(stderr, _("no file given for '%s' option\n" ), "--shallow-file");
+				usage(git_usage_string);
Should we maybe condense this into a single line?

    usage(_("no file given for '%s' option\n")), "--shallow-file")

I think that also printing the usage string is only distracting and
doesn't really give the user a lot of extra context.

Other than that this patch looks good to me, thanks!

Patrick
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help