diff options
author | Takuji Tanaka <ttk@t-lab.opal.ne.jp> | 2021-08-25 13:55:11 +0000 |
---|---|---|
committer | Takuji Tanaka <ttk@t-lab.opal.ne.jp> | 2021-08-25 13:55:11 +0000 |
commit | daad571338123052e0466c3e59cb183fe12aeb67 (patch) | |
tree | 385437f1898a6b2b6fc5a54c415f97ea64342958 /Build/source | |
parent | 0052fcfc5c7b6a85b5f9cb128c299effd52c6ebb (diff) |
upmendex: initialize string, check malformed input
git-svn-id: svn://tug.org/texlive/trunk@60319 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source')
-rw-r--r-- | Build/source/texk/upmendex/ChangeLog | 7 | ||||
-rw-r--r-- | Build/source/texk/upmendex/sort.c | 23 | ||||
-rw-r--r-- | Build/source/texk/upmendex/tests/rule3.ist | 4 | ||||
-rw-r--r-- | Build/source/texk/upmendex/tests/rule4.ist | 4 | ||||
-rwxr-xr-x | Build/source/texk/upmendex/tests/upmendex.test | 19 |
5 files changed, 50 insertions, 7 deletions
diff --git a/Build/source/texk/upmendex/ChangeLog b/Build/source/texk/upmendex/ChangeLog index a613c67f878..9bbb750dfda 100644 --- a/Build/source/texk/upmendex/ChangeLog +++ b/Build/source/texk/upmendex/ChangeLog @@ -1,3 +1,10 @@ +2021-08-25 TANAKA Takuji <ttk@t-lab.opal.ne.jp> + + * sort.c: + Initialize a string. Check malformed input for "icu_rules". + * tests/upmendex.test, tests/rule[34].ist: + Add new tests. + 2021-08-23 TANAKA Takuji <ttk@t-lab.opal.ne.jp> * tests/upmendex.test, tests/rule[12].ist, tests/rule.{idx,ind}: diff --git a/Build/source/texk/upmendex/sort.c b/Build/source/texk/upmendex/sort.c index e3a47c12b72..38b64feeebc 100644 --- a/Build/source/texk/upmendex/sort.c +++ b/Build/source/texk/upmendex/sort.c @@ -17,7 +17,7 @@ void wsort(struct index *ind, int num) { int i,order; UErrorCode status; - UChar rules[STYBUFSIZE]; + UChar rules[STYBUFSIZE] = {'\0'}; for (order=1,i=0;;i++) { switch (character_order[i]) { @@ -324,10 +324,11 @@ static int get_charset_juncture(UChar *str) } } -static int unescape(const unsigned char *src, UChar *dist) +static int unescape(const unsigned char *src, UChar *dest) { - int i,j,k; + int i,j,k,ret; char tmp[STYBUFSIZE]; + UErrorCode status; for (i=j=0;i<STYBUFSIZE;i++) { if (src[i]=='\0') { @@ -336,15 +337,23 @@ static int unescape(const unsigned char *src, UChar *dist) else if (src[i]< 0x80 && (src[i+1]>=0x80 || src[i+1]=='\0')) { strncpy(tmp,(char *)&src[j],i-j+1); tmp[i-j+1]='\0'; - k=u_strlen(dist); - u_unescape(tmp, &dist[k], STYBUFSIZE-k); + k=u_strlen(dest); + ret=u_unescape(tmp, &dest[k], STYBUFSIZE-k); + if (ret==0) { + verb_printf(efp, "\n[ICU] Escape sequence in input seems malformed.\n"); + exit(254); + } j=i+1; } else if (src[i]>=0x80 && (src[i+1]< 0x80 || src[i+1]=='\0')) { strncpy(tmp,(char *)&src[j],i-j+1); tmp[i-j+1]='\0'; - k=u_strlen(dist); - multibyte_to_widechar(&dist[k], STYBUFSIZE-k, tmp); + k=u_strlen(dest); + u_strFromUTF8(&dest[k], STYBUFSIZE-k, NULL, tmp, -1, &status); + if (U_FAILURE(status)) { + verb_printf(efp, "\n[ICU] Input string seems malformed.: %s\n", u_errorName(status)); + exit(254); + } j=i+1; } } diff --git a/Build/source/texk/upmendex/tests/rule3.ist b/Build/source/texk/upmendex/tests/rule3.ist new file mode 100644 index 00000000000..7ab835a8016 --- /dev/null +++ b/Build/source/texk/upmendex/tests/rule3.ist @@ -0,0 +1,4 @@ +% -*- coding: latin-1 -*- +% To test malformed input + +icu_rules "&a<<<A<C<<Ç<<c<<ç<u<<U<<ü<<Ü<b<<B" diff --git a/Build/source/texk/upmendex/tests/rule4.ist b/Build/source/texk/upmendex/tests/rule4.ist new file mode 100644 index 00000000000..0c30dceba23 --- /dev/null +++ b/Build/source/texk/upmendex/tests/rule4.ist @@ -0,0 +1,4 @@ +% -*- coding: utf-8 -*- +% To test malformed input + +icu_rules "&a<<<A<C<<\U000000c7<<c<<\uE7<u<<U<<\x{fc}<<\xDC<b<<B" diff --git a/Build/source/texk/upmendex/tests/upmendex.test b/Build/source/texk/upmendex/tests/upmendex.test index e9263997824..59074579b24 100755 --- a/Build/source/texk/upmendex/tests/upmendex.test +++ b/Build/source/texk/upmendex/tests/upmendex.test @@ -55,3 +55,22 @@ cat $srcdir/tests/uni.idx | \ -o rule2.ind1 -t rule2.ilg \ && diff $srcdir/tests/rule.ind rule2.ind1 || exit 1 +# malformed input +./upmendex -s $srcdir/tests/uni.ist -s $srcdir/tests/rule3.ist $srcdir/tests/rule.idx \ + -o rule3.ind1 -t rule3.ilg +if [ $? -eq 254 ]; then + echo "Error check: OK" +else + echo "Error check: NG" + exit 1 +fi + +./upmendex -s $srcdir/tests/uni.ist -s $srcdir/tests/rule4.ist $srcdir/tests/rule.idx \ + -o rule4.ind1 -t rule4.ilg +if [ $? -eq 254 ]; then + echo "Error check: OK" +else + echo "Error check: NG" + exit 1 +fi + |