
From grdetil@scrc.umanitoba.ca Tue Feb 16 13:30:04 1999
Date: Tue, 16 Feb 1999 15:24:03 -0600 (CST)
From: Gilles Detillieux <grdetil@scrc.umanitoba.ca>
To: htdig3-dev@htdig.org
Cc: grdetil@scrc.umanitoba.ca, htdig3-dev@htdig.org
Subject: Re: [htdig3-dev] Re: [htdig] SYNTAXERROR - bug?


According to Geoff Hutchison:
> > There's still another problem -- when I try an expression that doesn't have
> > enough closing parentheses, instead of a syntax error message, I get an
> > internal server error, with this error in the error log for Apache:
> 
> No, but this is a good thing to try from the command line:
> 
> ethel:~/htdig-cvs/build/htsearch$ ./htsearch -c
> /opt/htdig/conf/bad-sites.conf
> Enter value for words: (test and excerpt
> Segmentation fault (core dumped)
> ethel:~/htdig-cvs/build/htsearch$ gdb htsearch core
> ...
> #0  0x805925a in String::get ()
> (gdb) bt
> #0  0x805925a in String::get ()
> #1  0x804feaf in Parser::factor ()
> #2  0x8050523 in Parser::term ()
> #3  0x805057e in Parser::expr ()
> #4  0x8050635 in Parser::checkSyntax ()
> #5  0x804f0e0 in setupWords ()
> #6  0x804e558 in main ()
> 
> (I don't have debugging turned on in the binary, so I can't get more
> info.)

OK, the problem was with the new error message.  You can't use
current->word.get() if current is NULL, which it is when lexan()
returns DONE.  So, here's my fixed patch, which also addresses
the error Marjolein reported about it not checking for extra stuff
at the end of the expression.

Please, can people hammer away at this patch, to make sure I didn't
break anything!  Thanks.

--- ./htsearch/parser.h.errors	Mon Feb 15 20:37:20 1999
+++ ./htsearch/parser.h	Tue Feb 16 15:14:00 1999
@@ -39,6 +39,7 @@
     int			hadError()			{return valid == 0;}
 	
 protected:
+    void		fullexpr(int);
     int			lexan();
     void		expr(int);
     void		term(int);
--- ./htsearch/parser.cc.errors	Mon Feb 15 20:37:20 1999
+++ ./htsearch/parser.cc	Tue Feb 16 15:13:18 1999
@@ -60,11 +60,31 @@
     tokens->Start_Get();
     lookahead = lexan();
     valid = 1;
-    expr(0);
+    fullexpr(0);
     return valid;
 }
 
 //*****************************************************************************
+void
+Parser::fullexpr(int output)
+{
+    expr(output);
+    if (lookahead != DONE)
+    {
+	valid = 0;
+	error = 0;
+	error << "expected end of expression instead of '";
+	error << current->word.get() << '\'';
+	switch (lookahead)
+	{
+	case '&':	error << " or 'AND'";	break;
+	case '|':	error << " or 'OR'";	break;
+	case '!':	error << " or 'NOT'";	break;
+	}
+    }
+}
+
+//*****************************************************************************
 int
 Parser::lexan()
 {
@@ -155,6 +175,8 @@
 	else
 	{
 	    valid = 0;
+	    error = 0;
+	    error << "expected ')'";
 	}
     }
     else if (lookahead == WORD)
@@ -168,6 +190,27 @@
     else
     {
 	valid = 0;
+	error = 0;
+	error << "expected a word";
+    }
+
+    if (!valid)
+    {
+	if (lookahead == DONE || !current)
+	{
+	    error << " at the end";
+	}
+	else
+	{
+	    error << " instead of '" << current->word.get();
+	    error << '\'';
+	    switch (lookahead)
+	    {
+	    case '&':	error << " or 'AND'";	break;
+	    case '|':	error << " or 'OR'";	break;
+	    case '!':	error << " or 'NOT'";	break;
+	    }
+	}
     }
 }
 
@@ -391,7 +434,7 @@
     tokens = tokenList;
     tokens->Start_Get();
     lookahead = lexan();
-    expr(1);
+    fullexpr(1);
 
     ResultList	*result = (ResultList *) stack.pop();
     if (!result)  // Ouch!


-- 
Gilles R. Detillieux              E-mail: <grdetil@scrc.umanitoba.ca>
Spinal Cord Research Centre       WWW:    http://www.scrc.umanitoba.ca/~grdetil
Dept. Physiology, U. of Manitoba  Phone:  (204)789-3766
Winnipeg, MB  R3E 3J7  (Canada)   Fax:    (204)789-3930
------------------------------------
To unsubscribe from the htdig3-dev mailing list, send a message to
htdig3-dev@htdig.org containing the single word "unsubscribe" in
the SUBJECT of the message.
