$NetBSD: patch-bd,v 1.4 2017/11/26 20:39:40 snj Exp $

First chunk:
https://bugzilla.redhat.com/show_bug.cgi?id=1121299
CVE-2014-3618

Second chunk:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=876511
CVE-2017-16844

Third chunk:
Avoid conflict with existing getline() functions.

--- src/formisc.c.orig	2001-06-28 19:20:45.000000000 -0700
+++ src/formisc.c	2017-11-26 12:21:14.260042851 -0800
@@ -84,12 +84,11 @@ normal:	   *target++= *start++;
 	case '"':*target++=delim='"';start++;
       }
      ;{ int i;
-	do
+	while(*start)
 	   if((i= *target++= *start++)==delim)	 /* corresponding delimiter? */
 	      break;
 	   else if(i=='\\'&&*start)		    /* skip quoted character */
 	      *target++= *start++;
-	while(*start);						/* anything? */
       }
      hitspc=2;
    }
@@ -104,7 +103,7 @@ void loadsaved(sp)const struct saved*con
 }
 							    /* append to buf */
 void loadbuf(text,len)const char*const text;const size_t len;
-{ if(buffilled+len>buflen)			  /* buf can't hold the text */
+{ while(buffilled+len>buflen)			  /* buf can't hold the text */
      buf=realloc(buf,buflen+=Bsize);
   tmemmove(buf+buffilled,text,len);buffilled+=len;
 }
@@ -115,7 +114,7 @@ void loadchar(c)const int c;		      /* a
   buf[buffilled++]=c;
 }
 
-int getline P((void))			   /* read a newline-terminated line */
+int get_line P((void))			   /* read a newline-terminated line */
 { if(buflast==EOF)			 /* at the end of our Latin already? */
    { loadchar('\n');					  /* fake empty line */
      return EOF;					  /* spread the word */
