From 90238d516ef330d43c5795cf99c6d7f3cfa514fc Mon Sep 17 00:00:00 2001 From: dkf Date: Fri, 28 May 2010 09:11:31 +0000 Subject: * generic/tclCompCmdsSZ.c (IssueTryFinallyInstructions): [3007374]: Corrected error in handling of catch contexts to prevent crash with chained handlers. --- ChangeLog | 4 ++ generic/tclCompCmdsSZ.c | 102 +++++++++++++++++++++++++++--------------------- tests/error.test | 19 ++++++++- 3 files changed, 79 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index a749a87..3bc5462 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2010-05-28 Donal K. Fellows + * generic/tclCompCmdsSZ.c (IssueTryFinallyInstructions): [3007374]: + Corrected error in handling of catch contexts to prevent crash with + chained handlers. + * generic/tclExecute.c (TclExecuteByteCode): Restore correct operation of instruction-level execution tracing (had been broken by NRE). diff --git a/generic/tclCompCmdsSZ.c b/generic/tclCompCmdsSZ.c index 3d45833..8fef58d 100644 --- a/generic/tclCompCmdsSZ.c +++ b/generic/tclCompCmdsSZ.c @@ -14,7 +14,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCompCmdsSZ.c,v 1.8 2010/04/08 13:26:24 dkf Exp $ + * RCS: @(#) $Id: tclCompCmdsSZ.c,v 1.9 2010/05/28 09:11:31 dkf Exp $ */ #include "tclInt.h" @@ -2419,62 +2419,74 @@ IssueTryFinallyInstructions( STORE( optionVars[i]); OP( POP); } - } - if (!handlerTokens[i]) { + + if (!handlerTokens[i]) { + /* + * No handler. Will not be the last handler (that is a + * condition that is checked by the caller). Chain to the + * next one. + */ + + ExceptionRangeEnds(envPtr, range); + OP( END_CATCH); + forwardsNeedFixing = 1; + JUMP(forwardsToFix[i], JUMP4); + goto finishTrapCatchHandling; + } + } else if (!handlerTokens[i]) { /* * No handler. Will not be the last handler (that condition is * checked by the caller). Chain to the next one. */ - ExceptionRangeEnds(envPtr, range); forwardsNeedFixing = 1; JUMP(forwardsToFix[i], JUMP4); - if (resultVars[i] >= 0) { - goto finishTrapCatchHandling; - } - } else { - /* - * Got a handler. Make sure that any pending patch-up actions - * from previous unprocessed handlers are dealt with now that - * we know where they are to jump to. - */ + goto endOfThisArm; + } - if (forwardsNeedFixing) { - forwardsNeedFixing = 0; - OP1( JUMP1, 7); - for (j=0 ; j