On Sun, Nov 30, 2014 at 01:08:57AM +0400, Andrey Skvortsov wrote:

> Hello.
> 
> I'v faced with yacc segmentation fault error while trying to build
> TkGate-2.0b10 from tkgate.org
> (http://www.tkgate.org/downloads/tkgate-2.0-b10.tgz) on OpenBSD-5.6. Error
> appears when yacc parses ./src/tkgate/vgrammar.y file (attached).
> I have no any tests and knowledge about yacc structure, but the attached
> patch seems to fix the problem in this particular case at least.
> 
> Yours sincerely,
> Andrey V. Skvortsov


> 605c605
> <                     if (loc >= maxtable) {
> ---
> >                     if (loc >= maxtable - 1) {
> 612c612
> <                             } while (newmax <= loc);
> ---
> >                             } while (newmax <= loc + 1);

Nice. I'm not 100% convinced yet this is the best fix. The actual
problem is that the scanning for the new lowzero goes out of bounds.
The diff below also fixes the crash for me. The question is do we need
a -1 entry as a guard at the end of the check vector. 

BTW, we prefer unified diffs,

        -Otto

Index: output.c
===================================================================
RCS file: /cvs/src/usr.bin/yacc/output.c,v
retrieving revision 1.23
diff -u -p -r1.23 output.c
--- output.c    13 Mar 2014 01:18:22 -0000      1.23
+++ output.c    30 Nov 2014 07:58:55 -0000
@@ -639,7 +639,7 @@ pack_vector(int vector)
                                        high = loc;
                        }
 
-                       while (check[lowzero] != -1)
+                       while (lowzero < maxtable && check[lowzero] != -1)
                                ++lowzero;
 
                        return (j);


Reply via email to