From: Bruno Haible Date: Thu, 11 Sep 2003 17:07:33 +0000 (+0000) Subject: Make handling of out-of-range Unicode characters consistent with the handling X-Git-Tag: v0.13~260 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=049344392b6e428c33366c03b5da7dd8595b17fe;p=thirdparty%2Fgettext.git Make handling of out-of-range Unicode characters consistent with the handling of invalid multibyte sequences. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 150aacd42..190e7ed39 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,7 +1,7 @@ 2003-09-11 Bruno Haible - * po-lex.c (mbfile_getc): Ignore the return value of u8_mbtouc(). - Reported by Jochen Hein . + * po-lex.c (mbfile_getc): Handle unexpected return value of + u8_mbtouc(). Reported by Jochen Hein . 2003-09-09 Bruno Haible diff --git a/gettext-tools/src/po-lex.c b/gettext-tools/src/po-lex.c index c0b7df2e1..9564e2b29 100644 --- a/gettext-tools/src/po-lex.c +++ b/gettext-tools/src/po-lex.c @@ -510,12 +510,16 @@ incomplete multibyte sequence at end of line")); if (outbytes == 0) abort (); /* Convert it from UTF-8 to UCS-4. */ + if (u8_mbtouc (&mbc->uc, scratchbuf, outbytes) < outbytes) + { + /* scratchbuf contains an out-of-range Unicode character + (> 0x10ffff). */ + if (signal_eilseq) + po_gram_error (_("invalid multibyte sequence")); + mbc->uc_valid = false; + break; + } mbc->uc_valid = true; - /* We ignore the return value of u8_mbtouc(): Usually it returns - outbytes, but if scratchbuf contains an out-of-range Unicode - character (> 0x10ffff), it can also return 1 and set mbc->uc - to 0xfffd. This is precisely what we need. */ - u8_mbtouc (&mbc->uc, scratchbuf, outbytes); break; } } diff --git a/gettext-tools/tests/msgfmt-14 b/gettext-tools/tests/msgfmt-14 index 61b03ebdf..08d2b1db3 100755 --- a/gettext-tools/tests/msgfmt-14 +++ b/gettext-tools/tests/msgfmt-14 @@ -30,8 +30,12 @@ EOF tmpfiles="$tmpfiles mf-test14.mo" : ${MSGFMT=msgfmt} -${MSGFMT} mf-test14.po -o mf-test14.mo -test $? = 0 || { rm -fr $tmpfiles; exit 1; } +${MSGFMT} mf-test14.po -o mf-test14.mo 2>/dev/null +# Exit code must be 1. +# If the invalid sequence didn't get noticed, it would be 0. +# If it produced a core dump, it would be 134 (= 128 + SIGABRT). +test $? = 1 +result=$? rm -fr $tmpfiles