aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2020-04-17 16:51:44 -0700
committerRob Landley <rob@landley.net>2020-04-20 17:15:51 -0500
commit539e66891279044d2ade4e9d2590939301c5944c (patch)
tree9f2a23075dc95a04bb70784276ec208b50dde8c9 /toys/posix
parentc33dc593b2ff3a2a0b2800c3e4f35806bd5e89ae (diff)
downloadtoybox-539e66891279044d2ade4e9d2590939301c5944c.tar.gz
patch: fix out of bounds memory access.
On empty lines, we'd read one byte before the start of the buffer.
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/patch.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/toys/posix/patch.c b/toys/posix/patch.c
index d3d77792..f0caf8ae 100644
--- a/toys/posix/patch.c
+++ b/toys/posix/patch.c
@@ -327,7 +327,7 @@ void patch_main(void)
// Other versions of patch accept damaged patches, so we need to also.
if (strip || !patchlinenum++) {
int len = strlen(patchline);
- if (patchline[len-1] == '\r') {
+ if (len && patchline[len-1] == '\r') {
if (!strip && !FLAG(s)) fprintf(stderr, "Removing DOS newlines\n");
strip = 1;
patchline[len-1]=0;