summaryrefslogtreecommitdiff
path: root/usr.bin/patch
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2003-07-16 16:06:54 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2003-07-16 16:06:54 +0000
commitf58738aceeb6ea2e2a00fa3c259f7fd8ada1fb49 (patch)
treec1410ee9862d9392bf782096a81ff07aed5a7cf2 /usr.bin/patch
parentd2521f3995b7976ca1866c0ce01b59a3ad6f8590 (diff)
Do not produce garbage if the patch file contains invalid line numbers.
ok millert@ tedu@
Diffstat (limited to 'usr.bin/patch')
-rw-r--r--usr.bin/patch/inp.c10
-rw-r--r--usr.bin/patch/patch.c11
2 files changed, 14 insertions, 7 deletions
diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c
index a60d48aa138..51f29033b0c 100644
--- a/usr.bin/patch/inp.c
+++ b/usr.bin/patch/inp.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: inp.c,v 1.9 2002/07/04 04:22:48 deraadt Exp $ */
+/* $OpenBSD: inp.c,v 1.10 2003/07/16 16:06:53 otto Exp $ */
#ifndef lint
-static char rcsid[] = "$OpenBSD: inp.c,v 1.9 2002/07/04 04:22:48 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: inp.c,v 1.10 2003/07/16 16:06:53 otto Exp $";
#endif /* not lint */
#include "EXTERN.h"
@@ -320,8 +320,10 @@ ifetch(line,whichbuf)
Reg1 LINENUM line;
int whichbuf; /* ignored when file in memory */
{
- if (line < 1 || line > input_lines)
- return "";
+ if (line < 1 || line > input_lines) {
+ say2("No such line %ld in input file, ignoring\n", line);
+ return NULL;
+ }
if (using_plan_a)
return i_ptr[line];
else {
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? */