History log of /freebsd-10-stable/usr.bin/patch/pch.c
Revision Date Author Comments
# 320086 18-Jun-2017 pfg

MFC r319676:
patch: if reading fails, do not go into infinite loop asking for a filename.

This can happen if no tty is available.

Obtained from: OpenBSD (CVS rev 1.54)


# 298763 29-Apr-2016 pfg

MFC r298530:
patch(1): avoid signed integer overflow when debugging.

Integer i is used to index p_end of type LINENUM (actually long).
Match the types.


# 293290 06-Jan-2016 bdrewery

MFC r289677:

Fix a ton of speelling errors


# 287223 27-Aug-2015 delphij

MFC r281800 (pfg):

patch(1): small include changes.

Mostly to match OpenBSD, no functional change.

MFC r286601 + 286617:

use posix_spawn(3) instead of fork() and exec() manually as suggested
by jmg@.


# 286348 05-Aug-2015 delphij

Fix patch(1) shell injection vulnerability via ed(1). [SA-15:18]

Fix routed remote denial of service vulnerability. [SA-15:19]


# 276807 08-Jan-2015 pfg

MFC r276218:

patch: Bring in xstrdup and use it when appropriate.

The function savestr allows NULL return values during Plan A patching so in
case of out of memory conditions, Plan B can step in. In many cases, NULL
value is not properly handled, so use xstrdup here (it's outside Plan A/B
patching, which means that even Plan B relies on successful operations).

Clean up some whitespaces while here

Obtained from: OpenBSD


# 275841 16-Dec-2014 pfg

MFC r275553, r275612;

patch(1): Bring fixes from OpenBSD

Check fstat return value. Use off_t for file size and offsets.
Avoid iterating over end of string.

Introduce strtolinenum to properly check line numbers while parsing:
no signs, no spaces, just digits, 0 <= x <= LONG_MAX

Properly validate line ranges supplied in diff file to prevent overflows.
Also fixes an out of boundary memory access because the resulting values
are used as array indices.

PR: 195436
Obtained from: OpenBSD


# 275840 16-Dec-2014 pfg

MFC r275531, r275581, r275582;

patch(1): Small changes to sync with OpenBSD

Update OpenBSD CVS revision tag for our r255232.
Prefer setvbuf() to setlinebuf().
Small space changes, mostly to keep in sync with OpenBSD

Obtained from: OpenBSD


# 267746 22-Jun-2014 pfg

MFC r267490:
patch: unsign the line length to avoid overflows.

Patch(1) uses a short int for the line length, which is usually
sufficient for regular diffs, but makes no effort to signal
when there is an overflow.

Change the line length to an unsigned short int to better use
the fact that a length is never negative. The change is loosely
inspired on a related change in DragonFly, but we avoid spending
more memory than necessary.

While here adjust the messages to be clearer on what is happening.


# 267701 21-Jun-2014 pfg

MFC r267426, r267464:

Avoid zeroing during allocation.

This change reverts a change from OpenBSD which made use of
calloc, and therefore wasted time initializing arrays that
will later be realloc'ed.

Consistently use FreeBSD's reallocf():
- Drop some bogus casts to size_t.
- The new_p_foo variables are not needed anymore.

Also merge the changes from OpenBSD's manpage
patch.1 Rev 1.27:
"patch was moved from user portability (UP) to base in issue 7
and is no longer optional"


# 287223 27-Aug-2015 delphij

MFC r281800 (pfg):

patch(1): small include changes.

Mostly to match OpenBSD, no functional change.

MFC r286601 + 286617:

use posix_spawn(3) instead of fork() and exec() manually as suggested
by jmg@.


# 286348 05-Aug-2015 delphij

Fix patch(1) shell injection vulnerability via ed(1). [SA-15:18]

Fix routed remote denial of service vulnerability. [SA-15:19]


# 276807 08-Jan-2015 pfg

MFC r276218:

patch: Bring in xstrdup and use it when appropriate.

The function savestr allows NULL return values during Plan A patching so in
case of out of memory conditions, Plan B can step in. In many cases, NULL
value is not properly handled, so use xstrdup here (it's outside Plan A/B
patching, which means that even Plan B relies on successful operations).

Clean up some whitespaces while here

Obtained from: OpenBSD


# 275841 16-Dec-2014 pfg

MFC r275553, r275612;

patch(1): Bring fixes from OpenBSD

Check fstat return value. Use off_t for file size and offsets.
Avoid iterating over end of string.

Introduce strtolinenum to properly check line numbers while parsing:
no signs, no spaces, just digits, 0 <= x <= LONG_MAX

Properly validate line ranges supplied in diff file to prevent overflows.
Also fixes an out of boundary memory access because the resulting values
are used as array indices.

PR: 195436
Obtained from: OpenBSD


# 275840 16-Dec-2014 pfg

MFC r275531, r275581, r275582;

patch(1): Small changes to sync with OpenBSD

Update OpenBSD CVS revision tag for our r255232.
Prefer setvbuf() to setlinebuf().
Small space changes, mostly to keep in sync with OpenBSD

Obtained from: OpenBSD


# 267746 22-Jun-2014 pfg

MFC r267490:
patch: unsign the line length to avoid overflows.

Patch(1) uses a short int for the line length, which is usually
sufficient for regular diffs, but makes no effort to signal
when there is an overflow.

Change the line length to an unsigned short int to better use
the fact that a length is never negative. The change is loosely
inspired on a related change in DragonFly, but we avoid spending
more memory than necessary.

While here adjust the messages to be clearer on what is happening.


# 267701 21-Jun-2014 pfg

MFC r267426, r267464:

Avoid zeroing during allocation.

This change reverts a change from OpenBSD which made use of
calloc, and therefore wasted time initializing arrays that
will later be realloc'ed.

Consistently use FreeBSD's reallocf():
- Drop some bogus casts to size_t.
- The new_p_foo variables are not needed anymore.

Also merge the changes from OpenBSD's manpage
patch.1 Rev 1.27:
"patch was moved from user portability (UP) to base in issue 7
and is no longer optional"