]> diplodocus.org Git - nmh/commitdiff
Fixed problem with m_getfld() with long headers reported by
authorDavid Levine <levinedl@acm.org>
Thu, 2 May 2013 01:40:55 +0000 (20:40 -0500)
committerDavid Levine <levinedl@acm.org>
Thu, 2 May 2013 01:40:55 +0000 (20:40 -0500)
Paul Fox.  The problem occurred with the 512th byte of the
header was a newline:  it then skipped the next character.

sbr/m_getfld.c
test/inc/test-inc-scanout

index f84d2933719f1131191c60703e89c1e1bedc10d5..f19f7f11c632bdcf60b45d6b88f7a82ece92aaa8 100644 (file)
@@ -635,7 +635,13 @@ m_getfld (m_getfld_state_t *gstate, char name[NAMESZ], char *buf, int *bufsz,
 
                if (c != EOF) c = Peek (s);
                if (max < n) {
-                   /* the dest buffer is full */
+                   /* The dest buffer is full.  Need to back the read
+                       pointer up by one because when m_getfld() is
+                       reentered, it will read a character.  Then
+                       we'll jump right to the FLDPLUS handling code,
+                       which will not store that character, but
+                       instead move on to the next one. */
+                    if (s->readpos > s->msg_buf) --s->readpos;
                    s->state = FLDPLUS;
                    finished = 1;
                } else if (c != ' '  &&  c != '\t') {
index 87335d527e927ce8d523d4df5a605c00ebd5f496..491a520f42e3adea0c808c2e2be8a23023cbf8de 100755 (executable)
@@ -297,6 +297,42 @@ run_test 'scan -width 80 -file '"$MH_TEST_DIR"'/mess' \
          '   1  01/16 No Such User       FLDPLUS test'
 rm -f "$MH_TEST_DIR/mess"
 
+# check inc of message with header field body with more than 511 characters
+cat >"$expected" <<EOF
+Comments: The important characteristic of this message is that this header
+          field body is more than 511 bytes long.  That tests the logic in
+          m_getfld () for transitioning to the FLDPLUS state.  This is the
+          only use for the FLDPLUS state, handling header field bodies that
+          are longer than the buffer used to retrieve them.  The trailing
+          newline after the last character is the 512th character.  The 511th
+          character, counting all spaces, even the leading one, is*
+          And, it continues onto this line.
+From: No Such User <nosuch@example.com>
+To: Some Other User <someother@example.com>
+Subject: FLDPLUS test
+Date: Wed, 16 Jan 2013 20:33:58 -0600
+EOF
+
+cat >"$MH_TEST_DIR/mess" <<EOF
+From nosuch@example.com  Wed 16 Jan 2013 20:33:58 -0600
+Comments: The important characteristic of this message is that this header
+          field body is more than 511 bytes long.  That tests the logic in
+          m_getfld () for transitioning to the FLDPLUS state.  This is the
+          only use for the FLDPLUS state, handling header field bodies that
+          are longer than the buffer used to retrieve them.  The trailing
+          newline after the last character is the 512th character.  The 511th
+          character, counting all spaces, even the leading one, is*
+          And, it continues onto this line.
+From: No Such User <nosuch@example.com>
+To: Some Other User <someother@example.com>
+Subject: FLDPLUS test
+Date: Wed, 16 Jan 2013 20:33:58 -0600
+
+EOF
+inc -file "$MH_TEST_DIR/mess" >/dev/null
+check "$expected" `mhpath last`  ||  rmm last
+rm -f "$MH_TEST_DIR/mess"
+
 # check scan and inc of mbox with multiple messages
 echo y | packf -file "$MH_TEST_DIR/msgbox"
 run_test "scan -width 80 -file $MH_TEST_DIR/msgbox" \