#4 ArrayIndexOutOfBoundException in yyparse()

closed-fixed
code (8)
8
2014-01-31
2006-06-15
Tomas Hurka
No

This bug report is from raimi at sourceforge.

i think i have found a bug that was introduced with 1.11: the
state_* functions lost their ability to check for underflow. for
example, state_peek was modified from:

"int state_peek(int relative)",
"{",
"int ptr;",
" ptr=stateptr-relative;",
" if (ptr<0)",
" return -1;",
" return statestk[ptr];",

to:

"final int state_peek(int relative)",
"{",
" return statestk[stateptr-relative];",
"}",

... which triggers an ArrayIndexOutOfBoundException in yyparse() in
the
"ERROR RECOVERY" part:

yyn = yysindex[state_peek(0)];
if ((yyn != 0) && (yyn += YYERRCODE) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)

...when a syntax error occurs at the "top level". it's easy to
reproduce: take your favourite language and let it parse an unexpected
token (which used to trigger a simple "syntax error"). with 1.12 (and
probably 1.11) it triggers ArrayIndexOutOfBoundsException: -1 in
yyparse/state_peek.

i tried to hand-fix those methods, but that just defers the problem and
does not result in my precious "syntax error". The error recovery is
probably different.

Discussion

  • Tomas Hurka

    Tomas Hurka - 2006-06-15

    Logged In: YES
    user_id=482413

    You are right, there is a regression in 1.11 and 1.12. The problem is not
    state_* functions itself, but there is important test right before

    yyn = yysindex[state_peek(0)];

    which was removed.
    The correct code should look like this:
    if (stateptr<0) //check for under & overflow here
    {
    yyerror("stack underflow. aborting..."); //note lower case 's'
    return 1;
    }
    yyn = yysindex[state_peek(0)];

     
  • Tomas Hurka

    Tomas Hurka - 2006-06-15
    • labels: --> code
     
  • Tomas Hurka

    Tomas Hurka - 2006-06-15

    Logged In: YES
    user_id=482413

    Fixed in CVS trunk.
    Checking in skeleton.c;
    /cvsroot/byaccj/1.1/src/skeleton.c,v <-- skeleton.c
    new revision: 1.6; previous revision: 1.5
    done

     
  • Tomas Hurka

    Tomas Hurka - 2006-06-15
    • status: open --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks