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

[PATCH] format-patch: dereference tags with --ignore-if-in-upstream

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jun 1, 2015, 01:03 UTC
Message-ID
<1433120593-186980-1-git-send-email-sandals@crustytoothpaste.net>
In-Reply-To
<CAP8UFD1phg8E0JCgkz88CMUo9H-W=s5JDuKeCMOkf1=UYBJt+g@mail.gmail.com>

format-patch would segfault if provided a tag as one of the range endpoints in conjunction with --ignore-if-in-upstream, as it assumed the object was a commit and attempted to cast it to struct commit. Dereference the tag as soon as possible to prevent this, but not until after copying the necessary flags.

Reported-by: Bruce Korb <bruce.korb@gmail.com>
Diagnosed-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/log.c           |  6 ++++++
 t/t4014-format-patch.sh | 10 ++++++++++
 2 files changed, 16 insertions(+)
diff --git a/builtin/log.c b/builtin/log.c
index dd8f3fc..e0465ba 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -807,6 +807,12 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
 	o2 = rev->pending.objects[1].item;
 	flags2 = o2->flags;
 
+	o1 = deref_tag(o1, NULL, 0);
+	o2 = deref_tag(o2, NULL, 0);
+
+	if (!o1 || !o2)
+		die(_("Invalid tag."));
+
 	if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))
 		die(_("Not a range."));
 
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index c39e500..60b9875 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -57,6 +57,16 @@ test_expect_success "format-patch --ignore-if-in-upstream" '
 
 '
 
+test_expect_success "format-patch --ignore-if-in-upstream handles tags" '
+
+	git tag -a v1 -m tag side &&
+	git format-patch --stdout \
+		--ignore-if-in-upstream master..v1 >patch1 &&
+	cnt=$(grep "^From " patch1 | wc -l) &&
+	test $cnt = 2
+
+'
+
 test_expect_success "format-patch doesn't consider merge commits" '
 
 	git checkout -b slave master &&
-- 
2.4.0
Previous: Christian CouderNext: Jeff King
Message 8 of 21 in “seg fault in "git format-patch"”
  1. Bruce KorbMay 31, 2015
  2. Christian CouderMay 31, 2015
  3. Bruce KorbMay 31, 2015
  4. Bruce KorbMay 31, 2015
  5. Christian CouderMay 31, 2015
  6. Christian CouderMay 31, 2015
  7. Christian CouderJun 1, 2015
  8. format-patch: dereference tags with --ignore-if-in-upstreambrian m. carlson, Jun 1, 2015
  9. Jeff KingJun 1, 2015
  10. brian m. carlsonJun 1, 2015
  11. Jeff KingJun 1, 2015
  12. Junio C HamanoJun 1, 2015
  13. Junio C HamanoJun 1, 2015
  14. Jeff KingJun 1, 2015
  15. Junio C HamanoJun 1, 2015
  16. brian m. carlsonJun 1, 2015
  17. Junio C HamanoJun 1, 2015
  18. Junio C HamanoJun 1, 2015
  19. Christian CouderJun 1, 2015
  20. Christian CouderJun 1, 2015
  21. Bruce KorbJun 1, 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.