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

Re: Bug: Segmentation fault in git diff

From
Đoàn Trần Công Danh <congdanhqx@gmail.com>
Date
Aug 18, 2021, 12:52 UTC
Message-ID
<YR0CkdVNVKa65vbo@danh.dev>
In-Reply-To
<YRzkq47gOGfn8zsw@danh.dev>
On 2021-08-18 17:44:59+0700, Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote:
Show 50 quoted lines
> On 2021-08-18 10:42:45+0200, Thomas De Zeeuw <thomas@slight.dev> wrote:
> > Hello,
> > 
> > This is my first bug report to Git mailing list so let me know if more information is needed.
> > 
> > Running the following command results in a segmentation fault on macOS arm64
> > $ git diff --name-only --diff-filter=U —relative
> > Segmentation fault: 11
> 
> MVCE:
> 
> ---- 8< ---
> #!/bin/sh
> 
> rm -rf /tmp/diff-bug
> git init /tmp/diff-bug
> cd /tmp/diff-bug
> mkdir -p dir
> 
> printf '%s\n' one two three >file
> printf '%s\n' inner >dir/file
> git add file dir/file
> git commit -m first
> 
> git branch side
> 
> printf '%s\n' one two >file
> git add file
> git commit -m checkpoint
> git tag checkpoint
> 
> git switch side
> printf '%s\n' two two four >file
> git add file
> git commit -m side
> 
> cd dir
> git rebase checkpoint
> 
> git diff --name-only --relative
> ---- >8 -----
> 
> It's NULL pointer dereference bug because pair is NULL.
> I haven't check further:
> 
> ---- 8< -----
> #0  run_diff_files (revs=revs@entry=0x7ffcc85ae270, option=option@entry=0)
>     at diff-lib.c:196
> 196                                     pair->two->mode = wt_mode;
> ----- >8 -----
This diff could fix the issue, and the test suite still passes:
---- 8< ----
diff --git a/diff-lib.c b/diff-lib.c
index f9eadc4fc1..8f303958dd 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -192,7 +192,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 			 * from the desired stage.
 			 */
 			pair = diff_unmerge(&revs->diffopt, ce->name);
-			if (wt_mode)
+			if (pair && wt_mode)
 				pair->two->mode = wt_mode;
 			if (ce_stage(ce) != diff_unmerged_stage)
 				continue;
---- >8 -----
-- 
Danh
Previous: Đoàn Trần Công DanhNext: Junio C Hamano
Message 3 of 8 in “Bug: Segmentation fault in git diff”
  1. Thomas De ZeeuwAug 18, 2021
  2. Đoàn Trần Công DanhAug 18, 2021
  3. Đoàn Trần Công DanhAug 18, 2021
  4. Junio C HamanoAug 18, 2021
  5. diff-lib: ignore all outsider if --relative askedĐoàn Trần Công Danh, Aug 19, 2021
  6. Carlo ArenasAug 19, 2021
  7. Junio C HamanoAug 19, 2021
  8. Junio C HamanoAug 19, 2021

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.