Re: Segfault in libpspell


Subject: Re: Segfault in libpspell
From: Sam TH (sam@uchicago.edu)
Date: Wed Nov 15 2000 - 00:16:24 CST


On Wed, Nov 15, 2000 at 01:04:07AM -0500, Kevin Atkinson wrote:
> On Tue, 14 Nov 2000, Sam TH wrote:
>
> > On Tue, Nov 14, 2000 at 07:29:43PM -0500, Kevin Atkinson wrote:
> > > On Tue, 14 Nov 2000, Matt Brubeck wrote:
> > >
> > > > Also, pspell_manager_check() should not segfault when passed a null
> > > > pointer as its first argument. This is a bug in Pspell.
> > >
> > > Um, Why? You are violating an implied precondition of passing in a valid
> > > pointer.
> > >
> >
> > Because programs shouldn't segfault. This is certainly our fault,
> > for passing the NULL pointer. However, it is preferable to check
> > that, than to just segfault.
>
> A library can certainly segfault. The behavior of many libc functions
> are undefined if you give them invalid input. Similarly the behavior of
> many pspell functions are undefined if you give them invalid input.
>
> Just what would you like me to do if I get a null pointer?

Well, as far as I can tell from Dom's code, pspell_manager_check() returns
1 if found, 0 if not found, and -1 on error. Therefore, if it was passed
a null pointer, it could return -1. The following patch does just that
(actually it checks both arguments, which should be the right thing to do):

Index: interface/manager.cc
===================================================================
RCS file: /cvsroot/pspell/pspell/interface/manager.cc,v
retrieving revision 1.4
diff -u -r1.4 manager.cc
--- interface/manager.cc 2000/05/30 15:59:40 1.4
+++ interface/manager.cc 2000/11/15 06:15:56
@@ -29,6 +29,8 @@
 
 int pspell_manager_check(PspellManager * m, const char * word)
 {
+ if (!m || !word)
+ return -1;
   return m->check(word);
 }
 

        sam th
        sam@uchicago.edu
        http://www.abisource.com/~sam/
        GnuPG Key:
        http://www.abisource.com/~sam/key




This archive was generated by hypermail 2b25 : Wed Nov 15 2000 - 00:16:29 CST