From: Dan Harkless Date: Thu, 13 May 1999 01:16:14 +0000 (+0000) Subject: Change ordering of a conditional to prevent a bad pointer dereference. X-Git-Tag: nmh-1_0~192 X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=6f48e12f2d4dd510f1610338648c2f6ab904392f;p=mmh Change ordering of a conditional to prevent a bad pointer dereference. Fixes a segv in inc (and occasionally other programs). Originally from Ruud de Rooij --- diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index 8697f20..aca481a 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -259,7 +259,7 @@ m_getfld (int state, unsigned char *name, unsigned char *buf, bp = sp = (unsigned char *) iob->_ptr - 1; j = (cnt = iob->_cnt+1) < i ? cnt : i; #endif - while ((c = *bp++) != ':' && c != '\n' && --j >= 0) + while (--j >= 0 && (c = *bp++) != ':' && c != '\n') *cp++ = c; j = bp - sp; @@ -538,7 +538,7 @@ m_unknown(FILE *iob) ; #else /* RPATHS */ cp = unixbuf; - while ((c = getc (iob)) != '\n') + while ((c = getc (iob)) != '\n' && cp - unixbuf < BUFSIZ - 1) *cp++ = c; *cp = 0; #endif /* RPATHS */ @@ -639,7 +639,7 @@ m_Eom (int c, FILE *iob) break; #else /* RPATHS */ cp = unixbuf; - while ((c = getc (iob)) != '\n' && c >= 0) + while ((c = getc (iob)) != '\n' && c >= 0 && cp - unixbuf < BUFSIZ - 1) *cp++ = c; *cp = 0; #endif /* RPATHS */