--- sbr/m_getfld.c.orig Tue Jul 7 18:19:48 1998 +++ sbr/m_getfld.c Tue Jul 7 18:25:56 1998 @@ -390,6 +390,31 @@ *cp++ = j = *(iob->_ptr + c); c = _filbuf(iob); #endif +/* bugfix, 03/1998. + * If we encounter EOF halfway through reading the value (ie there is + * no trailing \n in the field) then __underflow() above returns EOF. + * Previously we didn't check for this, with the result that we then + * attempt to read from the stream and wind up segfaulting doing a + * bcopy() with length parameter -1. Instead, we just append a newline + * to what we've read, so the following conditional will pick it up + * and return the field value. Then the EOF is actually dealt with + * the next time this function is called. + * The reason for appending \n is because the callers are known to + * work with 'name: value\n', and setting j to '\n' is known to exit + * in the right way, and the less we change the less likely + * we are to introduce new bugs. And I'm scared of the curse in the + * comments at the top of this file :-> + * -- PMM (pmaydell(_at_)chiark(_dot_)greenend(_dot_)org(_dot_)uk) + * + * Patch slightly modified for nmh 0.26 + * Ruud de Rooij Tue, 7 Jul 1998 18:24:15 +0200 + */ + if (c == EOF && j != '\0' && j != '\n') { + *cp++ = j = '\n'; + /* maybe we should advise(something) here? */ + } +/* bugfix end */ + if ((j == '\0' || j == '\n') && c != ' ' && c != '\t') { if (c != EOF) { #ifdef LINUX_STDIO