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

Re: [PATCH 2/2] apply: handle assertion failure gracefully

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 27, 2017, 18:08 UTC
Message-ID
<xmqqshil1ex1.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<5128cdf1-39fc-59ca-5640-801777bac2fa@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 38 quoted lines
> Thought a bit more about it, and as a result here's a simpler approach:
>
> -- >8 --
> Subject: [PATCH] apply: check git diffs for mutually exclusive header lines
>
> A file can either be added, removed, copied, or renamed, but no two of
> these actions can be done by the same patch.  Some of these combinations
> provoke error messages due to missing file names, and some are only
> caught by an assertion.  Check git patches already as they are parsed
> and report conflicting lines on sight.
>
> Found by Vegard Nossum using AFL.
>
> Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
>  apply.c                | 14 ++++++++++++++
>  apply.h                |  1 +
>  t/t4136-apply-check.sh | 18 ++++++++++++++++++
>  3 files changed, 33 insertions(+)
>
> diff --git a/apply.c b/apply.c
> index 8cd6435c74..8a5e44c474 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -1312,6 +1312,18 @@ static char *git_header_name(struct apply_state *state,
>  	}
>  }
>  
> +static int check_header_line(struct apply_state *state, struct patch *patch)
> +{
> +	int extensions = (patch->is_delete == 1) + (patch->is_new == 1) +
> +			 (patch->is_rename == 1) + (patch->is_copy == 1);
> +	if (extensions > 1)
> +		return error(_("inconsistent header lines %d and %d"),
> +			     state->extension_linenr, state->linenr);
> +	if (extensions && !state->extension_linenr)
> +		state->extension_linenr = state->linenr;

OK. I wondered briefly what happens if the first git_header that sets one of the extensions can be at line 0 (calusng state->extension_linenr to be set to 0), but even in that case, the second problematic one will correctly report the 0th and its own line as culprit, so this is OK. It makes me question if there is any point checking !state->extension_linenr in the if() statement, though.

Previous: René ScharfeNext: René Scharfe
Message 9 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.