summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorkevans <kevans@FreeBSD.org>2018-01-27 06:20:27 +0000
committerkevans <kevans@FreeBSD.org>2018-01-27 06:20:27 +0000
commit803c47e38277420cacfe9899a8bf46cb9afb338e (patch)
treeecf0fb6192cb50f785c3528166b7a9068437bf7c /usr.bin
parent0fdc3d008c8751adbf4ed83b1a8ea24444fbba19 (diff)
downloadFreeBSD-src-803c47e38277420cacfe9899a8bf46cb9afb338e.zip
FreeBSD-src-803c47e38277420cacfe9899a8bf46cb9afb338e.tar.gz
MFC r327826: patch(1): Don't check for NUL bytes in Plan A
Plan A mmap()'s the entire input file and operates on it in memory. The map(2) call succeeded, so we shouldn't need to bother checking for the NUL byte as long as we're within our buffer space. This was clearly intentional to match "the behavior of the original code", but it creates a discrepancy between Plan A and Plan B that doesn't seem sensible and it's not inherently wrong to allow a NUL byte. This change was motivated by the gemspec in net/rubygem-grpc failing to patch, despite the patch being generated with diff, because a NUL byte was used as a delimiter in the header briefly in an otherwise text file. An alternative was considered: to fallback to plan B if plan A won't process the entire file due to a NUL byte, but I deemed this to be the better option since plan A isn't failing due to memory limitations and will fail later on if it's really dealing with a file it shouldn't be.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/patch/inp.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c
index 19536da..1f0a835 100644
--- a/usr.bin/patch/inp.c
+++ b/usr.bin/patch/inp.c
@@ -213,8 +213,11 @@ plan_a(const char *filename)
/* now scan the buffer and build pointer array */
iline = 1;
i_ptr[iline] = i_womp;
- /* test for NUL too, to maintain the behavior of the original code */
- for (s = i_womp, i = 0; i < i_size && *s != '\0'; s++, i++) {
+ /*
+ * Testing for NUL here actively breaks files that innocently use NUL
+ * for other reasons. mmap(2) succeeded, just scan the whole buffer.
+ */
+ for (s = i_womp, i = 0; i < i_size; s++, i++) {
if (*s == '\n') {
if (iline == lines_allocated) {
if (!reallocate_lines(&lines_allocated))
OpenPOWER on IntegriCloud