# HG changeset patch # User Bruno Haible # Date 1552086107 -3600 # Node ID 8da9577294dafd839a9561ab164efa95c6def786 # Parent 5f58d2ac35ea2fc31ccc90cb6d21b8327ce30986 unistr/*, uniconv/*: Fix undefined behaviour. Reported by Jeffrey Walton . * lib/unistr/u-cpy.h (FUNC): Don't invoke memcpy with a zero size. * lib/unistr/u-cpy-alloc.h (FUNC): Likewise. * lib/uniconv/u8-conv-from-enc.c (u8_conv_from_encoding): Likewise. * lib/uniconv/u8-conv-to-enc.c (u8_conv_to_encoding): Likewise. diff -r 5f58d2ac35ea -r 8da9577294da ChangeLog --- a/ChangeLog Fri Mar 08 20:38:22 2019 +0100 +++ b/ChangeLog Sat Mar 09 00:01:47 2019 +0100 @@ -1,3 +1,12 @@ +2019-03-08 Bruno Haible + + unistr/*, uniconv/*: Fix undefined behaviour. + Reported by Jeffrey Walton . + * lib/unistr/u-cpy.h (FUNC): Don't invoke memcpy with a zero size. + * lib/unistr/u-cpy-alloc.h (FUNC): Likewise. + * lib/uniconv/u8-conv-from-enc.c (u8_conv_from_encoding): Likewise. + * lib/uniconv/u8-conv-to-enc.c (u8_conv_to_encoding): Likewise. + 2019-03-08 Bruno Haible unistr/u8-cmp: Fix undefined behaviour. diff -r 5f58d2ac35ea -r 8da9577294da lib/uniconv/u8-conv-from-enc.c --- a/lib/uniconv/u8-conv-from-enc.c Fri Mar 08 20:38:22 2019 +0100 +++ b/lib/uniconv/u8-conv-from-enc.c Sat Mar 09 00:01:47 2019 +0100 @@ -77,7 +77,8 @@ } } - memcpy ((char *) result, src, srclen); + if (srclen > 0) + memcpy ((char *) result, src, srclen); *lengthp = srclen; return result; } diff -r 5f58d2ac35ea -r 8da9577294da lib/uniconv/u8-conv-to-enc.c --- a/lib/uniconv/u8-conv-to-enc.c Fri Mar 08 20:38:22 2019 +0100 +++ b/lib/uniconv/u8-conv-to-enc.c Sat Mar 09 00:01:47 2019 +0100 @@ -60,7 +60,8 @@ } } - memcpy (result, (const char *) src, srclen); + if (srclen > 0) + memcpy (result, (const char *) src, srclen); *lengthp = srclen; return result; } diff -r 5f58d2ac35ea -r 8da9577294da lib/unistr/u-cpy-alloc.h --- a/lib/unistr/u-cpy-alloc.h Fri Mar 08 20:38:22 2019 +0100 +++ b/lib/unistr/u-cpy-alloc.h Sat Mar 09 00:01:47 2019 +0100 @@ -33,7 +33,8 @@ for (; n > 0; n--) *destptr++ = *s++; #else - memcpy ((char *) dest, (const char *) s, n * sizeof (UNIT)); + if (n > 0) + memcpy ((char *) dest, (const char *) s, n * sizeof (UNIT)); #endif } return dest; diff -r 5f58d2ac35ea -r 8da9577294da lib/unistr/u-cpy.h --- a/lib/unistr/u-cpy.h Fri Mar 08 20:38:22 2019 +0100 +++ b/lib/unistr/u-cpy.h Sat Mar 09 00:01:47 2019 +0100 @@ -26,7 +26,8 @@ for (; n > 0; n--) *destptr++ = *src++; #else - memcpy ((char *) dest, (const char *) src, n * sizeof (UNIT)); + if (n > 0) + memcpy ((char *) dest, (const char *) src, n * sizeof (UNIT)); #endif return dest; }