]> Savannah Git Hosting - gnulib.git/commitdiff
Fix undefined behaviour in gettext.h.
authorBruno Haible <bruno@clisp.org>
Mon, 9 May 2016 07:29:35 +0000 (09:29 +0200)
committerDaiki Ueno <ueno@gnu.org>
Thu, 12 May 2016 07:33:09 +0000 (16:33 +0900)
* lib/gettext.h (dcpgettext_expr, dcnpgettext_expr): Avoid accessing a
pointer's value after the storage it points to has been freed.
Reported by Michael Pyne in https://savannah.gnu.org/bugs/?47847.
Spotted by Coverity.

ChangeLog
lib/gettext.h

index fe747e52c43d77d75560847ff7817c74e12c29e4..a8ba38ef7b353daad5b3c22f4a3ab47f0ee556c0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2016-05-09  Bruno Haible  <bruno@clisp.org>
+
+       Fix undefined behaviour in gettext.h.
+       * lib/gettext.h (dcpgettext_expr, dcnpgettext_expr): Avoid accessing a
+       pointer's value after the storage it points to has been freed.
+       Reported by Michael Pyne in https://savannah.gnu.org/bugs/?47847.
+       Spotted by Coverity.
+
 2016-05-08  Paul Eggert  <eggert@cs.ucla.edu>
 
        git-version-gen: avoid undefined shift
index 3acc6a6eb827549597756e0e603a7b866d07e9a9..d26b8b4a1ce4726aac459706a723625e77a534ef 100644 (file)
@@ -225,15 +225,17 @@ dcpgettext_expr (const char *domain,
   if (msg_ctxt_id != NULL)
 #endif
     {
+      int found_translation;
       memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
       msg_ctxt_id[msgctxt_len - 1] = '\004';
       memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
       translation = dcgettext (domain, msg_ctxt_id, category);
+      found_translation = (translation != msg_ctxt_id);
 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
       if (msg_ctxt_id != buf)
         free (msg_ctxt_id);
 #endif
-      if (translation != msg_ctxt_id)
+      if (found_translation)
         return translation;
     }
   return msgid;
@@ -271,15 +273,17 @@ dcnpgettext_expr (const char *domain,
   if (msg_ctxt_id != NULL)
 #endif
     {
+      int found_translation;
       memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
       msg_ctxt_id[msgctxt_len - 1] = '\004';
       memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
       translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
+      found_translation = !(translation == msg_ctxt_id || translation == msgid_plural);
 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
       if (msg_ctxt_id != buf)
         free (msg_ctxt_id);
 #endif
-      if (!(translation == msg_ctxt_id || translation == msgid_plural))
+      if (found_translation)
         return translation;
     }
   return (n == 1 ? msgid : msgid_plural);