summaryrefslogtreecommitdiffstats
path: root/usr.bin/patch/patch.c
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2003-07-16 16:06:53 +0000
committerotto <otto@openbsd.org>2003-07-16 16:06:53 +0000
commit328a6cea628e291608421215d51fb70167656df1 (patch)
treef17fcb6601b444be5ad29e8bb0adca2ca17a9148 /usr.bin/patch/patch.c
parentAdd support for unbuffered SBus LANCE devices. jason@ and deraadt@ OK (diff)
downloadwireguard-openbsd-328a6cea628e291608421215d51fb70167656df1.tar.xz
wireguard-openbsd-328a6cea628e291608421215d51fb70167656df1.zip
Do not produce garbage if the patch file contains invalid line numbers.
ok millert@ tedu@
Diffstat (limited to 'usr.bin/patch/patch.c')
-rw-r--r--usr.bin/patch/patch.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c
index 58c924e9a8f..eca5f1eec9d 100644
--- a/usr.bin/patch/patch.c
+++ b/usr.bin/patch/patch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: patch.c,v 1.17 2003/07/02 00:21:16 avsm Exp $ */
+/* $OpenBSD: patch.c,v 1.18 2003/07/16 16:06:53 otto Exp $ */
/* patch - a program to apply diffs to original files
*
@@ -27,7 +27,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: patch.c,v 1.17 2003/07/02 00:21:16 avsm Exp $";
+static char rcsid[] = "$OpenBSD: patch.c,v 1.18 2003/07/16 16:06:53 otto Exp $";
#endif /* not lint */
#include "INTERN.h"
@@ -881,8 +881,11 @@ LINENUM line;
Reg1 char *s;
Reg2 char R_newline = '\n';
+ s = ifetch(line, 0);
+ if (s == NULL)
+ return;
/* Note: string is not null terminated. */
- for (s=ifetch(line, 0); putc(*s, ofp) != R_newline; s++) ;
+ for (; putc(*s, ofp) != R_newline; s++) ;
}
/* Does the patch pattern match at line base+offset? */
@@ -920,6 +923,8 @@ Reg1 char *a;
Reg2 char *b;
Reg3 int len;
{
+ if (a == NULL || b == NULL)
+ return FALSE;
while (len) {
if (isspace(*b)) { /* whitespace (or \n) to match? */
if (!isspace(*a)) /* no corresponding whitespace? */