From: Bruno Haible Date: Wed, 15 Mar 2023 21:47:47 +0000 (+0100) Subject: xgettext: In language Perl, avoid a crash. X-Git-Tag: v0.22~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eea9d109d1eb81d5ea2e5e63848d9b123073a238;p=thirdparty%2Fgettext.git xgettext: In language Perl, avoid a crash. * gettext-tools/src/xg-arglist-parser.c (arglist_parser_clone): Clone the msgid_pos correctly. * gettext-tools/tests/xgettext-perl-10: New file. * gettext-tools/tests/Makefile.am (TESTS): Add it. --- diff --git a/gettext-tools/src/xg-arglist-parser.c b/gettext-tools/src/xg-arglist-parser.c index d9795eb2d..c41e92116 100644 --- a/gettext-tools/src/xg-arglist-parser.c +++ b/gettext-tools/src/xg-arglist-parser.c @@ -1,6 +1,6 @@ /* Resolving ambiguity of argument lists: Progressive parsing of an argument list, keeping track of all possibilities. - Copyright (C) 2001-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2023 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -130,7 +130,7 @@ arglist_parser_clone (struct arglist_parser *ap) ccp->msgctxt_pos = cp->msgctxt_pos; ccp->msgid = (cp->msgid != NULL ? mixed_string_clone (cp->msgid) : NULL); ccp->msgid_context = cp->msgid_context; - ccp->msgid_pos = cp->msgctxt_pos; + ccp->msgid_pos = cp->msgid_pos; ccp->msgid_comment = add_reference (cp->msgid_comment); ccp->msgid_comment_is_utf8 = cp->msgid_comment_is_utf8; ccp->msgid_plural = diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 6b30f9a00..4670cad9d 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -130,7 +130,7 @@ TESTS = gettext-1 gettext-2 \ xgettext-objc-1 xgettext-objc-2 \ xgettext-perl-1 xgettext-perl-2 xgettext-perl-3 xgettext-perl-4 \ xgettext-perl-5 xgettext-perl-6 xgettext-perl-7 xgettext-perl-8 \ - xgettext-perl-9 \ + xgettext-perl-9 xgettext-perl-10 \ xgettext-perl-stackovfl-1 xgettext-perl-stackovfl-2 \ xgettext-perl-stackovfl-3 xgettext-perl-stackovfl-4 \ xgettext-php-1 xgettext-php-2 xgettext-php-3 xgettext-php-4 \ diff --git a/gettext-tools/tests/xgettext-perl-10 b/gettext-tools/tests/xgettext-perl-10 new file mode 100755 index 000000000..d4f21ed78 --- /dev/null +++ b/gettext-tools/tests/xgettext-perl-10 @@ -0,0 +1,26 @@ +#! /bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test of Perl support: ngettext invocation that used to trigger a crash. + +cat <<\EOF > xg-pl-10.pl +ngettext p=>(" +EOF + +: ${XGETTEXT=xgettext} +${XGETTEXT} --omit-header -n -d xg-pl-10.tmp xg-pl-10.pl || Exit 1 +LC_ALL=C tr -d '\r' < xg-pl-10.tmp.po > xg-pl-10.po || Exit 1 + +cat <<\EOF > xg-pl-10.ok +#: xg-pl-10.pl:1 +msgid "p" +msgid_plural "\n" +msgstr[0] "" +msgstr[1] "" +EOF + +: ${DIFF=diff} +${DIFF} xg-pl-10.ok xg-pl-10.po +result=$? + +exit $result