1 From 97e079a23d459aeb6e64435350d7710c90dbca85 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
3 Date: Fri, 11 Sep 2015 13:28:52 +0100
4 Subject: [PATCH] Resolves: rhbz#1261421 crash on mashing hangul korean
8 src/hunspell/hunspell.cxx | 69 +++++++++++++++++++++++++++++++++++------------
9 src/hunspell/hunspell.hxx | 4 ++-
10 src/hunspell/replist.cxx | 18 ++++++++++---
11 src/hunspell/replist.hxx | 2 ++
12 src/tools/hunspell.cxx | 2 +-
13 6 files changed, 78 insertions(+), 24 deletions(-)
15 diff --git a/src/hunspell/hunspell.cxx b/src/hunspell/hunspell.cxx
16 index 7fae54b..d8ef357 100644
17 --- misc/hunspell-1.3.3/src/hunspell/hunspell.cxx
18 +++ misc/build/hunspell-1.3.3/src/hunspell/hunspell.cxx
26 Hunspell::Hunspell(const char * affpath, const char * dpath, const char * key)
27 @@ -349,8 +350,13 @@ int Hunspell::spell(const char * word, int * info, char ** root)
30 RepList * rl = (pAMgr) ? pAMgr->get_iconvtable() : NULL;
31 - if (rl && rl->conv(word, wspace)) wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
32 - else wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
33 + int convstatus = rl ? rl->conv(word, wspace, MAXWORDUTF8LEN) : 0;
36 + else if (convstatus > 0)
37 + wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
39 + wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
41 if (wl == 0 || maxdic == 0) return 1;
42 if (root) *root = NULL;
43 @@ -702,8 +708,13 @@ int Hunspell::suggest(char*** slst, const char * word)
46 RepList * rl = (pAMgr) ? pAMgr->get_iconvtable() : NULL;
47 - if (rl && rl->conv(word, wspace)) wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
48 - else wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
49 + int convstatus = rl ? rl->conv(word, wspace, MAXWORDUTF8LEN) : 0;
52 + else if (convstatus > 0)
53 + wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
55 + wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
57 if (wl == 0) return 0;
59 @@ -1020,7 +1031,7 @@ int Hunspell::suggest(char*** slst, const char * word)
61 rl = (pAMgr) ? pAMgr->get_oconvtable() : NULL;
62 for (int j = 0; rl && j < ns; j++) {
63 - if (rl->conv((*slst)[j], wspace)) {
64 + if (rl->conv((*slst)[j], wspace, MAXWORDUTF8LEN) > 0) {
66 (*slst)[j] = mystrdup(wspace);
68 @@ -1395,8 +1406,13 @@ int Hunspell::analyze(char*** slst, const char * word)
71 RepList * rl = (pAMgr) ? pAMgr->get_iconvtable() : NULL;
72 - if (rl && rl->conv(word, wspace)) wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
73 - else wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
74 + int convstatus = rl ? rl->conv(word, wspace, MAXWORDUTF8LEN) : 0;
77 + else if (convstatus > 0)
78 + wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
80 + wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
84 @@ -1684,12 +1700,16 @@ int Hunspell::get_langnum() const
88 -int Hunspell::input_conv(const char * word, char * dest)
89 +int Hunspell::input_conv(const char * word, char * dest, size_t destsize)
91 RepList * rl = (pAMgr) ? pAMgr->get_iconvtable() : NULL;
92 - return (rl && rl->conv(word, dest));
93 + return (rl && rl->conv(word, dest, destsize) > 0);
96 +int Hunspell::input_conv(const char * word, char * dest)
98 + return input_conv(word, dest, std::numeric_limits<std::size_t>::max());
101 // return the beginning of the element (attr == NULL) or the attribute
102 const char * Hunspell::get_xml_pos(const char * s, const char * attr)
103 diff --git a/src/hunspell/hunspell.hxx b/src/hunspell/hunspell.hxx
104 index e62f0dd..0b5ad2e 100644
105 --- misc/hunspell-1.3.3/src/hunspell/hunspell.hxx
106 +++ misc/build/hunspell-1.3.3/src/hunspell/hunspell.hxx
107 @@ -226,7 +226,9 @@ public:
109 /* need for putdic */
110 int input_conv(const char * word, char * dest);
112 + // ^^-deprecated, use this-vv"
113 + int input_conv(const char * word, char * dest, size_t destsize);
115 /* experimental and deprecated functions */
117 #ifdef HUNSPELL_EXPERIMENTAL
118 diff --git a/src/hunspell/replist.cxx b/src/hunspell/replist.cxx
119 index b9b1255..bac3e06 100644
120 --- misc/hunspell-1.3.3/src/hunspell/replist.cxx
121 +++ misc/build/hunspell-1.3.3/src/hunspell/replist.cxx
128 #include "replist.hxx"
129 #include "csutil.hxx"
130 @@ -139,19 +140,30 @@ int RepList::add(char * pat1, char * pat2) {
134 -int RepList::conv(const char * word, char * dest) {
135 +int RepList::conv(const char * word, char * dest, size_t destsize) {
138 for (size_t i = 0; i < strlen(word); i++) {
139 int n = near(word + i);
140 int l = match(word + i, n);
142 + size_t replen = strlen(dat[n]->pattern2);
143 + if (stl+replen >= destsize)
145 strcpy(dest + stl, dat[n]->pattern2);
146 - stl += strlen(dat[n]->pattern2);
150 - } else dest[stl++] = word[i];
152 + if (stl+1 >= destsize)
154 + dest[stl++] = word[i];
161 +int RepList::conv(const char * word, char * dest) {
162 + return conv(word, dest, std::numeric_limits<std::size_t>::max());
164 diff --git a/src/hunspell/replist.hxx b/src/hunspell/replist.hxx
165 index 1e3d6e4..e418298 100644
166 --- misc/hunspell-1.3.3/src/hunspell/replist.hxx
167 +++ misc/build/hunspell-1.3.3/src/hunspell/replist.hxx
168 @@ -99,5 +99,7 @@ public:
169 int near(const char * word);
170 int match(const char * word, int n);
171 int conv(const char * word, char * dest);
172 + // ^^-deprecated, use this-vv"
173 + int conv(const char * word, char * dest, size_t destsize);
176 diff --git a/src/tools/hunspell.cxx b/src/tools/hunspell.cxx
177 index 6124ac4..1b50fe1 100644
178 --- misc/hunspell-1.3.3/src/tools/hunspell.cxx
179 +++ misc/build/hunspell-1.3.3/src/tools/hunspell.cxx
180 @@ -524,7 +524,7 @@ int putdic(char * word, Hunspell * pMS)
182 word = chenc(word, ui_enc, dic_enc[0]);
184 - if(pMS->input_conv(word, buf)) word = buf;
185 + if(pMS->input_conv(word, buf, MAXLNLEN)) word = buf;