2018-02-03  Andreas Gruenbacher  <agruen@gnu.org>

	Version 2.7.6
	* NEWS: Update.

	Fix typo in README
	* README: Fix typo.

	Switch to gnupload module
	* bootstrap.conf: use gnupload module.
	* (RELEASE_TYPE): Define, as maint.mk expects it to be defined.
	(tell-upload): Remove obsolete target.

	Remove stale reference to m4/utimbuf.m4
	* Makefile.am (EXTRA_DIST): Remove stale reference to m4/utimbuf.m4.

	maint: update bootstrap and gnulib submodule
	* bootstrap: Update from gnulib.

2018-01-23  Andreas Gruenbacher  <agruen@gnu.org>

	Clarify the error messages for malformed normal diff patches
	* src/pch.c (another_hunk): Clarify the error messages for malformed
	normal diff patches.

2018-01-23  Thomas Orgis  <thomas@orgis.org>

	Create git diff files with indicated mode
	* src/patch.c (main): Create git diff files with indicated mode.
	* tests/file-create-modes: New test case.
	* tests/Makefile.am (TESTS): Add test case.

	This fixes building current Linux 4.14.x from the signed tarball and
	patch file, where the patch creates a script with the executable bit
	set.

2018-01-23  Andreas Gruenbacher  <agruen@gnu.org>

	gnulib: update to latest

2018-01-23  Bruno Haible  <bruno@clisp.org>

	Don't use an undocumented Autoconf macro
	* configure.ac: Use AC_CONFIG_HEADERS instead of AC_CONFIG_HEADER.

2017-09-06  Andreas Gruenbacher  <agruen@gnu.org>

	Don't allow hunks to overlap
	* src/patch.c (locate_hunk): Don't allow a hunk to overlap with the
	previous one.
	* tests/false-match: Add regression test.

	patch.man: Clarify --forward description

2017-09-04  Andreas Gruenbacher  <agruen@gnu.org>

	gnulib: update to latest

2017-02-22  Tim Waugh  <twaugh@redhat.com>

	Rename canonicalize global variable
	* src/common.h, src/merge.c (context_matches_file), src/patch.c
	(get_some_switches, patch_match), src/pch.c(another_hunk): Rename the
	global variable 'canonicalize' to 'canonicalize_ws'.

	Patch uses a global variable 'canonicalize' as part of its
	implementation of the --ignore-whitespace flag.

	In glibc there is a function canonicalize():
	https://www.gnu.org/software/libc/manual/html_node/FP-Bit-Twiddling.html#index-canonicalize

	Rename the global variable so that it will not conflict.

	Original bug report:
	https://bugzilla.redhat.com/show_bug.cgi?id=1422463

2016-08-10  Hanno Boeck  <hanno@gentoo.org>

	Add a missing NULL check in parse_name
	* src/util.c (parse_name): parse_c_string() can fail and return NULL.
	Check for that so that we won't access the NULL pointer here.

	Fix out-of-bounds access to lines in a patch
	This bug can trigger with malformed patches.
	* src/pch.c (pch_write_line): Avoid out-of-bounds access to
	p_line[line][p_len[line] - 1] when p_len[line] is 0.

2016-07-31  Jim Meyering  <meyering@fb.com>

	tests: use $PATCH rather than hard-coded path
	* tests/git-cleanup: Don't hard-code program name.

	maint: placate a "make syntax-check" rule
	* src/pch.c (set_hunkmax): Don't cast return value of xmalloc.
	(grow_hunkmax): Likewise for two uses of realloc that the syntax-check
	rule did not detect.

2016-07-31  Jim Meyering  <meyering@fb.com>

	maint: avoid new warning-errors from gcc-6.1
	When configured with --enable-gcc-warnings and gcc-6.1, ...
	* src/safe.c (count_path_components): Use _GL_ATTRIBUTE_PURE,
	to avoid an error from -Werror=suggest-attribute=pure.
	* src/util.h (filename_is_safe): Likewise.
	* src/patch.c (main): Placate -Werror=format= by casting
	pch_mode's mode_t return type to the "unsigned int" required
	to match the %o format string.
	* src/patch.c (delete_files): Correct indentation, to avoid
	this error from -Werror=misleading-indentation:

	  patch.c: In function 'delete_files':
	  patch.c:1816:4: error: this 'if' clause does not guard...
	      if (verbosity == VERBOSE)
	      ^~
	  patch.c:1820:6: note: ...this statement, but the latter is
	    misleadingly indented as if it is guarded by the 'if'
		move_file (0, 0, 0, file_to_delete->name, mode,
		^~~~~~~~~

2016-07-31  Jim Meyering  <meyering@fb.com>

	gnulib: update to latest

2016-07-27  Andreas Gruenbacher  <agruen@gnu.org>

	Fix broken git-style patch behavior
	When a git-syle patch is applied, all file modifications are done to
	temporary files which are put in place when the patch ends.  When a
	patch fails, GNU patch was trying to "roll back" to the start.  A bug in
	that code that lead to accidental file deletion was recently discovered
	by Richard Weinberger <richard@nod.at>.  Even worse though, GNU patch
	should not exhibit this "rollback" behavior in the first place; that's
	not what people expect. Instead, the files modified so far should be put
	in place.
	* src/patch.c (cleanup): Put output files processed successfully
	in place instead of trying to "roll back" to the start.
	(forget_output_files): Remove obsolete (and broken) function.
	* tests/git-cleanup: New broken git-style patch test case that exercises
	the cleanup path.
	* tests/Makefile.am (TESTS): Add new test case.

	Fix inname test case
	* src/safe.h (unsafe): New flag to allow turning off safe file
	operations.
	* src/safe.c (safe_xstat, safe_open, safe_rename, safe_mkdir,
	safe_rmdir, safe_unlink, safe_symlink, safe_chmod, safe_lchown,
	safe_lutimens, safe_readlink, safe_access): When safe file operations
	are turned off, skip safe path traversal.  Any symlink checks of the
	last path component are still done though.
	* src/patch.c (main): When the file to patch is specified on the command
	line, turn off safe file operations.
	* tests/inname: Fix typo in test.

	Add context-format test to XFAIL_TESTS for now
	* tests/Makefile.am (XFAIL_TESTS): Add context-format test until someone
	gets to fixing it.

2016-03-18  Andreas Gruenbacher  <agruen@gnu.org>

	Add broken context-format test cases
	* tests/context-format: Add context-format test cases from
	Mattias Andrée <maandree@member.fsf.org> that patch doesn't parse
	correctly.

2015-10-03  Andreas Gruenbacher  <agruen@gnu.org>

	Don't use a zero-size array in struct symlink
	* src/safe.c (struct symlink): Get rid of the zero-size array which is a gcc
	extension.
	(read_symlink): Adapt to this struct symlink change.

2015-07-20  Andreas Gruenbacher  <agruen@gnu.org>

	Input file outside current directory: add test case
	Patch currently makes sure that input / output files are inside the current
	working directory even when the input files are explicitly specified on the
	command line (see http://savannah.gnu.org/bugs/?45581).
	* tests/inname: Add a test case for this bug.

2015-07-12  Tobias Stoeckmann  <tobias@stoeckmann.org>

	Terminate readlink string
	The function readlink does not nul terminate its result string.  safe_readlink
	is a wrapper for readlinkat, which has the same behaviour.
	* src/util.c (copy_file): Therefore, explicitly set '\0' and reserve one byte
	for it.  (agruen: Reserve PATH_MAX + 1 bytes instead of only reading PATH_MAX -
	1 characters.)

2015-07-08  Tobias Stoeckmann  <tobias@stoeckmann.org>

	Use xmalloc in bestmatch
	* src/bestmatch.h (bestmatch): Use xmalloc instead of malloc to handle
	out-of-memory situations.

2015-03-09  Andreas Gruenbacher  <agruen@gnu.org>

	Don't require traditional patch header after "git --diff"
	Reported by Tim Waugh <twaugh@redhat.com>.
	* src/pch.c (intuit_diff_type): Don't require a traditional patch header
	("--- old\n+++ new/n") after a "git --diff" header; the "git --diff" header
	gives us enough information for being able to process subsequent hunks.  This
	deals with corrupted patches more gracefully.
	* tests/corrupt-patch: New test case.
	* tests/Makefile.am (TESTS): Add test case.

2015-03-08  Andreas Gruenbacher  <agruen@gnu.org>

	Use gnulib size_max module
	* bootstrap.conf (gnulib_modules): Add size_max.
	* configure.ac: Call gl_SIZE_MAX.

2015-03-07  Andreas Gruenbacher  <agruen@gnu.org>

	Version 2.7.5
	* NEWS: Update.

	build: update gnulib submodule to latest

	Allow absolute symlinks that lead back into the working directory
	* src/safe.c (cwd_stat_errno, cwd_stat): stat() result of ".".
	(read_symlink): When a symlink is absolute, check if it leads back into the
	working directory.  If it does, strip off the prefix above the working
	directory. If the symlink points to the working directory, return an empty
	path.
	(traverse_another_path): Recognize empty paths from read_symlink().
	* tests/symlinks: Absolute symlink test cases.

2015-03-05  Andreas Gruenbacher  <agruen@gnu.org>

	Describe better how the dirfd cache works

	Use overflow safe arithmetic for counting cache misses
	* src/safe.c: We don't need a long counter if we use overflow-safe arithmetic
	here.

	Also cache resolved symlinks
	When resolving a symlink in a pathname, we traverse each path component in the
	symlink and cache all of them.  At the end, add an additional cache entry for
	the symlink itself so that we don't have to resolve the symlink again (even
	though this will usually be cached).  Skip that if the symlink's parent isn't
	in the cache anymore, though.
	* src/safe.c (free_cached_dirfd): Remove from parent here instead of in
	callers. Move close() to remove_cached_dirfd() instead.
	(insert_cached_dirfd): Only insert if the entry's parent still exists; entries
	without parent are invalid (see compare_cached_dirfds()); "top-level" entries
	have cwd as their parent.
	(new_cached_dirfd): New function split off from openat_cached().
	(openat_cached): Use new_cached_dirfd() here.
	(traverse_another_path): When starting to resolve a symlink, create an unhashed
	dirfd cache entry for the symlink lookup result. When the symlink is completely
	resolved, add that entry to the cache.

	Invalidate child dirfd cache entries when their parent goes away
	If we don't do that, a directory could be removed from the cache, a new
	directory with the same dirfd could be created, and the entries from the old
	directory would appear in the new directory.
	* src/safe.c (struct cached_dirfd): Keep track of the children of each dirfd
	cache entry.
	(remove_cached_dirfd): Remove all the entry's children from the lookup hash,
	take them off the list of children, and initialize the children's
	children_link.  Then, remove the entry itself from its parent. This has no
	effect if the entry doesn't have a parent because then, children_link is empty.
	(openat_cached): Add new dirfd cache entries to their parent's list of children
	and initialize the entry's list of children.
	(traverse_another_path): Also initialize cwd's list of children.

	Convert lru list into a list_head list
	* src/safe.c (struct cached_dirfd): Replace prev and next with a lru_link
	list_head.
	(lru_list): Turn into a list_head.
	(lru_list_add, lru_list_del, lru_list_del_init): Replace by list_add(),
	list_del(), list_del_init().
	(insert_cached_dirfd): Get to the list entry from the embedded list_head with
	the list_entry() macro.

	Add list_head based double linked list
	* src/list.h: New data structure.
	src/Makefile.am (patch_SOURCES): Add list.h.

	Invalidate dirfd less aggressively
	src/safe.c (safe_rename, safe_rmdir): Only invalidate cache entries when the
	underlying sycall succeeds and the entry actually goes away.  This keeps the
	cache filled upon speculative rmdir when the directory may not be empty, for
	example.

2015-03-05  Tim Waugh  <twaugh@redhat.com>

	Add more path traversal test cases
	* tests/symlinks: Add more path traversal test cases.

2015-03-05  Andreas Gruenbacher  <agruen@gnu.org>

	Move path traversal error reporting into main()
	* src/safe.c (traverse_another_path): Don't report errors here.
	* src/patch.c (main): Instead, recognize and report them here. Detect when an
	output file name is invalid; it doesn't make sense to try creating a
	reject file based on the same outbut file name in that case.

	Limit the number of path components
	src/safe.c (MAX_PATH_COMPONENTS): The maximum number of path components
	allowed.
	(count_path_components): New function.
	(traverse_another_path): Fail if the number of path components gets too high.

	Follow directory symlinks within the working directory
	* src/safe.c (struct symlink): A symlink to resolve.
	(push_symlink, pop_symlink): New functions.
	(read_symlink): Create a new symlink stack entry.
	(traverse_next): Follow ".." components within the working directory. When
	hitting symlinks, "follow" them by reading and returning them.
	(traverse_another_path): Recursively traverse symlinks.

	Keep track of the directory hierarchy
	* src/safe.c (struct cached_dirfd): Add parent pointer. Now that we know our
	parent, we no longer need to duplicate its directory file descriptor.
	(lookup_cached_dirfd): Don't update the lru list here.
	(insert_cached_dirfd): The lru list may now be empty even if the cache is not.
	(put_path): New function to put a path back into the lru list.
	(openat_cached): Take cached entried off the lru list.  They are added back
	in put_path().
	(traverse_another_path): Put lookup result back into the lru list with
	put_path().

2015-02-28  Andreas Gruenbacher  <agruen@gnu.org>

	Refactor traverse_another_path() and helpers
	Prepare for keeping track of the directory hierarchy:
	* src/safe.c (traverse_another_path): Pass struct cached_dirfd to
	traverse_next().
	(traverse_next, openat_cached): Pass through struct cached_dirfd.

	Move error reporting out of make_tempfile()
	* src/util.c (make_tempfile): Remove error reporting here.
	* src/inp.c (plan_b): Readd error reporting here.
	* src/patch.c (main): Likewise.
	* src/pch.c (open_patch_file): Likewise.

	Minor cosmetic changes
	* src/safe.c: Minor cosmetic changes

2015-02-22  Andreas Gruenbacher  <agruen@gnu.org>

	Fix handling of renamed files
	When a file has already been renamed, make sure it is not renamed back to its
	old name.  Reported by Guido Draheim.
	* src/patch.c (main): Make sure we never rename a file back to its previous
	name. Report when a file was renamed already.
	* tests/copy-rename: Add "already renamed" test cases.

2015-02-10  Andreas Gruenbacher  <agruen@gnu.org>

	Fix symlinks test case on some architectures
	* src/safe.c: Include util.h for say(). Define EFTYPE if it isn't defined
	already.
	(traverse_another_path): When openat fails, also check for EMLINK, EFTYPE, and
	ENOTDIR. Change the error message to "file ... is not a directory" and only
	skip the rest of the patch instead of aborting.
	* tests/symlinks: Update.

2015-02-04  Andreas Gruenbacher  <agruen@gnu.org>

	Test suite portability fixes
	Reported and fixed (mostly) by Christian Weisgerber <naddy@mips.inka.de>:
	* tests/deep-directories: Avoid the bash >& redirection operator.
	* tests/no-mode-change-git-diff: Instead of "stat -c", use "ls -l  sed".
	* tests/read-only-files: A redirection failure for a special built-in causes
	some shells (FreeBSD sh, OpenBSD sh (pdksh), some bash --posix) to exit, and
	the colon command is a special built-in. Perform the redirection in a subshell.

	Switch from gen_tempname() to try_tempname()
	* Update gnulib submodule to latest.
	* src/util.c (try_safe_open_args, try_safe_open): Arguments and callback for
	try_tempname().
	(make_tempfile): Switch from gen_tempname() to try_tempname().

2015-02-02  Andreas Gruenbacher  <agruen@gnu.org>

	Check the result of the --follow-symlinks option
	* tests/symlinks: Check the result of treating a symlink as a file with
	--follow-symlinks.

2015-02-01  Andreas Gruenbacher  <agruen@gnu.org>

	Link patch with LIB_EACCESS where needed
	* src/Makefile.am (patch_LDADD): Add LIB_EACCESS here. At least on Solaris,
	faccessat() is implemented through eaccess() which is in the "gen" library.

	Fix minor signedness warning
	* src/pch.c (intuit_diff_type): Don't assign signed dummy value to unsigned
	variable.

	Use gnulib faccessat module
	* bootstrap.conf (gnulib_modules): Add faccessat.

2015-01-31  Andreas Gruenbacher  <agruen@gnu.org>

	Upate NEWS

	Fix indentation heuristic for context diffs
	Diffs can be indented by a variable number of spaces, tabs, or X characters.
	Make sure that intuit_diff_type() only accepts context diffs where the first
	and second line are indented identically, or else another_hunk() will fail.
	* src/pch.c (intuit_diff_type): Remember the indentation of the last line. Only
	recognize context diff hunks with the same amount of indentation on the first
	and second line.
	* tests/garbage: New test case.
	* tests/Makefile.am (TESTS): Add test case.

2015-01-31  Quentin Casasnovas  <quentin.casasnovas@oracle.com>

	patch: git-diff mode: do not change permissions if there isn't an explicit mode change.

	tests: add a test case for unwanted mode changes.

	test-lib.sh: factorize require_* functions
	Since the code is identical when just checking if a utility is present on
	the system or not, we can factorize it.

2015-01-31  Andreas Gruenbacher  <agruen@gnu.org>

	Add test case for patch behind symlink
	* tests/symlinks: Add a test case where the patch file itself is in a path that
	follows a symbolic link; we want to continue allowing that.

2015-01-31  Tim Waugh  <twaugh@redhat.com>

	Allow arbitrary symlink targets again
	* src/util.c (symlink_target_is_valid): Remove.
	(move_file): Remove symlink target checking.
	* tests/symlinks: Update test case.

2015-01-31  Andreas Gruenbacher  <agruen@gnu.org>

	Update list of gnulib modules used
	* bootstrap.conf (gnulib_modules): Remove lchmod, lstat, mkdir, readlink,
	rename, mkdir, symlink, unlink, utimens. Add fchownat, fchmodat, fstatat,
	mkdirat, openat, readlinkat, renameat, symlinkat, unlinkat, utimensat.
	* src/util.h: Don't include <utimens.h> anymore.

	Use symlink-safe system call replacements
	Use the symlink-safe replacements for system calls in many places throughout
	the code: In some places this makes patch safe against path traversal attacks;
	in other places, it saves the kernel from having to re-traverse the pathnames.
	* src/inp.c (plan_b): Use safe_open() + fdopen() instead of fopen().
	* src/util.c (copy_attr): Document why we are safe here.
	(create_backup): Use safe_open() instead of creat().

2015-01-31  Tim Waugh  <twaugh@redhat.com>

	Add symlink-safe system call replacements
	Add wrappers around system calls that traverse relative pathnames without
	following symlinks. Written by Tim Waugh <twaugh@redhat.com> and Andreas
	Gruenbacher <agruenba@redhat.com>.
	* src/safe.h: Declare functions here.
	* src/safe.c: Implement safe_* system call replacements that do not follow
	symlinks along pathnames. Pathname components are resolved with openat().
	Lookup results are cached to keep the overhead reasonably low.
	* tests/deep-directories: New path traversal cache test.
	* src/Makefile.am (patch_SOURCES): Add safe.[ch].
	* tests/Makefile.am (TESTS): Add new test.

2015-01-31  Andreas Gruenbacher  <agruen@gnu.org>

	build: update gnulib submodule to latest

2015-01-31  Tim Waugh  <twaugh@redhat.com>

	Avoid closing file descriptor twice
	* src/patch.c (main): Make sure we don't close() outfd after passing it on to
	fdopen(): the file descriptor might have been reused in the meantime.

2015-01-29  Andreas Gruenbacher  <agruen@gnu.org>

	Remove unused variable
	* src/pch.c (name_is_valid): Remove unused variable.

2015-01-22  Andreas Gruenbacher  <agruen@gnu.org>

	Fix the fix for CVE-2015-1196
	* src/util.c (filename_is_safe): New function split off from name_is_valid().
	(symlink_target_is_valid): Explain why we cannot have absolute symlinks or
	symlinks with ".." components for now.
	(move_file): Move absolute filename check here and explain.
	* tests/symlinks: Put test case with ".." symlink in comments for now.
	* NEWS: Add CVE number.

2015-01-21  Andreas Gruenbacher  <agruen@gnu.org>

	For renames and copies, make sure that both file names are valid
	* src/patch.c (main): Allow there_is_another_patch() to set the
	skip_rest_of_patch flag.
	* src/pch.c (intuit_diff_type): For renames and copies, also check the "other"
	file name.
	(pch_copy, pch_rename): Now that both names are checked in intuit_diff_type(),
	we know they are defined here.

2015-01-20  Andreas Gruenbacher  <agruen@gnu.org>

	Fail when out of memory in set_hunkmax()
	src/pch.c (another_hunk): Call set_hunkmax() from here to make sure it is
	called even when falling back from plan A to plan B.
	(open_patch_file): No need to call set_hunkmax() anymore.
	src/pch.c (set_hunkmax): Fail when out of memory. Make static.
	src/pch.h: Remove set_hunkmax() prototype.

	Don't try applying hunks at offsets that can't work
	* src/patch.c (locate_hunk): Start trying to apply the hunk at the minimum
	offset which puts the hunk in the valid range of lines. This will often still
	be offset 0.

2015-01-20  Andreas Gruenbacher  <andreas.gruenbacher@gmail.com>

	Move symlink_target_is_valid() and cwd_is_root()
	* src/util.c: Move symlink_target_is_valid() and cwd_is_root() here from
	src/pch.c.

2015-01-19  Andreas Gruenbacher  <andreas.gruenbacher@gmail.com>

	Make sure symlinks don't point outside working directory (CVE-2015-119)
	When creating symlinks from git-style patches, make sure the symlinks don't
	point above the current working directory.  Otherwise, a subsequent patch could
	use the symlink to write outside the working directory.

	* src/pch.c (symlink_target_is_valid): New function to check for valid symlink
	targets.
	* src/util.c (move_file): Use symlink_target_is_valid() here.
	* tests/symlinks: Add valid and invalid symlink test cases.

2014-11-30  Andreas Gruenbacher  <agruen@linbit.com>

	Add line number overflow checking
	* bootstrap.conf: use intprops module.
	* src/common.h: Define LINENUM_MIN and LINENUM_MAX macros.
	* src/pch.c (another_hunk): Add line number overflow checking.  Based on Robert
	C. Seacord's INT32-C document for integer overflow checking and Tobias
	Stoeckmann's "integer overflows and oob memory access" patch for FreeBSD.

2014-11-30  Andreas Gruenbacher  <agruen@linbit.com>

	More savebuf/savestr error handling
	* bootstrap.conf: use xmemdup0 module.
	* src/pch.c (there_is_another_patch): Use xmemdup0 instead of savebuf when we
	cannot recover from out-of-memory situations.
	(intuit_diff_type): Likewise, use xstrdup instead of savestr.
	(another_hunk): Handle the case when savestr returns NULL.
	* src/util.c (fetchname, parse_name): Use xmemdup0 instead of savebuf when we
	cannot recover from out-of-memory situations.

	Bugs pointed out by Tobias Stoeckmann <tobias@stoeckmann.org>.

2014-11-30  Tobias Stoeckmann  <tobias@stoeckmann.org>

	savebuf/savestr error handling
	* src/patch.c (get_some_switches): The function savebuf (and therefore savestr)
	copies strings using malloc.  If malloc fails, NULL is returned.  This is
	intentional behavior so that in case of failure during "plan a" patching, "plan
	b" can step in.  The return value has to be properly checked for NULL.  If the
	return value must not be NULL, use xstrdup instead.

2014-11-30  Andreas Gruenbacher  <andreas.gruenbacher@gmail.com>

	build: update gnulib submodule to latest
	* src/merge.c (compute_changes): The TOO_EXPENSIVE heuristic in diffseq has
	been removed, including compareseq's find_minimal parameter and the context's
	too_expensive limit.  Adjust.

2014-11-10  Jean Delvare  <jdelvare@suse.de>

	Drop useless test in another_hunk()
	src/pch.c (another_hunk): This test will always succeed.

2014-10-30  Tobias Stoeckmann  <tobias@stoeckmann.org>

	Buffer overflow on malicious input file
	There is a hard to reach but possible buffer overflow when using
	patch with a very large (modified) input file.  I doubt you will ever
	see this with a 64 bit system, but it's possible with 32 bit:

	$ echo hello > file1
	$ echo world > file2
	$ diff -Nau file1 file2 > file.diff

	Nothing fancy so far.  Adjust file1 so it contains at least one line that
	is 2 GB in size.  Larger is fine too, but stay below 4 GB.

	$ tr '\0' c < /dev/zero | dd bs=1K count=2097152 of=file1

	Now try to patch it.

	$ patch -Np0 -i file.diff
	Segmentation fault

	The issue is in patch's "plan b" strategy  (If your system would still
	want to use "plan a", force patch to use "plan b" through debug flag).

	Plan b writes lines into a temporary file, with equally long lines, so
	it can use a buffer mechanism to access them in a kind of randomly
	fassion.  In order to do that, it retrieves the longest line.

	In this example, it will encounter the 2 GB line and stores that as the
	longest one.  Afterwards it will adjust the tibufsize variable to be
	large enough:

	  for (tibufsize = TIBUFSIZE_MINIMUM;  tibufsize < maxlen;  tibufsize <<= 1)
	    /* do nothing */ ;

	Due to maxlen's size (2 GB), tibufsize will be SIZE_T_MAX, i.e. 4 GB.
	A few lines later it allocates space for the tibuf buffers:

	  tibuf[0] = xmalloc (2 * tibufsize);
	  tibuf[1] = tibuf[0] + tibufsize;

	This will allocate 0 bytes because tibufsize overflowed.  The next
	time patch writes into the buffer, a segmentation fault will occur...
	Depends on your system how long it takes until that happens. ;)

	The fix is simple:  Bail out on lines that are too long.  Patch already
	does that for files that have too many lines.

2014-08-13  Andreas Gruenbacher  <agruen@linbit.com>

	Improve error message when refusing to delete file
	* src/patch.c: Improve error message.
	* tests/create-delete: Update the test case.

2013-12-09  Andreas Gruenbacher  <agruen@linbit.com>

	Correct the --help text of option --merge
	* src/patch.c (option_help): The --merge option does not have a short
	form; update the help text.

2013-08-19  Steven Rostedt  <rostedt@goodmis.org>

	Preserve function names in reject files
	* src/patch.c (main): Preserve function names in reject files.
	* tests/reject-format: Update the test case.

2013-07-30  Andreas Gruenbacher  <agruen@linbit.com>

	Test case for the dry-run fix
	* tests/create-directory: Add test case here.

	In dry-run mode, create temporary files in a temporary directory
	* src/util.c (make_tempfile): Do not create temporary files in the final output
	directory when in dry-run mode: the path may be read-only.  In addition, we do
	not want to leave intermediary empty output directories around.

2013-06-18  Eric S. Raymond  <esr@thyrsus.com>

	Fix some formatting problems in the manpage
	* patch.1: Use higher-level markup that translates better into HTML and other
	formats.  (With changes by Andreas Gruenbacher.)

2013-05-02  Stefano Lattarini  <stefano.lattarini@gmail.com>  (tiny change)

	build: don't use -Werror in AM_INIT_AUTOMAKE
	Doing so prevents bootstrapping with bleeding-edge autotools,
	because of harmless deprecation warnings (that are not planned
	to become hard errors for at least a few years to come).  And
	unfortunately, options in AM_INIT_AUTOMAKE take precedence over
	those given on the command line (this is a long-time wart of
	automake).

	* configure.ac (AM_INIT_AUTOMAKE): Drop '-Werror' option.

2013-03-10  Andreas Gruenbacher  <agruen@linbit.com>

	Fix removing empty directories
	Reported by Thomas Moschny <thomas.moschny@gmx.de>:
	src/patch.c (main): Temporary output files are created in the same directory as
	the output file.  Make sure to remove them before removing empty files and
	their empty ancestor directories; else the directories won't be empty.
	tests/remove-directories: Add directory removal test case.
	tests/Makefile.am (TESTS): Add new test case.

2013-01-03  Andreas Gruenbacher  <agruen@linbit.com>

	Clarify the description of option --forward
	* patch.man: Clarify the description of option --forward.

2012-10-04  Andreas Gruenbacher  <agruen@linbit.com>

	Initialize data structures early enough
	* src/patch.c (main): Initialize data structures early enough, before error
	paths can access them.
	* tests/bad-usage: Test bad command line usage.
	* tests/Makefile.am (TESTS): Add bad-usage here.

2012-09-30  Andreas Gruenbacher  <agruen@linbit.com>

	Don't fail test suite if printf '\0' is broken
	* tests/create-delete: Skip binary diff test if printf '\0' is broken.

2012-09-28  Andreas Gruenbacher  <agruen@linbit.com>

	Version 2.7.1

	build: update gnulib submodule to latest

	Repair 'backup of unmodified file' test
	tests/create-delete: Repair 'backup of unmodified file' test.

	Use gnulib errno module instead of our own default ENOTSUP fallback
	* bootstrap.conf (gnulib_modules): Add errno module.
	* src/common.h: Remove ENOTSUP fallback.

	Trailing whitespace fix
	* NEWS: Trailing whitespace fix.

2012-09-26  Andreas Gruenbacher  <agruen@linbit.com>

	Improve the previous commit
	* src/patch.c: Only print the "file is not empty after patch" message when
	trying to delete the output file.  Say that we were trying to delete the file.
	* tests/create-delete: Fix the expected messages.  Add test cases for the
	--remove-empty-files and --posix options.
	* NEWS: Better describe this change.

2012-09-25  Andreas Gruenbacher  <agruen@linbit.com>

	Only expect files to become empty if the patch says so
	Test cases based on patches from Dmitry V. Levin <ldv@altlinux.org>.
	* src/patch.c (main): Only expect files to become empty if the patch says so.
	* NEWS: Document this change.
	* tests/create-delete: Add (more) empty vs. non-empty test cases.

2012-09-22  Jim Meyering  <meyering@redhat.com>

	build: avoid gcc warnings from -Wsuggest-attribute=format
	* configure.ac (WARN_CFLAGS): Disable -Wsuggest-attribute=format,
	to avoid some warnings that are not worth working around.

2012-09-22  Andreas Gruenbacher  <agruen@linbit.com>

	Update NEWS
	* NEWS: Update.

	Improve messages when in --dry-run mode
	* src/patch.c (main): Say that we are checking a file and not that we are
	patching it in --dry-run mode.  Don't say "saving rejects to file" when we
	don't create reject files.
	* tests/reject-format: Add rejects with --dry-run test case.
	* tests/bad-filenames, tests/fifo, tests/mixed-patch-types: Update.

	Improve handling of LF vs. CRLF line endings
	* src/patch.c (check_line_endings): New function.
	(main): When a hunk fails, report when the line endings differ between the
	input file and the patch.
	* src/pch.c (there_is_another_patch): When saying that we strip trailing CRs,
	also say how to turn this off.
	* tests/crlf-handling: Update changed messages.  Add test case that fails.

	Ignore when preserving extended attributes is not supported or allowed
	* src/common.h (ENOTSUP): Make sure this error code is defined.
	* src/util.c (set_file_attributes): Ignore ENOSYS, ENOTSUP, and EPERM errors.

2012-09-20  Andreas Gruenbacher  <agruen@linbit.com>

	Add a missing explanation in the tests/crlf-handling test case
	* tests/crlf-handling: Add explanation.

2012-09-19  Andreas Gruenbacher  <agruen@linbit.com>

	Add --follow-symlinks option for backwards compatibility
	* src/common.h (follow_symlinks): New variable.
	* src/patch.c (longopts): Add new --follow-symlinks option.
	(get_some_switches): Recognize the new option.
	* src/util.c (stat_file): Follow symlinks if requested.
	* patch.man: Document the new option.
	* tests/symlinks: Add test case.

	Introduce function to lstat all input files
	* src/util.c (stat_file): New function.
	(move_file): Use here.
	* src/util.h (stat_file): Declare here.
	* src/inp.c (get_input_file): Use here.
	* src/patch.c (main): Use here.
	(delete_file_later): Use here.
	* src/pch.c (there_is_another_patch): Use here.
	(intuit_diff_type): Use here.

	Use stat where we want to follow symlinks
	* src/pch.c (prefix_components): Follow symlinks.
	(cwd_is_root): Follow symlinks.

	Document command-line options in alphabetic order
	* patch.man: The options are mostly listen in alphabetical order; stick to
	that.

2012-09-18  Andreas Gruenbacher  <agruen@linbit.com>

	Fix file truncation when switching from git diff to non-git diff
	* src/patch.c (main): Output queued output files only when switching from a git
	diff to a non-git diff.  This can modify the input file, so make sure to
	stat() it again.
	* tests/concat-git-diff: Add test case growing a file with a git diff and then
	with a non-git diff; without this fix; the result would be truncated.

	Rename get_input_file() parameter to clarify code
	* src/inp.c (get_input_file): Rename mode parameter to file_type, it's all we
	care about here.

	Improve error message when patching a file of different type
	* src/inp.c (get_input_file): Improve error message when patching a file of
	different type.
	* tests/symlinks: Update test case.

	Minor test case updates
	* tests/dash-o-append: Minor update (still expected to fail).
	* tests/symlinks: Minor update.

2012-09-17  Andreas Gruenbacher  <agruen@linbit.com>

	Disable xattrs if libattr doesn't implement attr_copy_action()
	* m4/xattr.m4 (gl_FUNC_XATTR): Only enable USE_XATTR if both attr_copy_file()
	and attr_copy_action() are defined.
	* src/util.c (copy_attr_check): No fallback needed if attr_copy_action() is not
	defined.

	Allow to use potentially dangerous filenames from the root directory
	* src/pch.c (cwd_is_root): New function to check if we are in the root
	directory of a filename.
	(name_is_valid): Allow to use potentially dangerous filenames when the current
	working directory is the root directory: from there, those names are not
	any more dangerous than other names.
	* tests/bad-filenames: New test case.

2012-09-14  Andreas Gruenbacher  <agruen@linbit.com>

	Update leftover license notice in README
	* README: Change leftover GPLv2 license notice to GPLv3.

	Check if libattr implements attr_copy_action()
	* m4/xattr.m4 (gl_FUNC_XATTR): Check if attr_copy_action() is defined.
	* src/util.c: If attr_copy_action() doesn't exist, fall back to the default
	copy_attr_file() behavior of copying most extended attributes except ACLs.

2012-09-13  Andreas Gruenbacher  <agruen@linbit.com>

	Change the type of *_needs_removal from int to bool

	In a git-style diff, make sure not to unlink the original by accident
	* src/patch.c (main): Fail if a file is not empty as expected.
	(output_files): In a git-style diff, make sure not to unlink the original when
	making a backup of an unmodified file.
	* tests/create-delete: Fix failed-file-deletion test and add
	successful-file-deletion test.

	Do not pass file type in mode of open(..., O_CREAT, mode)
	* src/patch.c (main): Strip file type off of create mode for temporary output
	files: some systems don't ignore the file type; we want to create a regular
	file even when patching a symlink.

	Add note on GPLv3 license change in version 2.6
	* NEWS: Add note.

2012-09-12  Andreas Gruenbacher  <agruen@linbit.com>

	Version 2.7
	* NEWS: Update.

	maint: update gnulib submodule

2012-08-11  Andreas Gruenbacher  <agruen@linbit.com>

	Support double-quoted filenames in all context diff formats
	* src/util.c (fetchname): Always recognize double-quoted filenames.
	* src/util.h (fetchname): Update prototype.
	* src/pch.c (intuit_diff_type): Update calls to fetchname().
	* tests/quoted-filenames: Change to a normal unified diff.
	* NEWS: Update.

2012-08-08  Andreas Gruenbacher  <agruen@linbit.com>

	Remove SHA1 hashes from the file id cache
	* src/util.c (file_id): Remove sha1 field.
	(update_sha1, lookup_sha1): Remove functions.
	* src/util.h (update_sha1, lookup_sha1): Remove declarations.

	Detect concatenated git-style patches by tracking what's in the output queue
	* src/patch.c (main): Instead of looking at the SHA hashes to detect
	concatenated git-style patches, detect when a file to write to is already in
	the output queue.
	* tests/concat-git-diff: Add create/delete tests.

	In the file id cache, allow to flag files in the output queue
	* src/util.c (file_id): Add queued_output field.
	(__insert_file_id): Initialize queued_output.
	(set_queued_output, has_queued_output): New functions.
	* src/util.h (set_queued_output, has_queued_output): Declare.

2012-08-08  Dmitry V. Levin  <ldv@altlinux.org>

	Add another git-style diff concatenation regression test
	* tests/concat-git-diff: Add test case here.

2012-08-08  Andreas Gruenbacher  <agruen@linbit.com>

	maint: ignore more build artifacts

2012-08-07  Andreas Gruenbacher  <agruen@linbit.com>

	Change outst variable name to tmpoutst to be less misleading
	* src/patch.c (main): Rename outst to tmpoutst.

2012-08-02  Andreas Gruenbacher  <agruen@linbit.com>

	In git-style diffs, create new files immediatetly and only remember files to modify
	* src/patch.c (output_file): Create new files immediately.  Document why
	things are implemented that way.
	* tests/concat-git-diff: Fix glitch in test case.

2012-08-01  Jim Meyering  <meyering@redhat.com>

	Don't close a negative file descriptor
	* src/inp.c (re_input): Don't close FD if it's negative.

2012-08-01  Andreas Gruenbacher  <agruen@linbit.com>

	Add file create test case which still needs to be fixed
	* tests/concat-git-diff: Add file create test case.

2012-08-01  Jim Meyering  <meyering@redhat.com>

	build: remove unnecessary if-before-free
	* src/util.c (update_sha1): Remove unnecessary if-before-free,
	to avoid "make syntax-check" failure.

	build: mark an internal function as "pure"
	* src/pch.c (sha1_says_nonexistent): Apply _GL_ATTRIBUTE_PURE,
	to avoid failure with -Werror=suggest-attribute=pure.

2012-08-01  Andreas Gruenbacher  <agruen@linbit.com>

	maint: update bootstrap and gnulib submodule
	* bootstrap: Update from gnulib.

	Try to recognize concatenated git diffs and handle them appropriately
	* src/patch.c (main): Remember the "before" SHA1 hashes of git-style patches;
	the same patch will always use the same "before" SHA1 for a specific file.
	Try to recognize concatenated patches based on that.
	* tests/concat-git-diff: New test case.
	* tests/Makefile.am (TESTS): Add new test case.

	Allow to process only part of the deferred output file list
	* src/patch.c (output_files): Add parameter to specify which file to stop at.
	(main): Pass NULL to output_files() to process the entire list.

2012-07-31  Andreas Gruenbacher  <agruen@linbit.com>

	Allow to remember SHA1 hashes in the file id cache
	* src/util.c (file_id): New sha1 field.
	(__insert_file_id): Split off from insert_file_id().  Initialize sha1 field.
	(__lookup_file_id): Split off from lookup_file_id().
	(update_sha1): Remember SHA1 hash of a file or update the remembered SHA1 hash.
	(lookup_sha1): Look up the SHA1 hash of a file.
	* src/util.h (update_sha1, lookup_sha1): Declare.

	Accessor functions for SHA1 hashes in git-style diffs
	* src/pch.c (p_sha1): New variable.
	(get_sha1): New function for saving a sha1 checksum.
	(sha1_says_nonexistent): Take a NULL terminated string instead of an end
	pointer.
	(intuit_diff_type): Remember the SHA1 hashes from index headers in git-style
	diffs in p_sha1.
	(pch_sha1): New function for accessing p_sha1.
	* src/pch.h (pch_sha1): Declare.

	Add missing "diff --git" index lines
	* tests/copy-rename, tests/criss-cross, tests/file-modes,
	tests/mixed-patch-types, tests/quoted-filenames: Add missing index lines in the
	"dif --git" test cases: We will use some of them for consistency checks soon.

2012-04-24  Andreas Gruenbacher  <agruen@linbit.com>

	Fix segfault in output_file_later()
	Bug reported by Dmitry V. Levin <ldv@altlinux.org>.
	* src/patch.c (output_file_later): Fix case where the output file is identical
	with the input file (and to == NULL).

2012-04-17  Andreas Gruenbacher  <agruen@linbit.com>

	maint: update bootstrap and gnulib submodule
	* bootstrap: Update from gnulib.

	Update NEWS
	* NEWS: Update.

	Only warn when trying to modify read-only files
	Failing when trying to patch read-only files causes various users of patch to
	break.  Instead, warn by default and introduce a command line option for
	choosing a different behavior.
	* patch.man: Describe the new behavior and command-line option.
	* src/patch.c (read_only_behavior): New variable.
	(main): Implement the new behavior.
	(longopts): Add the new --read-only option.
	(option_help): Describe the new behavior.
	(get_some_switches): Recognize the new --read-only option.

	Fix "delete file which does not exist" test case
