]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Fix a report by an undefined-behaviour sanitizer.
authorBruno Haible <bruno@clisp.org>
Fri, 10 Apr 2020 19:19:36 +0000 (21:19 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 13 Apr 2020 11:39:02 +0000 (13:39 +0200)
Reported by Jeffrey Walton <noloader@gmail.com> in
<https://lists.gnu.org/archive/html/bug-gettext/2020-01/msg00029.html>.

* gettext-tools/src/read-properties.c (read_escaped_string): Don't call memcpy
with a NULL argument.

gettext-tools/src/read-properties.c

index 8b6c84a04808ebdf89336292d5dc4d4dae9df027..4dcb8aaeb71e049ba6da3749f0f96119f94fa39e 100644 (file)
@@ -1,5 +1,5 @@
 /* Reading Java .properties files.
-   Copyright (C) 2003, 2005-2007, 2009, 2018 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2005-2007, 2009, 2018, 2020 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2003.
 
    This program is free software: you can redistribute it and/or modify
@@ -582,7 +582,8 @@ read_escaped_string (bool in_key)
   /* Return the result.  */
   {
     unsigned char *utf8_string = XNMALLOC (utf8_buflen + 1, unsigned char);
-    memcpy (utf8_string, utf8_buffer, utf8_buflen);
+    if (utf8_buflen > 0)
+      memcpy (utf8_string, utf8_buffer, utf8_buflen);
     utf8_string[utf8_buflen] = '\0';
 
     return (char *) utf8_string;