From 81cc95f2a7a8617b7acaa7fa5fd37db6252ce9bb Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Sat, 6 Apr 1996 02:00:17 +0000 Subject: [PATCH] Here is a patch for a little bug in the WaitForString routine. The problem is when the matched string spans the end of the inbuff. This fix allocates twice the IBSIZE so that it can keep the last and the current text to search in the inbuff so that the match won't fail if it gets truncated by the read. It also warns if the search string is to long and truncates it. Submitted by: Dough Ambrisco --- usr.sbin/ppp/chat.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c index f31b4417c84..e281f992ee9 100644 --- a/usr.sbin/ppp/chat.c +++ b/usr.sbin/ppp/chat.c @@ -18,7 +18,7 @@ * Columbus, OH 43221 * (614)451-1883 * - * $Id: chat.c,v 1.7 1996/03/08 12:34:37 ache Exp $ + * $Id: chat.c,v 1.8 1996/03/08 13:22:21 ache Exp $ * * TODO: * o Support more UUCP compatible control sequences. @@ -45,7 +45,7 @@ static int TimeoutSec; static int abort_next, timeout_next; static int numaborts; char *AbortStrings[50]; -char inbuff[IBSIZE]; +char inbuff[IBSIZE*2+1]; extern int ChangeParity(char *); @@ -209,6 +209,11 @@ char *estr; str = buff; inp = inbuff; + if (strlen(str)>=IBSIZE){ + str[IBSIZE]=0; + LogPrintf(LOG_CHAT, "Truncating String to %d character: %s\n", IBSIZE, str); + } + nfds = modem + 1; s = str; for (;;) { @@ -245,8 +250,13 @@ char *estr; } if (FD_ISSET(modem, &rfds)) { /* got something */ if (DEV_IS_SYNC) { - nb = read(modem, inbuff, IBSIZE-1); - inbuff[nb] = 0; + int length; + if ((length=strlen(inbuff))>IBSIZE){ + bcopy(&(inbuff[IBSIZE]),inbuff,IBSIZE+1); /* shuffle down next part*/ + length=strlen(inbuff); + } + nb = read(modem, &(inbuff[length]), IBSIZE); + inbuff[nb + length] = 0; if (strstr(inbuff, str)) { #ifdef SIGALRM sigsetmask(omask);