hnj_hyphen_hyphword: add test to detect overflows

This commit is contained in:
Bartek Fabiszewski 2017-04-28 10:10:59 +02:00
parent 4e09ea69d6
commit 568e5f92b3
6 changed files with 26 additions and 1 deletions

View File

@ -67,7 +67,7 @@ main(int argc, char** argv)
char *hyphens;
char *lcword;
char *hyphword;
char hword[BUFSIZE * 2];
char *hword;
int arg = 1;
int optd = 1;
int optn = 0;
@ -151,12 +151,16 @@ main(int argc, char** argv)
rep = NULL;
pos = NULL;
cut = NULL;
/* set minimum required output buffer size (2 * word_size) */
hword = (char *) malloc((n-1)*2);
hword[0] = '\0';
if ((!optd && hnj_hyphen_hyphenate(dict, lcword, n-1, hyphens)) ||
(optd && hnj_hyphen_hyphenate2(dict, lcword, n-1, hyphens, hword, &rep, &pos, &cut))) {
free(hyphens);
free(lcword);
free(hword);
fprintf(stderr, "hyphenation error\n");
exit(1);
}
@ -202,6 +206,7 @@ main(int argc, char** argv)
}
free(hyphens);
free(lcword);
free(hword);
}
fclose(wtclst);

View File

@ -10,6 +10,7 @@ alt3.test \
alt4.test \
alt5.test \
alt6.test \
alt7.test \
compound.test \
compound2.test \
compound3.test \
@ -46,6 +47,9 @@ alt5.word \
alt6.hyph \
alt6.pat \
alt6.word \
alt7.hyph \
alt7.pat \
alt7.word \
alt.hyph \
alt.pat \
alt.word \
@ -100,6 +104,7 @@ alt3.test \
alt4.test \
alt5.test \
alt6.test \
alt7.test \
alt.test \
basealt2.test \
basealt.test \

2
tests/alt7.hyph Normal file
View File

@ -0,0 +1,2 @@
b=bbbbbbbbbbbbbbbbbbbbbba=a=a=a=a=a=a=a=a=a=a=a=a=a=a=a
b=bbbbbbbbbbbbbbbbbbbbbba=b=bbbbbbbbbbbbbbbbbbbbbba=b=b

7
tests/alt7.pat Normal file
View File

@ -0,0 +1,7 @@
ISO8859-1
LEFTHYPHENMIN 1
RIGHTHYPHENMIN 1
% Check for buffer overflows
.a1b.
a9a
ab3a/b=bbbbbbbbbbbbbbbbbbbbbb,1,2

4
tests/alt7.test Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
DIR="`dirname $0`"
NAME="`basename $0 .test`"
$DIR/test.sh $NAME.pat $NAME.word $NAME.hyph

2
tests/alt7.word Normal file
View File

@ -0,0 +1,2 @@
abaaaaaaaaaaaaaaaaaaaaaaaaaa
abaabaababababababababababab