Blame SOURCES/0001-Resolves-rhbz-1261421-crash-on-mashing-hangul-korean.patch

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