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

Re: [PATCH] archive: error instead of triggering a segfault in `git archive --remote=""`

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 10, 2025, 15:59 UTC
Message-ID
<xmqq7c4wanb8.fsf@gitster.g>
In-Reply-To
<Z86WtQ-3Rk9OSmn_@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 7 quoted lines
>> +	if (remote && !remote[0]) {
>
> Okay, so this triggers in case the user passes "--remote ''"?
> I see that we ultimately pass the string to `remote_get()`, so does that
> function segfault? If so, can other callers of that function segfault in
> a similar way? In that case, we should probably address the issue deeper
> down in the call stack.

A good thing to point out. If remote_get() segfaults, that is a grave bug. If remote_get() returns a NULL for such a non-existent remote, the code should be able to cope with it, or you found a bug.

In short, I agree with you that this may merely be sweeping a problem under a rug, not addressing a real problem.

run_remote_archiver() seems to run remote_get() and use the returned value (which could be NULL, if you named a remote nickname that you do not even have) without validating when it calls transport_get(), so that is probably where the problem lies. If I were writing this code path, I would probably make run_remote_archiver() take a pointer to an instance of "struct remote", moving the call to remote_get() to the caller's side, and deal with an error inside cmd_archive().

Thanks.
Previous: Patrick SteinhardtNext: Junio C Hamano
Message 3 of 4 in “archive: error instead of triggering a segfault in `git archive --remote=""`”
  1. archive: error instead of triggering a segfault in `git archive --remote=""`emilylime via GitGitGadget, Mar 9, 2025
  2. Patrick SteinhardtMar 10, 2025
  3. Junio C HamanoMar 10, 2025
  4. Junio C HamanoMar 10, 2025

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.