From 15b158db3ae11cb835f2eb8d2eb48e09d1a4af48 Mon Sep 17 00:00:00 2001
From: Andreas Gruenbacher <agruen@gnu.org>
Date: Mon, 15 Jul 2019 19:10:02 +0200
Subject: Avoid invalid memory access in context format diffs

* src/pch.c (another_hunk): Avoid invalid memory access in context format
diffs.

CVE: CVE-2019-20633
Upstream-Status: Backport [https://git.savannah.gnu.org/cgit/patch.git/patch/?id=15b158db3ae11cb835f2eb8d2eb48e09d1a4af48]
Signed-off-by: Scott Murray <scott.murray@konsulko.com>

---
 src/pch.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/pch.c b/src/pch.c
index a500ad9..cb54e03 100644
--- a/src/pch.c
+++ b/src/pch.c
@@ -1328,6 +1328,7 @@ another_hunk (enum diff difftype, bool rev)
 		  ptrn_prefix_context = context;
 		ptrn_suffix_context = context;
 		if (repl_beginning
+		    || p_end <= 0
 		    || (p_end
 			!= p_ptrn_lines + 1 + (p_Char[p_end - 1] == '\n')))
 		  {
-- 
cgit v1.2.1

