diff options
author | Georg Brandl <georg@python.org> | 2006-10-08 07:06:29 +0000 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-10-08 07:06:29 +0000 |
commit | 74284b9606b4c2743ef82119b41eb3a74dd5b2d2 (patch) | |
tree | d7ff03b06ee15ed9d1cc3ba3790720f72ab23acd /Python/compile.c | |
parent | 2c8851e614cefa4b4056338423dc71501dc8773c (diff) | |
download | cpython-git-74284b9606b4c2743ef82119b41eb3a74dd5b2d2.tar.gz |
Patch #1542451: fix crash with continue in nested try/finally
(backport from rev. 51439)
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Python/compile.c b/Python/compile.c index 92eff00732..76c462829d 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -2288,6 +2288,8 @@ static int 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 @@ compiler_continue(struct compiler *c) 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; |