bug-gettext
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gettext] Debian Bug#872869: msgfmt: trailing null bytes in head


From: Daiki Ueno
Subject: Re: [bug-gettext] Debian Bug#872869: msgfmt: trailing null bytes in header's msgstr
Date: Tue, 05 Sep 2017 17:36:38 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Bruno Haible <address@hidden> writes:

>>   $ msgunfmt /usr/share/locale/pl/LC_MESSAGES/gettext-runtime.mo | msgfmt -
>>   $ i18nspector messages.mo
>>   E: messages.mo: invalid-mo-file unexpected null byte in msgstr
>
> Thanks for this report! Fixed through
> http://git.savannah.gnu.org/gitweb/?p=gettext.git;a=commitdiff;h=2bad4d89684303fe884410ab0ae53770df6a6093

Although it was reported against an unreleased version, can we have a
test case for this to prevent similar issue happening in the future?

Regards,
-- 
Daiki Ueno
>From 01d82c6ed523b0c44ad4ae4e2935e4d0072abb86 Mon Sep 17 00:00:00 2001
From: Daiki Ueno <address@hidden>
Date: Tue, 5 Sep 2017 16:14:03 +0200
Subject: [PATCH] Add test for "Avoid extraneous NUL bytes in .mo files" change

* gettext-tools/src/read-mo.c: Include "msgunfmt.h".
(get_string): Print warning if a string is followed by an extraneous
NUL character.
* gettext-tools/tests/msgfmt-19: Check if extraneous NUL character is
not included in the output.
---
 gettext-tools/src/read-mo.c   | 5 +++++
 gettext-tools/tests/msgfmt-19 | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/gettext-tools/src/read-mo.c b/gettext-tools/src/read-mo.c
index 9ddd6b2d2..37d7ca291 100644
--- a/gettext-tools/src/read-mo.c
+++ b/gettext-tools/src/read-mo.c
@@ -29,6 +29,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "msgunfmt.h"
+
 /* This include file describes the main part of binary .mo format.  */
 #include "gmo.h"
 
@@ -131,6 +133,9 @@ get_string (const struct binary_mo_file *bfp, size_t 
offset, size_t *lengthp)
     error (EXIT_FAILURE, 0,
            _("file \"%s\" contains a not NUL terminated string"),
            bfp->filename);
+  if (s_length > 0 && bfp->data[s_offset + s_length - 1] == '\0' && verbose)
+    error (0, 0, _("file \"%s\" contains an extraneous NUL character"),
+           bfp->filename);
 
   *lengthp = s_length + 1;
   return bfp->data + s_offset;
diff --git a/gettext-tools/tests/msgfmt-19 b/gettext-tools/tests/msgfmt-19
index 76d4a739d..043456332 100755
--- a/gettext-tools/tests/msgfmt-19
+++ b/gettext-tools/tests/msgfmt-19
@@ -56,6 +56,11 @@ EOF
 ${MSGFMT} -o mf-19-1.mo mf-19-1.po 2>/dev/null
 test $? = 0 || { Exit 1; }
 
+: ${MSGUNFMT=msgunfmt}
+LC_ALL=C \
+${MSGUNFMT} -v -o mf-19-1.tmp mf-19-1.mo 2> mf-19.err > /dev/null || Exit 1
+grep -v 'contains an extraneous NUL character' mf-19.err && Exit 1
+
 : ${MSGFMT=msgfmt}
 ${MSGFMT} -o mf-19-2.mo mf-19-2.po 2>/dev/null
 test $? = 0 || { Exit 1; }
-- 
2.13.5


reply via email to

[Prev in Thread] Current Thread [Next in Thread]