util:charset: Return EILSEQ in smb_iconv() if newer libc is detected
authorAndreas Schneider <asn@samba.org>
Mon, 30 Jan 2017 16:17:38 +0000 (17:17 +0100)
committerJeremy Allison <jra@samba.org>
Wed, 1 Feb 2017 04:16:46 +0000 (05:16 +0100)
This is the behaviour of glibc 2.24 and newer.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Wed Feb  1 05:16:46 CET 2017 on sn-devel-144

lib/util/charset/iconv.c
lib/util/charset/wscript_configure

index bf561f26619d9764213dbf705e69942f9f996d23..e06fa2ca3962829f3e9139d4acaa6477175d5f6b 100644 (file)
@@ -740,12 +740,12 @@ static size_t utf8_push(void *cd, const char **inbuf, size_t *inbytesleft,
                }
 
                if ((uc[1] & 0xfc) == 0xdc) {
-                       /* its the second part of a 4 byte sequence. Illegal */
+                       errno = EILSEQ;
+#ifndef HAVE_ICONV_ERRNO_ILLEGAL_MULTIBYTE
                        if (in_left < 4) {
                                errno = EINVAL;
-                       } else {
-                               errno = EILSEQ;
                        }
+#endif
                        goto error;
                }
 
index 804c2663f640cc361c22a2446615eab1ae2c8c1f..d5ac5d0100f74d457bf2593e3141c80788c4a23d 100644 (file)
@@ -16,3 +16,23 @@ if (conf.CHECK_FUNCS_IN('iconv_open', 'iconv', checklibc=False, headers='iconv.h
     conf.CHECK_FUNCS('iconv_open', headers='iconv.h')):
     
     conf.DEFINE('HAVE_NATIVE_ICONV', 1)
+
+conf.CHECK_CODE('''
+                uint8_t inbuf[2] = { 0x30, 0xdf };
+                uint8_t outbuf[4] = { 0 };
+                char *ptr_in = (char *)inbuf;
+                char *ptr_out = (char *)outbuf;
+                size_t size_in = sizeof(inbuf);
+                size_t size_out = sizeof(outbuf);
+                size_t ret;
+                iconv_t cd;
+                cd = iconv_open("UTF-8", "UTF-16LE");
+                if (cd == 0 || cd == (iconv_t)-1) return -1;
+                ret = iconv(cd, &ptr_in, &size_in, &ptr_out, &size_out);
+                if (ret != (size_t)-1 || errno != EILSEQ) return -1;
+                ''',
+                define='HAVE_ICONV_ERRNO_ILLEGAL_MULTIBYTE',
+                execute=True,
+                msg='Checking errno of iconv for illegal multibyte sequence',
+                lib='iconv',
+                headers='errno.h iconv.h')