From 539e66891279044d2ade4e9d2590939301c5944c Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 17 Apr 2020 16:51:44 -0700 Subject: patch: fix out of bounds memory access. On empty lines, we'd read one byte before the start of the buffer. --- toys/posix/patch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toys/posix') 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; -- cgit v1.2.3