460 Commits

Author SHA1 Message Date
Andreas Gruenbacher
40b387de08 Version 2.7.6
* NEWS: Update.
v2.7.6
2018-02-03 19:43:57 +01:00
Andreas Gruenbacher
66f9fa2690 Fix typo in README
* README: Fix typo.
2018-02-03 19:43:57 +01:00
Andreas Gruenbacher
107e1cecfc 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.
2018-02-03 14:46:17 +01:00
Andreas Gruenbacher
e6da0b81bf Remove stale reference to m4/utimbuf.m4
* Makefile.am (EXTRA_DIST): Remove stale reference to m4/utimbuf.m4.
2018-02-03 14:44:53 +01:00
Andreas Gruenbacher
9ab866d562 maint: update bootstrap and gnulib submodule
* bootstrap: Update from gnulib.
2018-02-03 13:26:55 +01:00
Andreas Gruenbacher
6a737fca57 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 11:01:47 +01:00
Thomas Orgis
592e1f9163 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 10:56:27 +01:00
Andreas Gruenbacher
15cc7d44d4 gnulib: update to latest 2018-01-23 10:41:04 +01:00
Bruno Haible
5bf48c87ca Don't use an undocumented Autoconf macro
* configure.ac: Use AC_CONFIG_HEADERS instead of AC_CONFIG_HEADER.
2018-01-23 10:40:56 +01:00
Andreas Gruenbacher
00947f4111 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.
2017-09-06 18:35:44 +02:00
Andreas Gruenbacher
61b6ec8857 patch.man: Clarify --forward description 2017-09-06 17:57:29 +02:00
Andreas Gruenbacher
a2b6fb1672 gnulib: update to latest 2017-09-04 13:56:25 +02:00
Tim Waugh
817d7d1767 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
2017-02-22 11:03:43 +01:00
Hanno Boeck
49705d1d8d 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.
2016-08-10 09:25:29 +02:00
Hanno Boeck
a0d7fe4589 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-08-10 00:13:25 +02:00
Jim Meyering
4c43a0b1cb tests: use $PATCH rather than hard-coded path
* tests/git-cleanup: Don't hard-code program name.
2016-07-31 10:17:52 +02:00
Jim Meyering
d874c38335 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 10:17:52 +02:00
Jim Meyering
b6c4780f73 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 10:17:52 +02:00
Jim Meyering
9ca38fa1e6 gnulib: update to latest 2016-07-31 10:17:52 +02:00
Andreas Gruenbacher
66fdcf0e7c 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.
2016-07-27 15:47:47 +02:00
Andreas Gruenbacher
83a3ed012c 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.
2016-07-27 15:47:47 +02:00
Andreas Gruenbacher
70532e21a8 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-07-27 10:58:03 +02:00
Andreas Gruenbacher
4f4fd1b41d 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.
2016-03-18 10:12:31 +01:00
Andreas Gruenbacher
3270d221a9 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-10-03 15:25:49 +02:00
Andreas Gruenbacher
98b86e970a 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-20 11:18:12 +02:00
Tobias Stoeckmann
68049159f2 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-12 15:38:23 +02:00
Tobias Stoeckmann
871f87824a Use xmalloc in bestmatch
* src/bestmatch.h (bestmatch): Use xmalloc instead of malloc to handle
out-of-memory situations.
2015-07-08 20:55:51 +02:00
Andreas Gruenbacher
5c6625bf62 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-09 15:29:15 -04:00
Andreas Gruenbacher
6a55099e7a Use gnulib size_max module
* bootstrap.conf (gnulib_modules): Add size_max.
* configure.ac: Call gl_SIZE_MAX.
2015-03-08 14:55:48 -04:00
Andreas Gruenbacher
3b698ab6a1 Version 2.7.5
* NEWS: Update.
v2.7.5
2015-03-07 01:32:27 +01:00
Andreas Gruenbacher
3cd040cf4c build: update gnulib submodule to latest 2015-03-07 01:32:21 +01:00
Andreas Gruenbacher
7a77ae9f81 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-07 01:23:29 +01:00
Andreas Gruenbacher
274c66c775 Describe better how the dirfd cache works 2015-03-05 23:14:57 +01:00
Andreas Gruenbacher
99d3b514e9 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.
2015-03-05 23:14:25 +01:00
Andreas Gruenbacher
a6615bcb83 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.
2015-03-05 22:57:44 +01:00
Andreas Gruenbacher
914d06b7c3 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.
2015-03-05 22:57:44 +01:00
Andreas Gruenbacher
c5705fd476 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.
2015-03-05 22:57:42 +01:00
Andreas Gruenbacher
ca9df22fe6 Add list_head based double linked list
* src/list.h: New data structure.
src/Makefile.am (patch_SOURCES): Add list.h.
2015-03-05 22:57:07 +01:00
Andreas Gruenbacher
0d3df382d6 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 22:57:07 +01:00
Tim Waugh
9f92e52c9f Add more path traversal test cases
* tests/symlinks: Add more path traversal test cases.
2015-03-05 22:57:07 +01:00
Andreas Gruenbacher
6fbdcefe7d 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.
2015-03-05 22:57:07 +01:00
Andreas Gruenbacher
a025a51ca5 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.
2015-03-05 22:57:07 +01:00
Andreas Gruenbacher
ef609c26b2 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.
2015-03-05 22:57:04 +01:00
Andreas Gruenbacher
3c58eb50ce 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-03-05 21:49:55 +01:00
Andreas Gruenbacher
e1f0aa0a9d 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.
2015-02-28 21:10:34 +01:00
Andreas Gruenbacher
c5da382c0b 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.
2015-02-28 21:10:34 +01:00
Andreas Gruenbacher
d55ab5b941 Minor cosmetic changes
* src/safe.c: Minor cosmetic changes
2015-02-28 21:10:22 +01:00
Andreas Gruenbacher
db9f39507e 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-22 18:50:16 +01:00
Andreas Gruenbacher
8d12036047 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-10 22:31:56 +01:00
Andreas Gruenbacher
7297352e16 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.
2015-02-04 10:54:03 +01:00