|
|
5358ff |
From 97e079a23d459aeb6e64435350d7710c90dbca85 Mon Sep 17 00:00:00 2001
|
|
|
5358ff |
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
|
|
|
5358ff |
Date: Fri, 11 Sep 2015 13:28:52 +0100
|
|
|
5358ff |
Subject: [PATCH] Resolves: rhbz#1261421 crash on mashing hangul korean
|
|
|
5358ff |
keyboard
|
|
|
5358ff |
|
|
|
5358ff |
---
|
|
|
5358ff |
src/hunspell/hunspell.cxx | 69 +++++++++++++++++++++++++++++++++++------------
|
|
|
5358ff |
src/hunspell/hunspell.hxx | 4 ++-
|
|
|
5358ff |
src/hunspell/replist.cxx | 18 ++++++++++---
|
|
|
5358ff |
src/hunspell/replist.hxx | 2 ++
|
|
|
5358ff |
src/tools/hunspell.cxx | 2 +-
|
|
|
5358ff |
6 files changed, 78 insertions(+), 24 deletions(-)
|
|
|
5358ff |
|
|
|
5358ff |
diff --git a/src/hunspell/hunspell.cxx b/src/hunspell/hunspell.cxx
|
|
|
5358ff |
index 7fae54b..d8ef357 100644
|
|
|
5358ff |
--- a/src/hunspell/hunspell.cxx
|
|
|
5358ff |
+++ b/src/hunspell/hunspell.cxx
|
|
|
5358ff |
@@ -12,6 +12,7 @@
|
|
|
5358ff |
#endif
|
|
|
5358ff |
#include "csutil.hxx"
|
|
|
5358ff |
|
|
|
5358ff |
+#include <limits>
|
|
|
5358ff |
#include <string>
|
|
|
5358ff |
|
|
|
5358ff |
Hunspell::Hunspell(const char * affpath, const char * dpath, const char * key)
|
|
|
5358ff |
@@ -345,8 +346,13 @@
|
|
|
5358ff |
|
|
|
5358ff |
// input conversion
|
|
|
5358ff |
RepList * rl = (pAMgr) ? pAMgr->get_iconvtable() : NULL;
|
|
|
5358ff |
- if (rl && rl->conv(word, wspace)) wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
|
|
|
5358ff |
- else wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
|
|
|
5358ff |
+ int convstatus = rl ? rl->conv(word, wspace, MAXWORDUTF8LEN) : 0;
|
|
|
5358ff |
+ if (convstatus < 0)
|
|
|
5358ff |
+ return 0;
|
|
|
5358ff |
+ else if (convstatus > 0)
|
|
|
5358ff |
+ wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
|
|
|
5358ff |
+ else
|
|
|
5358ff |
+ wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
|
|
|
5358ff |
|
|
|
5358ff |
int info2 = 0;
|
|
|
5358ff |
if (wl == 0 || maxdic == 0) return 1;
|
|
|
5358ff |
@@ -699,8 +705,13 @@
|
|
|
5358ff |
|
|
|
5358ff |
// input conversion
|
|
|
5358ff |
RepList * rl = (pAMgr) ? pAMgr->get_iconvtable() : NULL;
|
|
|
5358ff |
- if (rl && rl->conv(word, wspace)) wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
|
|
|
5358ff |
- else wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
|
|
|
5358ff |
+ int convstatus = rl ? rl->conv(word, wspace, MAXWORDUTF8LEN) : 0;
|
|
|
5358ff |
+ if (convstatus < 0)
|
|
|
5358ff |
+ return 0;
|
|
|
5358ff |
+ else if (convstatus > 0)
|
|
|
5358ff |
+ wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
|
|
|
5358ff |
+ else
|
|
|
5358ff |
+ wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
|
|
|
5358ff |
|
|
|
5358ff |
if (wl == 0) return 0;
|
|
|
5358ff |
int ns = 0;
|
|
|
5358ff |
@@ -1008,7 +1019,7 @@
|
|
|
5358ff |
// output conversion
|
|
|
5358ff |
rl = (pAMgr) ? pAMgr->get_oconvtable() : NULL;
|
|
|
5358ff |
for (int j = 0; rl && j < ns; j++) {
|
|
|
5358ff |
- if (rl->conv((*slst)[j], wspace)) {
|
|
|
5358ff |
+ if (rl->conv((*slst)[j], wspace, MAXWORDUTF8LEN) > 0) {
|
|
|
5358ff |
free((*slst)[j]);
|
|
|
5358ff |
(*slst)[j] = mystrdup(wspace);
|
|
|
5358ff |
}
|
|
|
5358ff |
@@ -1383,8 +1394,13 @@
|
|
|
5358ff |
|
|
|
5358ff |
// input conversion
|
|
|
5358ff |
RepList * rl = (pAMgr) ? pAMgr->get_iconvtable() : NULL;
|
|
|
5358ff |
- if (rl && rl->conv(word, wspace)) wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
|
|
|
5358ff |
- else wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
|
|
|
5358ff |
+ int convstatus = rl ? rl->conv(word, wspace, MAXWORDUTF8LEN) : 0;
|
|
|
5358ff |
+ if (convstatus < 0)
|
|
|
5358ff |
+ return 0;
|
|
|
5358ff |
+ else if (convstatus > 0)
|
|
|
5358ff |
+ wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
|
|
|
5358ff |
+ else
|
|
|
5358ff |
+ wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
|
|
|
5358ff |
|
|
|
5358ff |
if (wl == 0) {
|
|
|
5358ff |
if (abbv) {
|
|
|
5358ff |
diff --git a/src/hunspell/replist.cxx b/src/hunspell/replist.cxx
|
|
|
5358ff |
index b9b1255..bac3e06 100644
|
|
|
5358ff |
--- a/src/hunspell/replist.cxx
|
|
|
5358ff |
+++ b/src/hunspell/replist.cxx
|
|
|
5358ff |
@@ -74,6 +74,7 @@
|
|
|
5358ff |
#include <stdlib.h>
|
|
|
5358ff |
#include <string.h>
|
|
|
5358ff |
#include <stdio.h>
|
|
|
5358ff |
+#include <limits>
|
|
|
5358ff |
|
|
|
5358ff |
#include "replist.hxx"
|
|
|
5358ff |
#include "csutil.hxx"
|
|
|
5358ff |
@@ -139,19 +140,30 @@ int RepList::add(char * pat1, char * pat2) {
|
|
|
5358ff |
return 0;
|
|
|
5358ff |
}
|
|
|
5358ff |
|
|
|
5358ff |
-int RepList::conv(const char * word, char * dest) {
|
|
|
5358ff |
+int RepList::conv(const char * word, char * dest, size_t destsize) {
|
|
|
5358ff |
int stl = 0;
|
|
|
5358ff |
int change = 0;
|
|
|
5358ff |
for (size_t i = 0; i < strlen(word); i++) {
|
|
|
5358ff |
int n = near(word + i);
|
|
|
5358ff |
int l = match(word + i, n);
|
|
|
5358ff |
if (l) {
|
|
|
5358ff |
+ size_t replen = strlen(dat[n]->pattern2);
|
|
|
5358ff |
+ if (stl+replen >= destsize)
|
|
|
5358ff |
+ return -1;
|
|
|
5358ff |
strcpy(dest + stl, dat[n]->pattern2);
|
|
|
5358ff |
- stl += strlen(dat[n]->pattern2);
|
|
|
5358ff |
+ stl += replen;
|
|
|
5358ff |
i += l - 1;
|
|
|
5358ff |
change = 1;
|
|
|
5358ff |
- } else dest[stl++] = word[i];
|
|
|
5358ff |
+ } else {
|
|
|
5358ff |
+ if (stl+1 >= destsize)
|
|
|
5358ff |
+ return -1;
|
|
|
5358ff |
+ dest[stl++] = word[i];
|
|
|
5358ff |
+ }
|
|
|
5358ff |
}
|
|
|
5358ff |
dest[stl] = '\0';
|
|
|
5358ff |
return change;
|
|
|
5358ff |
}
|
|
|
5358ff |
+
|
|
|
5358ff |
+int RepList::conv(const char * word, char * dest) {
|
|
|
5358ff |
+ return conv(word, dest, std::numeric_limits<std::size_t>::max());
|
|
|
5358ff |
+}
|
|
|
5358ff |
diff --git a/src/hunspell/replist.hxx b/src/hunspell/replist.hxx
|
|
|
5358ff |
index 1e3d6e4..e418298 100644
|
|
|
5358ff |
--- a/src/hunspell/replist.hxx
|
|
|
5358ff |
+++ b/src/hunspell/replist.hxx
|
|
|
5358ff |
@@ -99,5 +99,7 @@ public:
|
|
|
5358ff |
int near(const char * word);
|
|
|
5358ff |
int match(const char * word, int n);
|
|
|
5358ff |
int conv(const char * word, char * dest);
|
|
|
5358ff |
+ // ^^-deprecated, use this-vv"
|
|
|
5358ff |
+ int conv(const char * word, char * dest, size_t destsize);
|
|
|
5358ff |
};
|
|
|
5358ff |
#endif
|