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

[PATCH] graph: avoid infinite loop in graph_show_commit()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Sep 22, 2012, 14:24 UTC
Message-ID
<1348323880-3751-1-git-send-email-pclouds@gmail.com>

The loop can be triggered with "git diff-tree --graph commit" where the commit is a non-merge. It goes like this

 - graph_show_commit
 - graph_next_line
 - graph_output_padding_line

The last function quits because graph->commit is NULL, but graph_next_line() does not return "shown", so the loop in graph_show_commit keeps going.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Corner case. Nobody sane would do that. But still worth plugging.
 graph.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/graph.c b/graph.c
index e864fe2..1735b26 100644
--- a/graph.c
+++ b/graph.c
@@ -1224,7 +1224,7 @@ void graph_show_commit(struct git_graph *graph)
 	struct strbuf msgbuf = STRBUF_INIT;
 	int shown_commit_line = 0;
 
-	if (!graph)
+	if (!graph || !graph->commit)
 		return;
 
 	while (!shown_commit_line) {
-- 
1.7.12.1.389.gc2218b5
Next: Michal Kiedrowicz
Message 1 of 5 in “graph: avoid infinite loop in graph_show_commit()”
  1. graph: avoid infinite loop in graph_show_commit()Nguyễn Thái Ngọc Duy, Sep 22, 2012
  2. Michal KiedrowiczSep 23, 2012
  3. Nguyen Thai Ngoc DuySep 23, 2012
  4. Junio C HamanoSep 24, 2012
  5. Junio C HamanoSep 25, 2012

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.