Segfault in libpspell


Subject: Segfault in libpspell
From: Matt Brubeck (mbrubeck@hmc.edu)
Date: Tue Nov 14 2000 - 17:56:06 CST


I get the following on startup when I compile with ABI_OPT_PSPELL:

> SpellCheckInit: Pspell error: I'm sorry I can't find any sutable word
> lists for the language-tag "en".

When SpellCheckInit() gets an error from pspell, it prints the error and
returns zero.

Unfortunately, abi doesn't check the return value of SpellCheckInit. This
causes problems when it calls SpellCheckXXX(), because spell_manager does
not exist and is set to NULL. Passing NULL to pspell_manager_check causes
a segfault in libpspell.

The following patch will prevent my segfault, but doesn't fix the
underlying bug. In the long run, abi should check for error values from
SpellCheckInit(), and disable spell-checking. I'll work on this, but I'll
need some help.

Also, pspell_manager_check() should not segfault when passed a null
pointer as its first argument. This is a bug in Pspell.

Lastly, does anyone know why Pspell may be having trouble finding a
word-list?

For now, here's the quick fix:

Index: abi/src/other/spell/pspell.c
===================================================================
RCS file: /cvsroot/abi/src/other/spell/pspell.c,v
retrieving revision 1.1
diff -u -r1.1 pspell.c
--- pspell.c 2000/11/13 03:54:28 1.1
+++ pspell.c 2000/11/14 23:12:06
@@ -24,6 +24,8 @@
 
 #include "sp_spell.h"
 
+#define WORD_SIZE 256 /* or whatever */
+
 /**********************************************************************/
 /* encoding manager method hack so we can use it in C code */
 /**********************************************************************/
@@ -103,7 +105,11 @@
  */
 int SpellCheckNWord16(const unsigned short *word16, int length)
 {
- unsigned char word8[256];
+ unsigned char word8[WORD_SIZE];
+
+ /* pspell segfaults if we don't pass it a valid spell_manager */
+ if (spell_manager == NULL)
+ return -1;
 
   utf16_to_utf8(word16, word8, length);
   return pspell_manager_check(spell_manager, (char*)word8);
@@ -115,8 +121,15 @@
   PspellStringEmulation *suggestions = NULL;
   const PspellWordList *word_list = NULL;
   const char *new_word = NULL;
- unsigned char word8[256];
+ unsigned char word8[WORD_SIZE];
   int count = 0, i = 0;
+
+ if(word16 == NULL || length == 0)
+ {
+ /* error: incoming word is null */
+ sg->count = 0;
+ return 0;
+ }
 
   utf16_to_utf8(word16, word8, length);
   word_list = pspell_manager_suggest(spell_manager, (char*)word8);



This archive was generated by hypermail 2b25 : Tue Nov 14 2000 - 17:56:11 CST