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

Re: git segfault in tag verify (patch included)

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 16, 2019, 18:20 UTC
Message-ID
<xmqqsgr53kov.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<CAOGP0GoYviFHhFzhqEimEw+ebd=DJx9JucG4BNvSvPuDudoWxw@mail.gmail.com>
Steven Roberts <fenderq@gmail.com> writes:
> I believe I have found an off-by-one error in git.
>
> Please see https://marc.info/?l=openbsd-ports&m=156326783610123&w=2
That is this thing.
        static void parse_gpg_output(struct signature_check *sigc)
        {
                const char *buf = sigc->gpg_status;
                const char *line, *next;
                int i, j;
                int seen_exclusive_status = 0;
                /* Iterate over all lines */
                for (line = buf; *line; line = strchrnul(line+1, '\n')) {
                        while (*line == '\n')
                                line++;
                        /* Skip lines that don't start with GNUPG status */
                        if (!skip_prefix(line, "[GNUPG:] ", &line))
                                continue;

If the GPG output ends with a trailing blank line, we skip and get to the terminating NUL, then find that it does not begin with the "[GNUPG:] " prefix, and hit the continue. We try to scan and look for LF (or stop at the end of the string) for the next round, starting at one past where we are, which is already the terminating NUL. Ouch.

Good finding.
We need your sign-off (see Documentation/SubmittingPatches).
Thanks.
-- >8 --
From: Steven Roberts <fenderq@gmail.com>
Subject: gpg-interface: do not scan past the end of buffer

If the GPG output ends with trailing blank lines, after skipping them over inside the loop to find the terminating NUL at the end, the loop ends up looking for the next line, starting past the end.

---
 gpg-interface.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/gpg-interface.c b/gpg-interface.c
index 8ed274533f..eb55d46ea4 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -116,6 +116,9 @@ static void parse_gpg_output(struct signature_check *sigc)
 	for (line = buf; *line; line = strchrnul(line+1, '\n')) {
 		while (*line == '\n')
 			line++;
+		if (!*line)
+			break;
+
 		/* Skip lines that don't start with GNUPG status */
 		if (!skip_prefix(line, "[GNUPG:] ", &line))
 			continue;
Previous: Steven RobertsNext: Steven Roberts
Message 2 of 5 in “git segfault in tag verify (patch included)”
  1. Steven RobertsJul 16, 2019
  2. Junio C HamanoJul 16, 2019
  3. Steven RobertsJul 16, 2019
  4. Jeff KingJul 16, 2019
  5. Junio C HamanoJul 16, 2019

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.