diff Python/compile.c @ 40042:ed88d6b7c1f9 2.5

Patch #1542451: fix crash with continue in nested try/finally (backport from rev. 51439)
author Georg Brandl <georg@python.org>
date Sun, 08 Oct 2006 07:06:29 +0000
parents 9f390882a2c3
children 9e0431fd674a
line wrap: on
line diff
--- a/Python/compile.c	Sat Oct 07 14:56:30 2006 +0000
+++ b/Python/compile.c	Sun Oct 08 07:06:29 2006 +0000
@@ -2288,6 +2288,8 @@
 compiler_continue(struct compiler *c)
 {
 	static const char LOOP_ERROR_MSG[] = "'continue' not properly in loop";
+	static const char IN_FINALLY_ERROR_MSG[] = 
+			"'continue' not supported inside 'finally' clause";
 	int i;
 
 	if (!c->u->u_nfblocks)
@@ -2299,15 +2301,19 @@
 		break;
 	case EXCEPT:
 	case FINALLY_TRY:
-		while (--i >= 0 && c->u->u_fblock[i].fb_type != LOOP)
-			;
+		while (--i >= 0 && c->u->u_fblock[i].fb_type != LOOP) {
+			/* Prevent try: ... finally:
+			      try: continue ...  or
+			      try: ... except: continue */
+			if (c->u->u_fblock[i].fb_type == FINALLY_END)
+				return compiler_error(c, IN_FINALLY_ERROR_MSG);
+		}
 		if (i == -1)
 			return compiler_error(c, LOOP_ERROR_MSG);
 		ADDOP_JABS(c, CONTINUE_LOOP, c->u->u_fblock[i].fb_block);
 		break;
 	case FINALLY_END:
-		return compiler_error(c,
-			"'continue' not supported inside 'finally' clause");
+		return compiler_error(c, IN_FINALLY_ERROR_MSG);
 	}
 
 	return 1;