nmh-workers
[Top] [All Lists]

Re: [Nmh-workers] mhshow(1) iconv(3) Bug if Multibyte Straddles Buffer End.

2016-10-15 10:49:38
Ralph wrote:

1.6's mhshow(1) says

Might Ken's commit adfed5f72bc07ac7de8dfc62188338d4d4f25a38
have fixed this?

I took a look at mhshowsbr.c's convert_charset() and I think it's
failing to handle an EINVAL return.

That commit adds handling of EINVAL and EISLEQ, relevant portion of
the diff is below.

David

+       if (errno == EINVAL) {
+           /* middle of multi-byte sequence */
+           if (write (fd, dest_buffer, outbytes_before - outbytes) < 0) {
+               advise (dest, "write");
+           }
+           fseeko (*fp, -inbytes, SEEK_CUR);
+           if (end > 0) bytes_to_read += inbytes;
+           /* advise(NULL, "convert_charset: EINVAL"); */
+           continue;
+       }
+       if (errno == EILSEQ) {
+           /* invalid multi-byte sequence */
+           if (fromutf8) {
+               for (++ib, --inbytes;
+                    inbytes > 0 &&
+                           (((unsigned char) *ib) & 0xc0) == 0x80;
+                    ++ib, --inbytes)
+                   continue;
+           } else {
+               ib++; inbytes--; /* skip it */
+           }
+           (*ob++) = '?'; outbytes --;
+           /* advise(NULL, "convert_charset: EILSEQ"); */
+           goto iconv_start;
+       }
+       advise (NULL, "convert_charset: errno = %d", errno);

_______________________________________________
Nmh-workers mailing list
Nmh-workers(_at_)nongnu(_dot_)org
https://lists.nongnu.org/mailman/listinfo/nmh-workers

<Prev in Thread] Current Thread [Next in Thread>