Date: Tue, 2 Apr 1996 19:56:48 -0800 (PST) From: "Doug Ambrisko" <ambrisko@ambrisko.roble.com> To: freebsd-current@freebsd.org Subject: iijppp chat.c patch Message-ID: <199604030356.TAA00820@big.ambrisko.com>
next in thread | raw e-mail | index | archive | help
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. Doug A. *** chat.c.orig Thu Mar 28 18:59:09 1996 --- chat.c Tue Apr 2 19:48:41 1996 *************** *** 45,51 **** static int abort_next, timeout_next; static int numaborts; char *AbortStrings[50]; ! char inbuff[IBSIZE]; extern int ChangeParity(char *); --- 45,51 ---- static int abort_next, timeout_next; static int numaborts; char *AbortStrings[50]; ! char inbuff[IBSIZE*2+1]; extern int ChangeParity(char *); *************** *** 209,214 **** --- 209,219 ---- 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,252 **** } if (FD_ISSET(modem, &rfds)) { /* got something */ if (DEV_IS_SYNC) { ! nb = read(modem, inbuff, IBSIZE-1); ! inbuff[nb] = 0; if (strstr(inbuff, str)) { #ifdef SIGALRM sigsetmask(omask); --- 250,262 ---- } if (FD_ISSET(modem, &rfds)) { /* got something */ if (DEV_IS_SYNC) { ! 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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199604030356.TAA00820>