diff options
| author | Elliott Hughes <enh@google.com> | 2020-04-17 16:51:44 -0700 | 
|---|---|---|
| committer | Rob Landley <rob@landley.net> | 2020-04-20 17:15:51 -0500 | 
| commit | 539e66891279044d2ade4e9d2590939301c5944c (patch) | |
| tree | 9f2a23075dc95a04bb70784276ec208b50dde8c9 | |
| parent | c33dc593b2ff3a2a0b2800c3e4f35806bd5e89ae (diff) | |
| download | toybox-539e66891279044d2ade4e9d2590939301c5944c.tar.gz | |
patch: fix out of bounds memory access.
On empty lines, we'd read one byte before the start of the buffer.
| -rw-r--r-- | toys/posix/patch.c | 2 | 
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; | 
