nmh-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nmh-commits] nmh ChangeLog uip/mhparse.c test/tests/mhshow/t...


From: Eric Gillespie
Subject: [Nmh-commits] nmh ChangeLog uip/mhparse.c test/tests/mhshow/t...
Date: Wed, 13 Aug 2008 01:01:14 +0000

CVSROOT:        /sources/nmh
Module name:    nmh
Changes by:     Eric Gillespie <epg>    08/08/13 01:01:13

Modified files:
        .              : ChangeLog 
        uip            : mhparse.c 
Added files:
        test/tests/mhshow: test-qp 

Log message:
                * test/tests/mhshow/test-qp: Test various valid and invalid
                escape sequences.
        
                * uip/mhparse.c (openQuoted): Simplify the decode-or-show for 
loop by
                peeking ahead to the next byte(s) when encountering '=', and 
just let
                invalid escape sequences through as literals (fixes bug #15245).

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/nmh/ChangeLog?cvsroot=nmh&r1=1.288&r2=1.289
http://cvs.savannah.gnu.org/viewcvs/nmh/test/tests/mhshow/test-qp?cvsroot=nmh&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/mhparse.c?cvsroot=nmh&r1=1.18&r2=1.19

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/nmh/nmh/ChangeLog,v
retrieving revision 1.288
retrieving revision 1.289
diff -u -b -r1.288 -r1.289
--- ChangeLog   12 Aug 2008 18:04:29 -0000      1.288
+++ ChangeLog   13 Aug 2008 01:01:12 -0000      1.289
@@ -1,3 +1,12 @@
+2008-08-12  Eric Gillespie  <address@hidden>
+
+       * test/tests/mhshow/test-qp: Test various valid and invalid
+       escape sequences.
+
+       * uip/mhparse.c (openQuoted): Simplify the decode-or-show for loop by
+       peeking ahead to the next byte(s) when encountering '=', and just let
+       invalid escape sequences through as literals (fixes bug #15245).
+
 2008-08-12  Peter Maydell  <address@hidden>
 
        * autogen.sh (new file): add script for running the GNU

Index: uip/mhparse.c
===================================================================
RCS file: /sources/nmh/nmh/uip/mhparse.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- uip/mhparse.c       5 Apr 2008 18:41:38 -0000       1.18
+++ uip/mhparse.c       13 Aug 2008 01:01:13 -0000      1.19
@@ -2,7 +2,7 @@
 /*
  * mhparse.c -- routines to parse the contents of MIME messages
  *
- * $Id: mhparse.c,v 1.18 2008/04/05 18:41:38 pm215 Exp $
+ * $Id: mhparse.c,v 1.19 2008/08/13 01:01:13 epg Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -1859,8 +1859,6 @@
 
     fseek (ct->c_fp, ct->c_begin, SEEK_SET);
     while (len > 0) {
-       char *dp;
-
        if (fgets (buffer, sizeof(buffer) - 1, ct->c_fp) == NULL) {
            content_error (NULL, ct, "premature eof");
            goto clean_up;
@@ -1876,80 +1874,68 @@
        *++ep = '\n', ep++;
 
        for (; cp < ep; cp++) {
-           if (quoted) {
-               if (quoted > 1) {
-                   if (!isxdigit (*cp)) {
-invalid_hex:
-                       dp = "expecting hexidecimal-digit";
-                       goto invalid_encoding;
-                   }
+           if (quoted > 0) {
+               /* in an escape sequence */
+               if (quoted == 1) {
+                   /* at byte 1 of an escape sequence */
+                   mask = hex2nib[*cp & 0x7f];
+                   /* next is byte 2 */
+                   quoted = 2;
+               } else {
+                   /* at byte 2 of an escape sequence */
                    mask <<= 4;
                    mask |= hex2nib[*cp & 0x7f];
                    putc (mask, ce->ce_fp);
                    if (digested)
                        MD5Update (&mdContext, &mask, 1);
-               } else {
-                   switch (*cp) {
-                   case ':':
-                       putc (*cp, ce->ce_fp);
-                       if (digested)
-                           MD5Update (&mdContext, (unsigned char *) ":", 1);
-                       break;
-
-                   default:
-                       if (!isxdigit (*cp))
-                           goto invalid_hex;
-                       mask = hex2nib[*cp & 0x7f];
-                       quoted = 2;
-                       continue;
-                   }
-               }
-
                if (ferror (ce->ce_fp)) {
                    content_error (ce->ce_file, ct, "error writing to");
                    goto clean_up;
                }
+                   /* finished escape sequence; next may be literal or a new
+                    * escape sequence */
                quoted = 0;
+               }
+               /* on to next byte */
                continue;
            }
 
-           switch (*cp) {
-           default:
-               if (*cp < '!' || *cp > '~') {
-                   int i;
-                   dp = "expecting character in range [!..~]";
-
-invalid_encoding:
-                   i = strlen (invo_name) + 2;
-                   content_error (NULL, ct,
-                                  "invalid QUOTED-PRINTABLE encoding -- 
%s,\n%*.*sbut got char 0x%x",
-                                  dp, i, i, "", *cp);
-                   goto clean_up;
+           /* not in an escape sequence */
+           if (*cp == '=') {
+               /* starting an escape sequence, or invalid '='? */
+               if (cp + 1 < ep && cp[1] == '\n') {
+                   /* "=\n" soft line break, eat the \n */
+                   cp++;
+                   continue;
+               }
+               if (cp + 1 >= ep || cp + 2 >= ep) {
+                   /* We don't have 2 bytes left, so this is an invalid
+                    * escape sequence; just show the raw bytes (below). */
+               } else if (isxdigit (cp[1]) && isxdigit (cp[2])) {
+                   /* Next 2 bytes are hex digits, making this a valid escape
+                    * sequence; let's decode it (above). */
+                   quoted = 1;
+                   continue;
+               } else {
+                   /* One or both of the next 2 is out of range, making this
+                    * an invalid escape sequence; just show the raw bytes
+                    * (below). */
+               }
                }
-               /* and fall...*/
-           case ' ':
-           case '\t':
-           case '\n':
+
+           /* Just show the raw byte. */
                putc (*cp, ce->ce_fp);
                if (digested) {
-                   if (*cp == '\n')
+               if (*cp == '\n') {
                        MD5Update (&mdContext, (unsigned char *) "\r\n",2);
-                   else
+               } else {
                        MD5Update (&mdContext, (unsigned char *) cp, 1);
                }
+           }
                if (ferror (ce->ce_fp)) {
                    content_error (ce->ce_file, ct, "error writing to");
                    goto clean_up;
                }
-               break;
-
-           case '=':
-               if (*++cp != '\n') {
-                   quoted = 1;
-                   cp--;
-               }
-               break;
-           }
        }
     }
     if (quoted) {

Index: test/tests/mhshow/test-qp
===================================================================
RCS file: test/tests/mhshow/test-qp
diff -N test/tests/mhshow/test-qp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ test/tests/mhshow/test-qp   13 Aug 2008 01:01:13 -0000      1.1
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+set -e
+
+expected=$MH_TEST_DIR/$$.expected
+actual=$MH_TEST_DIR/$$.actual
+
+# Write message with bogus quoted-printable data.
+msgfile=$(mhpath new)
+msgnum=$(basename $msgfile)
+cat > $msgfile <<EOF
+From: address@hidden
+To: address@hidden
+Subject: test
+MIME-Version: 1.0
+Content-Transfer-Encoding: quoted-printable
+Date: Sun, 18 Dec 2005 00:52:39 +0100
+
+=3D
+=3d
+ignored space at end 
+ignored tab at end     
+just a newline =
+
+==3d ====3D
+=      just a tab
+= just a space
+=cl
+=l with a space
+=l
+= ^H (backspace) character, probably erased = in diff output
+EOF
+
+# check it
+cat > $expected <<EOF
+Date:    Sun, 18 Dec 2005 00:52:39 +0100
+To:      address@hidden
+From:    address@hidden
+Subject: test
+
+MIME-Version: 1.0
+
+part       text/plain                 181
+=
+=
+ignored space at end
+ignored tab at end
+just a newline 
+== ====
+=      just a tab
+= just a space
+=cl
+=l with a space
+=l
+= ^H (backspace) character, probably erased = in diff output
+EOF
+mhshow -nopause $msgnum > $actual 2>&1
+diff -u $expected $actual




reply via email to

[Prev in Thread] Current Thread [Next in Thread]