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

Re: [PATCH 3/5] wt-status: avoid building bogus branch name with detached HEAD

From
René Scharfe <l.s.r@web.de>
Date
Nov 1, 2015, 18:11 UTC
Message-ID
<563655BA.906@web.de>
In-Reply-To
<xmqqbnbdip6y.fsf@gitster.mtv.corp.google.com>
Am 01.11.2015 um 18:50 schrieb Junio C Hamano:
Show 20 quoted lines
> René Scharfe <l.s.r@web.de> writes:
>
>> If we're on a detached HEAD then wt_shortstatus_print_tracking() takes
>> the string "HEAD (no branch)", translates it, skips the first eleven
>> characters and passes the result to branch_get(), which returns a bogus
>> result and accesses memory out of bounds in order to produce it.
>
> The fix is correct, but the above explanation looks "not quite" to
> me.
>
> That "HEAD (no branch)" thing is in a separate branch_name variable
> that is not involved in the actual computation (i.e. call to
> branch_get()).
>
> The function gets "HEAD" in s->branch, uses that and skips the first
> eleven characters (i.e. beyond the end of that string), lets
> branch_get() to return a garbage and likely missing branch, finds
> that nobody tracks that, and does the right thing anyway.  If the
> garbage past the end of the "HEAD" happens to have a name of an
> existing branch, we would get an incorrect result.

Ah, yes. This came from an earlier round which had patch 3 and 4 reversed, causing the translated string to be passed to branch_get(). Thanks for catching the commit message inconsistency!

René
Previous: Junio C HamanoNext: René Scharfe
Message 6 of 10 in “wt-status: fix an invalid memory read, clean up”
  1. 0/5 wt-status: fix an invalid memory read, clean upRené Scharfe, Oct 31, 2015
  2. 1/5 t7060: add test for status --branch on a detached HEADRené Scharfe, Oct 31, 2015
  3. 2/5 wt-status: exit early using goto in wt_shortstatus_print_tracking()René Scharfe, Oct 31, 2015
  4. 3/5 wt-status: avoid building bogus branch name with detached HEADRené Scharfe, Oct 31, 2015
  5. Junio C HamanoNov 1, 2015
  6. René ScharfeNov 1, 2015
  7. 4/5 wt-status: don't skip a magical number of characters blindlyRené Scharfe, Oct 31, 2015
  8. Junio C HamanoNov 1, 2015
  9. Junio C HamanoNov 1, 2015
  10. 5/5 wt-status: use skip_prefix() to get rid of magic string length constantsRené Scharfe, Oct 31, 2015

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.