Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/mail PR/47396: Steffen: mail(1) may falsely use quot...



details:   https://anonhg.NetBSD.org/src/rev/591ecc61fd96
branches:  trunk
changeset: 783692:591ecc61fd96
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jan 04 01:54:55 2013 +0000

description:
PR/47396: Steffen: mail(1) may falsely use quoted-printable for files with
embedded NULs

diffstat:

 usr.bin/mail/mime_attach.c |  29 +++++++++++++++++------------
 1 files changed, 17 insertions(+), 12 deletions(-)

diffs (74 lines):

diff -r f425d05c92a9 -r 591ecc61fd96 usr.bin/mail/mime_attach.c
--- a/usr.bin/mail/mime_attach.c        Fri Jan 04 01:43:59 2013 +0000
+++ b/usr.bin/mail/mime_attach.c        Fri Jan 04 01:54:55 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mime_attach.c,v 1.15 2013/01/04 01:43:59 christos Exp $        */
+/*     $NetBSD: mime_attach.c,v 1.16 2013/01/04 01:54:55 christos Exp $        */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #ifndef __lint__
-__RCSID("$NetBSD: mime_attach.c,v 1.15 2013/01/04 01:43:59 christos Exp $");
+__RCSID("$NetBSD: mime_attach.c,v 1.16 2013/01/04 01:54:55 christos Exp $");
 #endif /* not __lint__ */
 
 #include <assert.h>
@@ -224,12 +224,18 @@
 static const char *
 content_encoding_core(void *fh, const char *ctype)
 {
-       int c, lastc;
+#define MAILMSG_CLEAN  0x0
+#define MAILMSG_ENDWS  0x1
+#define MAILMSG_CTRLC  0x2
+#define MAILMSG_8BIT   0x4
+#define MAILMSG_LONGL  0x8
+       int c, lastc, state;
        int ctrlchar, endwhite;
        size_t curlen, maxlen;
 
+       state = MAILMSG_CLEAN;
        curlen = 0;
-       maxlen = 0;
+       maxlen = line_limit();
        ctrlchar = 0;
        endwhite = 0;
        lastc = EOF;
@@ -240,27 +246,26 @@
                        return MIME_TRANSFER_BASE64;
 
                if (c > 0x7f) {
-                       if (is_text(ctype))
-                               return MIME_TRANSFER_QUOTED;
-                       else
+                       if (!is_text(ctype))
                                return MIME_TRANSFER_BASE64;
+                       state |= MAILMSG_8BIT;
+                       continue;
                }
                if (c == '\n') {
                        if (is_WSP(lastc))
-                               endwhite = 1;
+                               state |= MAILMSG_ENDWS;
                        if (curlen > maxlen)
-                               maxlen = curlen;
+                               state |= MAILMSG_LONGL;
                        curlen = 0;
                }
                else if ((c < 0x20 && c != '\t') || c == 0x7f || lastc == '\r')
-                       ctrlchar = 1;
-
+                       state |= MAILMSG_CTRLC;
                lastc = c;
        }
        if (lastc == EOF) /* no characters read */
                return MIME_TRANSFER_7BIT;
 
-       if (lastc != '\n' || ctrlchar || endwhite || maxlen > line_limit())
+       if (lastc != '\n' || state != MAILMSG_CLEAN)
                return MIME_TRANSFER_QUOTED;
 
        return MIME_TRANSFER_7BIT;



Home | Main Index | Thread Index | Old Index