Mercurial > gnulib
changeset 40212:8da9577294da
unistr/*, uniconv/*: Fix undefined behaviour.
Reported by Jeffrey Walton <noloader@gmail.com>.
* 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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 09 Mar 2019 00:01:47 +0100 |
parents | 5f58d2ac35ea |
children | cc3fed3b7788 |
files | ChangeLog lib/uniconv/u8-conv-from-enc.c lib/uniconv/u8-conv-to-enc.c lib/unistr/u-cpy-alloc.h lib/unistr/u-cpy.h |
diffstat | 5 files changed, 17 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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 <bruno@clisp.org> + + unistr/*, uniconv/*: Fix undefined behaviour. + Reported by Jeffrey Walton <noloader@gmail.com>. + * 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 <bruno@clisp.org> unistr/u8-cmp: Fix undefined behaviour.
--- 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; }
--- 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; }
--- 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;
--- 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; }