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

Re: [PATCH 1/2] apply: guard against renames of non-existant empty files

From
Philip Oakley <philipoakley@iee.org>
Date
Feb 25, 2017, 11:59 UTC
Message-ID
<E14B054C79E1450F8B41E6477D1D7CD1@PhilipOakley>
In-Reply-To
<20170225101307.24067-1-vegard.nossum@oracle.com>
From: "Vegard Nossum" <vegard.nossum@oracle.com>
> If we have a patch like the one in the new test-case, then we will

"the one in the new test-case" needs a clearer reference to the particular case so that future readers will know what it refers to. Noticed while browsing the commit message..

..reads further; Maybe it's "AFL (American fuzzy lop) found a failure. Add a new test case and fix the fault"?

[same for patch 2]
Show 54 quoted lines
> try to rename a non-existant empty file, i.e. patch->old_name will
> be NULL. In this case, a NULL entry will be added to fn_table, which
> is not allowed (a subsequent binary search will die with a NULL
> pointer dereference).
>
> The patch file is completely bogus as it tries to rename something
> that is known not to exist, so we can throw an error for this.
>
> Found using AFL.
>
> Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
> ---
> apply.c                     |  3 ++-
> t/t4154-apply-git-header.sh | 15 +++++++++++++++
> 2 files changed, 17 insertions(+), 1 deletion(-)
> create mode 100755 t/t4154-apply-git-header.sh
>
> diff --git a/apply.c b/apply.c
> index 0e2caeab9..cbf7cc7f2 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -1585,7 +1585,8 @@ static int find_header(struct apply_state *state,
>  patch->old_name = xstrdup(patch->def_name);
>  patch->new_name = xstrdup(patch->def_name);
>  }
> - if (!patch->is_delete && !patch->new_name) {
> + if ((!patch->is_delete && !patch->new_name) ||
> +     (patch->is_rename && !patch->old_name)) {
>  error(_("git diff header lacks filename information "
>       "(line %d)"), state->linenr);
>  return -128;
> diff --git a/t/t4154-apply-git-header.sh b/t/t4154-apply-git-header.sh
> new file mode 100755
> index 000000000..d651af4a2
> --- /dev/null
> +++ b/t/t4154-apply-git-header.sh
> @@ -0,0 +1,15 @@
> +#!/bin/sh
> +
> +test_description='apply with git/--git headers'
> +
> +. ./test-lib.sh
> +
> +test_expect_success 'apply old mode / rename new' '
> + test_must_fail git apply << EOF
> +diff --git a/1 b/1
> +old mode 0
> +rename new 0
> +EOF
> +'
> +
> +test_done
> -- 
> 2.12.0.rc0

-- Philip

Previous: René ScharfeNext: Vegard Nossum
Message 13 of 19 in “apply: guard against renames of non-existant empty files”
  1. 1/2 apply: guard against renames of non-existant empty filesVegard Nossum, Feb 25, 2017
  2. 2/2 apply: handle assertion failure gracefullyVegard Nossum, Feb 25, 2017
  3. René ScharfeFeb 25, 2017
  4. Junio C HamanoFeb 27, 2017
  5. René ScharfeFeb 27, 2017
  6. Junio C HamanoFeb 27, 2017
  7. René ScharfeFeb 28, 2017
  8. René ScharfeJun 27, 2017
  9. Junio C HamanoJun 27, 2017
  10. René ScharfeJun 27, 2017
  11. Junio C HamanoJun 27, 2017
  12. René ScharfeJun 27, 2017
  13. Philip OakleyFeb 25, 2017
  14. Vegard NossumFeb 25, 2017
  15. Philip OakleyFeb 25, 2017
  16. René ScharfeFeb 25, 2017
  17. Junio C HamanoFeb 27, 2017
  18. René ScharfeFeb 27, 2017
  19. René ScharfeJun 27, 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.