[PATCH] Fix

Jeremy Allison jra at samba.org
Wed Feb 1 00:10:59 UTC 2017


On Tue, Jan 31, 2017 at 06:01:43PM +0100, Andreas Schneider wrote:
> Hello,
> 
> the samba4.local.iconv test fails on newer glibc version (>= glibc-2.24, 
> Fedora 25, openSUSE Tumbleweed)
> 
> 
> test: 5M random UTF-16LE sequences
> time: 2017-01-31 16:54:17.914315
>  rem1: 30 df
>  rem2: 30 df
> i=159 failed UTF-8
> time: 2017-01-31 16:54:17.916137
> failure: 5M random UTF-16LE sequences [
> ../lib/util/charset/tests/iconv.c:225: errno mismatch with UTF-8 internal=22/
> Invalid argument system=84/Invalid or incomplete multibyte or wide character
> ]
> 
> 
> The attached patch checks the return code and choses the appropriate one to 
> return.
> 
> 
> Review and push much appreciated!

LGTM. Pushed !

> 
> 
> 	Andreas
> 
> 
> -- 
> Andreas Schneider                   GPG-ID: CC014E3D
> Samba Team                             asn at samba.org
> www.samba.org

> From 2e91f666900501187c67b259565a964f790a1d94 Mon Sep 17 00:00:00 2001
> From: Andreas Schneider <asn at samba.org>
> Date: Mon, 30 Jan 2017 17:17:38 +0100
> Subject: [PATCH] util:charset: Return EILSEQ in smb_iconv() if newer libc is
>  detected
> 
> This is the behaviour of glibc 2.24 and newer.
> 
> Signed-off-by: Andreas Schneider <asn at samba.org>
> ---
>  lib/util/charset/iconv.c           |  6 +++---
>  lib/util/charset/wscript_configure | 20 ++++++++++++++++++++
>  2 files changed, 23 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/util/charset/iconv.c b/lib/util/charset/iconv.c
> index bf561f26619..e06fa2ca396 100644
> --- a/lib/util/charset/iconv.c
> +++ b/lib/util/charset/iconv.c
> @@ -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;
>  		}
>  
> diff --git a/lib/util/charset/wscript_configure b/lib/util/charset/wscript_configure
> index 804c2663f64..d5ac5d0100f 100644
> --- a/lib/util/charset/wscript_configure
> +++ b/lib/util/charset/wscript_configure
> @@ -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')
> -- 
> 2.11.0
> 




More information about the samba-technical mailing list