git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/2] Fixes for dl/stash-show-untracked
@ 2021-05-12 20:16 Denton Liu
  2021-05-12 20:16 ` [PATCH 1/2] t3905: correct test title Denton Liu
  2021-05-12 20:16 ` [PATCH 2/2] stash show: fix segfault with --{include,only}-untracked Denton Liu
  0 siblings, 2 replies; 4+ messages in thread
From: Denton Liu @ 2021-05-12 20:16 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano, Eric Sunshine

These follow-up patches for the topic should be merged before the
next release happens. In particular, the last patch fixes a potential
segfault that occurs.

Denton Liu (2):
  t3905: correct test title
  stash show: fix segfault with --{include,only}-untracked

 builtin/stash.c                    |  8 ++++++--
 t/t3905-stash-include-untracked.sh | 17 ++++++++++++++++-
 2 files changed, 22 insertions(+), 3 deletions(-)

-- 
2.31.1.751.gd2f1c929bd


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] t3905: correct test title
  2021-05-12 20:16 [PATCH 0/2] Fixes for dl/stash-show-untracked Denton Liu
@ 2021-05-12 20:16 ` Denton Liu
  2021-05-12 20:16 ` [PATCH 2/2] stash show: fix segfault with --{include,only}-untracked Denton Liu
  1 sibling, 0 replies; 4+ messages in thread
From: Denton Liu @ 2021-05-12 20:16 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano, Eric Sunshine

We reference the non-existent option `git stash show --show-untracked`
when we really meant `--only-untracked`. Correct the test title
accordingly.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3905-stash-include-untracked.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh
index b470db7ef7..2e6796725b 100755
--- a/t/t3905-stash-include-untracked.sh
+++ b/t/t3905-stash-include-untracked.sh
@@ -367,7 +367,7 @@ test_expect_success 'stash show --only-untracked only shows untracked files' '
 	test_cmp expect actual
 '
 
-test_expect_success 'stash show --no-include-untracked cancels --{include,show}-untracked' '
+test_expect_success 'stash show --no-include-untracked cancels --{include,only}-untracked' '
 	git reset --hard &&
 	git clean -xf &&
 	>untracked &&
-- 
2.31.1.751.gd2f1c929bd


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] stash show: fix segfault with --{include,only}-untracked
  2021-05-12 20:16 [PATCH 0/2] Fixes for dl/stash-show-untracked Denton Liu
  2021-05-12 20:16 ` [PATCH 1/2] t3905: correct test title Denton Liu
@ 2021-05-12 20:16 ` Denton Liu
  2021-05-12 23:48   ` Junio C Hamano
  1 sibling, 1 reply; 4+ messages in thread
From: Denton Liu @ 2021-05-12 20:16 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano, Eric Sunshine

When `git stash show --include-untracked` or
`git stash show --only-untracked` is run on a stash that doesn't include
an untracked entry, a segfault occurs. This happens because we do not
check whether the untracked entry is actually present and just attempt
to blindly dereference it.

Ensure that the untracked entry is present before actually attempting to
dereference it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 builtin/stash.c                    |  8 ++++++--
 t/t3905-stash-include-untracked.sh | 15 +++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/builtin/stash.c b/builtin/stash.c
index 8922a1240c..82e4829d44 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -900,10 +900,14 @@ static int show_stash(int argc, const char **argv, const char *prefix)
 		diff_tree_oid(&info.b_commit, &info.w_commit, "", &rev.diffopt);
 		break;
 	case UNTRACKED_ONLY:
-		diff_root_tree_oid(&info.u_tree, "", &rev.diffopt);
+		if (info.has_u)
+			diff_root_tree_oid(&info.u_tree, "", &rev.diffopt);
 		break;
 	case UNTRACKED_INCLUDE:
-		diff_include_untracked(&info, &rev.diffopt);
+		if (info.has_u)
+			diff_include_untracked(&info, &rev.diffopt);
+		else
+			diff_tree_oid(&info.b_commit, &info.w_commit, "", &rev.diffopt);
 		break;
 	}
 	log_tree_diff_flush(&rev);
diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh
index 2e6796725b..1c9765928d 100755
--- a/t/t3905-stash-include-untracked.sh
+++ b/t/t3905-stash-include-untracked.sh
@@ -405,4 +405,19 @@ test_expect_success 'stash show --include-untracked errors on duplicate files' '
 	test_i18ngrep "worktree and untracked commit have duplicate entries: tracked" err
 '
 
+test_expect_success 'stash show --{include,only}-untracked on stashes without untracked entries' '
+	git reset --hard &&
+	git clean -xf &&
+	>tracked &&
+	git add tracked &&
+	git stash &&
+
+	git stash show >expect &&
+	git stash show --include-untracked >actual &&
+	test_cmp expect actual &&
+
+	git stash show --only-untracked >actual &&
+	test_must_be_empty actual
+'
+
 test_done
-- 
2.31.1.751.gd2f1c929bd


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] stash show: fix segfault with --{include,only}-untracked
  2021-05-12 20:16 ` [PATCH 2/2] stash show: fix segfault with --{include,only}-untracked Denton Liu
@ 2021-05-12 23:48   ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2021-05-12 23:48 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine

Denton Liu <liu.denton@gmail.com> writes:

> When `git stash show --include-untracked` or
> `git stash show --only-untracked` is run on a stash that doesn't include
> an untracked entry, a segfault occurs. This happens because we do not
> check whether the untracked entry is actually present and just attempt
> to blindly dereference it.
>
> Ensure that the untracked entry is present before actually attempting to
> dereference it.

Makes sense.  Thanks.

>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
>  builtin/stash.c                    |  8 ++++++--
>  t/t3905-stash-include-untracked.sh | 15 +++++++++++++++
>  2 files changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/stash.c b/builtin/stash.c
> index 8922a1240c..82e4829d44 100644
> --- a/builtin/stash.c
> +++ b/builtin/stash.c
> @@ -900,10 +900,14 @@ static int show_stash(int argc, const char **argv, const char *prefix)
>  		diff_tree_oid(&info.b_commit, &info.w_commit, "", &rev.diffopt);
>  		break;
>  	case UNTRACKED_ONLY:
> -		diff_root_tree_oid(&info.u_tree, "", &rev.diffopt);
> +		if (info.has_u)
> +			diff_root_tree_oid(&info.u_tree, "", &rev.diffopt);
>  		break;
>  	case UNTRACKED_INCLUDE:
> -		diff_include_untracked(&info, &rev.diffopt);
> +		if (info.has_u)
> +			diff_include_untracked(&info, &rev.diffopt);
> +		else
> +			diff_tree_oid(&info.b_commit, &info.w_commit, "", &rev.diffopt);
>  		break;
>  	}
>  	log_tree_diff_flush(&rev);
> diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh
> index 2e6796725b..1c9765928d 100755
> --- a/t/t3905-stash-include-untracked.sh
> +++ b/t/t3905-stash-include-untracked.sh
> @@ -405,4 +405,19 @@ test_expect_success 'stash show --include-untracked errors on duplicate files' '
>  	test_i18ngrep "worktree and untracked commit have duplicate entries: tracked" err
>  '
>  
> +test_expect_success 'stash show --{include,only}-untracked on stashes without untracked entries' '
> +	git reset --hard &&
> +	git clean -xf &&
> +	>tracked &&
> +	git add tracked &&
> +	git stash &&
> +
> +	git stash show >expect &&
> +	git stash show --include-untracked >actual &&
> +	test_cmp expect actual &&
> +
> +	git stash show --only-untracked >actual &&
> +	test_must_be_empty actual
> +'
> +
>  test_done

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-12 23:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12 20:16 [PATCH 0/2] Fixes for dl/stash-show-untracked Denton Liu
2021-05-12 20:16 ` [PATCH 1/2] t3905: correct test title Denton Liu
2021-05-12 20:16 ` [PATCH 2/2] stash show: fix segfault with --{include,only}-untracked Denton Liu
2021-05-12 23:48   ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).