Skip to content

Commit

Permalink
Fix #397
Browse files Browse the repository at this point in the history
If the interpreter runs into an error while reading from a stream and
tries to check for a dual semicolon at the end of the statement, the
call to GetSymbol() leads to a call to ReadLine on the input stream.

With  (IsInputTextStream and IsInputTextStringRep) the correct method
is selected and called. The crash happens inside the method when trying
to access the stream or local variables.

This might not be the correct fix yet, but it seems clear that the
interpreter state is not right at this point.
  • Loading branch information
markuspf committed Apr 2, 2016
1 parent 761f59d commit cf6272a
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -2726,20 +2726,20 @@ ExecStatus ReadEvalCommand ( Obj context, UInt *dualSemicolon )
SyntaxError( "; expected");
}

/* check for dual semicolon */
if ( *TLS(In) == ';' ) {
GetSymbol();
if (dualSemicolon) *dualSemicolon = 1;
}
else {
if (dualSemicolon) *dualSemicolon = 0;
}

/* end the interpreter */
if ( ! READ_ERROR() ) {
/* Note that GetSymbol below potentially calls into the interpreter
again, and if an error occurred the interpreter is not in the correct
state to execute ReadLine on an input stream, leading to crashes */
if (!READ_ERROR()) {
type = IntrEnd( 0UL );
}
else {

/* check for dual semicolon */
if ( *TLS(In) == ';' ) {
GetSymbol();
if (dualSemicolon) *dualSemicolon = 1;
} else {
if (dualSemicolon) *dualSemicolon = 0;
}
} else {
IntrEnd( 1UL );
type = STATUS_ERROR;
}
Expand Down

0 comments on commit cf6272a

Please sign in to comment.