]> diplodocus.org Git - nmh/blobdiff - uip/mhlsbr.c
ap: Fix write past end of addrs[] array.
[nmh] / uip / mhlsbr.c
index 5a6401e84ded06a599980df37d3d42fcc794d646..c56acff973cf8c236beb49a0b39e6eb3e02231f3 100644 (file)
@@ -94,7 +94,8 @@ DEFINE_SWITCH_ARRAY(MHL, mhlswitches);
 #define NOWRAP      0x040000   /* Don't wrap lines ever             */
 #define FMTFILTER   0x080000   /* Filter through format filter      */
 #define INVISIBLE   0x100000   /* count byte in display columns?    */
 #define NOWRAP      0x040000   /* Don't wrap lines ever             */
 #define FMTFILTER   0x080000   /* Filter through format filter      */
 #define INVISIBLE   0x100000   /* count byte in display columns?    */
-#define        LBITS   "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07CLEARSCR\010LEFTADJUST\011COMPRESS\012ADDRFMT\013BELL\014DATEFMT\015FORMAT\016INIT\017RTRIM\021SPLIT\022NONEWLINE\023NOWRAP\024FMTFILTER\025INVISIBLE"
+#define FORCE7BIT   0x200000   /* don't display 8-bit bytes         */
+#define        LBITS   "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07CLEARSCR\010LEFTADJUST\011COMPRESS\012ADDRFMT\013BELL\014DATEFMT\015FORMAT\016INIT\017RTRIM\021SPLIT\022NONEWLINE\023NOWRAP\024FMTFILTER\025INVISIBLE\026FORCE7BIT"
 #define        GFLAGS  (NOCOMPONENT | UPPERCASE | CENTER | LEFTADJUST | COMPRESS | SPLIT | NOWRAP)
 
 /*
 #define        GFLAGS  (NOCOMPONENT | UPPERCASE | CENTER | LEFTADJUST | COMPRESS | SPLIT | NOWRAP)
 
 /*
@@ -162,7 +163,7 @@ struct mcomp {
     int c_width;               /* width of field          */
     int c_cwidth;              /* width of component      */
     int c_length;              /* length in lines         */
     int c_width;               /* width of field          */
     int c_cwidth;              /* width of component      */
     int c_length;              /* length in lines         */
-    long c_flags;
+    unsigned long c_flags;
     struct mcomp *c_next;
 };
 
     struct mcomp *c_next;
 };
 
@@ -181,7 +182,7 @@ static struct mcomp holder = {
 
 struct pair {
     char *p_name;
 
 struct pair {
     char *p_name;
-    long p_flags;
+    unsigned long p_flags;
 };
 
 static struct pair pairs[] = {
 };
 
 static struct pair pairs[] = {
@@ -204,8 +205,8 @@ static struct pair pairs[] = {
 
 struct triple {
     char *t_name;
 
 struct triple {
     char *t_name;
-    long t_on;
-    long t_off;
+    unsigned long t_on;
+    unsigned long t_off;
 };
 
 static struct triple triples[] = {
 };
 
 static struct triple triples[] = {
@@ -323,14 +324,14 @@ static char *parse (void);
 static void process (char *, char *, int, int);
 static void mhlfile (FILE *, char *, int, int);
 static int mcomp_flags (char *);
 static void process (char *, char *, int, int);
 static void mhlfile (FILE *, char *, int, int);
 static int mcomp_flags (char *);
-static char *mcomp_add (long, char *, char *);
+static char *mcomp_add (unsigned long, char *, char *);
 static void mcomp_format (struct mcomp *, struct mcomp *);
 static struct mcomp *add_queue (struct mcomp **, struct mcomp **, char *, char *, int);
 static void free_queue (struct mcomp **, struct mcomp **);
 static void putcomp (struct mcomp *, struct mcomp *, int);
 static void mcomp_format (struct mcomp *, struct mcomp *);
 static struct mcomp *add_queue (struct mcomp **, struct mcomp **, char *, char *, int);
 static void free_queue (struct mcomp **, struct mcomp **);
 static void putcomp (struct mcomp *, struct mcomp *, int);
-static char *oneline (char *, long);
-static void putstr (char *, long);
-static void putch (char, long);
+static char *oneline (char *, unsigned long);
+static void putstr (char *, unsigned long);
+static void putch (char, unsigned long);
 static void intrser (int);
 static void pipeser (int);
 static void quitser (int);
 static void intrser (int);
 static void pipeser (int);
 static void quitser (int);
@@ -1126,7 +1127,7 @@ mcomp_flags (char *name)
 
 
 static char *
 
 
 static char *
-mcomp_add (long flags, char *s1, char *s2)
+mcomp_add (unsigned long flags, char *s1, char *s2)
 {
     char *dp;
 
 {
     char *dp;
 
@@ -1287,6 +1288,13 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag)
     char *trimmed_prefix;
     int count, cchdr;
     char *cp;
     char *trimmed_prefix;
     int count, cchdr;
     char *cp;
+    const int utf8 = strcasecmp(get_charset(), "UTF-8") == 0;
+
+    if (! utf8  &&  flag != BODYCOMP) {
+        /* Don't print 8-bit bytes in header field values if not in a
+           UTF-8 locale, as required by RFC 6532. */
+       c1->c_flags |= FORCE7BIT;
+    }
 
     text = c1->c_text ? c1->c_text : c1->c_name;
     /* Create a copy with trailing whitespace trimmed, for use with
 
     text = c1->c_text ? c1->c_text : c1->c_name;
     /* Create a copy with trailing whitespace trimmed, for use with
@@ -1406,7 +1414,7 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag)
 
 
 static char *
 
 
 static char *
-oneline (char *stuff, long flags)
+oneline (char *stuff, unsigned long flags)
 {
     int spc;
     char *cp, *ret;
 {
     int spc;
     char *cp, *ret;
@@ -1458,7 +1466,7 @@ oneline (char *stuff, long flags)
 
 
 static void
 
 
 static void
-putstr (char *string, long flags)
+putstr (char *string, unsigned long flags)
 {
     /* To not count, for the purpose of counting columns, all of
        the bytes of a multibyte character. */
 {
     /* To not count, for the purpose of counting columns, all of
        the bytes of a multibyte character. */
@@ -1478,7 +1486,7 @@ putstr (char *string, long flags)
     lm = 0;
 
 #ifdef MULTIBYTE_SUPPORT
     lm = 0;
 
 #ifdef MULTIBYTE_SUPPORT
-    (void) mbtowc (NULL, NULL, 0); /* reset shift state */
+    if (mbtowc (NULL, NULL, 0)) {} /* reset shift state */
     char_len = 0;
 #else
     NMH_UNUSED (char_len);
     char_len = 0;
 #else
     NMH_UNUSED (char_len);
@@ -1507,7 +1515,7 @@ putstr (char *string, long flags)
 
 
 static void
 
 
 static void
-putch (char ch, long flags)
+putch (char ch, unsigned long flags)
 {
     char buf[BUFSIZ];
 
 {
     char buf[BUFSIZ];
 
@@ -1561,9 +1569,24 @@ putch (char ch, long flags)
                putchar ('-');
                putchar (' ');
            }
                putchar ('-');
                putchar (' ');
            }
-            if ((flags & INVISIBLE) == 0) {
-                /* If multibyte character, its first byte only. */
-                ++column;
+            /*
+             * Increment the character count, unless
+             * 1) In UTF-8 locale, this is other than the last byte of
+                  a multibyte character, or
+             * 2) In C locale, will print a non-printable character.
+             */
+            if ((flags & FORCE7BIT) == 0) {
+                /* UTF-8 locale */
+                if ((flags & INVISIBLE) == 0) {
+                    /* If multibyte character, its first byte only. */
+                    ++column;
+                }
+            } else {
+                /* If not an ASCII character, the replace character will be
+                   displayed.  Count it. */
+                if (! isascii((unsigned char) ch) || isprint((unsigned char) ch)) {
+                    ++column;
+                }
             }
            break;
     }
             }
            break;
     }
@@ -1577,7 +1600,11 @@ putch (char ch, long flags)
        return;
     }
 
        return;
     }
 
-    putchar (ch);
+    if (flags & FORCE7BIT  &&  ! isascii((unsigned char) ch)) {
+        putchar ('?');
+    } else {
+        putchar (ch);
+    }
 }
 
 
 }