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

Re: [PATCH v3 06/20] builtin/receive-pack: convert portions to struct object_id

From
René Scharfe <l.s.r@web.de>
Date
Jul 15, 2017, 18:33 UTC
Message-ID
<cb9c62dc-0171-19f2-7d37-ebb726426a4d@web.de>
In-Reply-To
<20170331014001.953484-7-sandals@crustytoothpaste.net>
Am 31.03.2017 um 03:39 schrieb brian m. carlson:
Show 11 quoted lines
> @@ -1081,10 +1081,10 @@ static const char *update(struct command *cmd, struct shallow_info *si)
>   		return "hook declined";
>   	}
>   
> -	if (is_null_sha1(new_sha1)) {
> +	if (is_null_oid(new_oid)) {
>   		struct strbuf err = STRBUF_INIT;
> -		if (!parse_object(old_sha1)) {
> -			old_sha1 = NULL;
> +		if (!parse_object(old_oid->hash)) {
> +			old_oid = NULL;
So old_oid can become NULL...
Show 9 quoted lines
>   			if (ref_exists(name)) {
>   				rp_warning("Allowing deletion of corrupt ref.");
>   			} else {
> @@ -1094,7 +1094,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
>   		}
>   		if (ref_transaction_delete(transaction,
>   					   namespaced_name,
> -					   old_sha1,
> +					   old_oid->hash,
... and here we dereference it.
-- >8 --
Subject: [PATCH] receive-pack: don't access hash of NULL object_id pointer

We set old_oid to NULL if we found out that it's a corrupt reference. In that case don't try to access the hash member and pass NULL to ref_transaction_delete() instead.

Found with Clang's UBSan.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
That's the last bug of this kind which "make SANITIZE=undefined test"
turned up.
 builtin/receive-pack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index cabdc55e09..946cf55138 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1138,7 +1138,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
 		}
 		if (ref_transaction_delete(transaction,
 					   namespaced_name,
-					   old_oid->hash,
+					   old_oid ? old_oid->hash : NULL,
 					   0, "push", &err)) {
 			rp_error("%s", err.buf);
 			strbuf_release(&err);
-- 
2.13.3
Previous: brian m. carlsonNext: brian m. carlson
Message 22 of 24 in “object_id part 7”
  1. 00/20 object_id part 7brian m. carlson, Mar 31, 2017
  2. 04/20 builtin/diff: convert to struct object_idbrian m. carlson, Mar 31, 2017
  3. 09/20 test-sha1-array: convert most code to struct object_idbrian m. carlson, Mar 31, 2017
  4. 13/20 builtin/pull: convert to struct object_idbrian m. carlson, Mar 31, 2017
  5. 15/20 Make sha1_array_append take a struct object_id *brian m. carlson, Mar 31, 2017
  6. 12/20 submodule: convert check_for_new_submodule_commits to object_idbrian m. carlson, Mar 31, 2017
  7. 16/20 Convert remaining callers of sha1_array_lookup to object_idbrian m. carlson, Mar 31, 2017
  8. 19/20 Rename sha1_array to oid_arraybrian m. carlson, Mar 31, 2017
  9. 20/20 Documentation: update and rename api-sha1-array.txtbrian m. carlson, Mar 31, 2017
  10. 14/20 sha1-array: convert internal storage for struct sha1_array to object_idbrian m. carlson, Mar 31, 2017
  11. Junio C HamanoMar 31, 2017
  12. 18/20 Convert sha1_array_for_each_unique and for_each_abbrev to object_idbrian m. carlson, Mar 31, 2017
  13. 07/20 fsck: convert init_skiplist to struct object_idbrian m. carlson, Mar 31, 2017
  14. 17/20 Convert sha1_array_lookup to take struct object_idbrian m. carlson, Mar 31, 2017
  15. 11/20 sha1_name: convert disambiguate_hint_fn to take object_idbrian m. carlson, Mar 31, 2017
  16. 08/20 parse-options-cb: convert sha1_array_append caller to struct object_idbrian m. carlson, Mar 31, 2017
  17. 10/20 sha1_name: convert struct disambiguate_state to object_idbrian m. carlson, Mar 31, 2017
  18. 01/20 Define new hash-size constants for allocating memorybrian m. carlson, Mar 31, 2017
  19. 03/20 Convert GIT_SHA1_RAWSZ used for allocation to GIT_MAX_RAWSZbrian m. carlson, Mar 31, 2017
  20. 05/20 builtin/pull: convert portions to struct object_idbrian m. carlson, Mar 31, 2017
  21. 06/20 builtin/receive-pack: convert portions to struct object_idbrian m. carlson, Mar 31, 2017
  22. René ScharfeJul 15, 2017
  23. 02/20 Convert GIT_SHA1_HEXSZ used for allocation to GIT_MAX_HEXSZbrian m. carlson, Mar 31, 2017
  24. Junio C HamanoMar 31, 2017

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.