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

Re: [PATCH 5/5] refspec.c: use rhs in parse_refspec instead of potentially uninitialized item->dst

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 1, 2018, 02:46 UTC
Message-ID
<xmqq8t7z9qc6.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<xmqqzi0f9see.fsf@gitster-ct.c.googlers.com>
Junio C Hamano <gitster@pobox.com> writes:
> Perhaps a better fisx is to explicitly assign NULL to item->dst when
> we see there is no right-hand-side.
-- >8 --
Subject: [PATCH] refspec-api: avoid uninitialized field in refspec item

When parse_refspec() function was created at 3eec3700 ("refspec: factor out parsing a single refspec", 2018-05-16) to take a caller supplied piece of memory to fill parsed refspec_item, it forgot that a refspec without colon must set item->dst to NULL to let the users of refspec know that the result of the fetch does not get stored in an ref on our side.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * The original before that change filled a callee prepared piece of
   memory that was obtained from xcalloc(), and did not need to
   explicitly assign NULL to the field after noticing that there is
   no colon in the refspec, so it is understandable how this
   misconvesion happened.
 refspec.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/refspec.c b/refspec.c
index 97e76e8b1d..6e45365a23 100644
--- a/refspec.c
+++ b/refspec.c
@@ -48,6 +48,8 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet
 		size_t rlen = strlen(++rhs);
 		is_glob = (1 <= rlen && strchr(rhs, '*'));
 		item->dst = xstrndup(rhs, rlen);
+	} else {
+		item->dst = NULL;
 	}
 
 	llen = (rhs ? (rhs - lhs - 1) : strlen(lhs));
-- 
2.18.0-rc0
Previous: Junio C HamanoNext: Stefan Beller
Message 3 of 4 in “refspec.c: use rhs in parse_refspec instead of potentially uninitialized item->dst”
  1. 5/5 refspec.c: use rhs in parse_refspec instead of potentially uninitialized item->dstStefan Beller, May 30, 2018
  2. Junio C HamanoJun 1, 2018
  3. Junio C HamanoJun 1, 2018
  4. Stefan BellerJun 1, 2018

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.