diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-03-15 18:51:15 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-03-15 19:28:12 +0000 |
commit | e31c26d7a0fad2cd935d597d1dabd38f7d8941bc (patch) | |
tree | ac0ffcedd9a664e411a2af8d00a166f094ac6eaa /include/mupdf/fitz/context.h | |
parent | 66c2ddc228960b1c1d365bff3255c9c992acf757 (diff) | |
download | mupdf-e31c26d7a0fad2cd935d597d1dabd38f7d8941bc.tar.xz |
Tweak fz_try/catch to fix overflow case.
In the current code, when we hit the fz_try(), we check to see
if we are about to overflow the exception stack. If we are,
we throw. This does NOT throw to the fz_catch following the
try, but rather to the enclosing fz_always/fz_catch blocks.
This can cause leaks, as it's very hard to code correctly.
It would be a far nicer behaviour to have a failure in fz_try()
cause us to throw to the immediately following fz_always/fz_catch.
This commit achieves that.
Diffstat (limited to 'include/mupdf/fitz/context.h')
-rw-r--r-- | include/mupdf/fitz/context.h | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/include/mupdf/fitz/context.h b/include/mupdf/fitz/context.h index c2b08898..db5d5d75 100644 --- a/include/mupdf/fitz/context.h +++ b/include/mupdf/fitz/context.h @@ -55,23 +55,27 @@ void fz_var_imp(void *); #define fz_try(ctx) \ {{{ \ - if (fz_setjmp(fz_push_try(ctx)->buffer) == 0)\ - { do { + if (fz_push_try(ctx)) {\ + if (fz_setjmp((ctx)->error->top->buffer) == 0)\ + { do {\ #define fz_always(ctx) \ - } while (0); \ + } while (0); \ + } \ } \ if (ctx->error->top->code < 3) \ { \ - ctx->error->top->code++; \ - do { \ + { \ + ctx->error->top->code++; \ + do { \ #define fz_catch(ctx) \ - } while(0); \ + } while(0); \ + } \ } }}} \ if ((ctx->error->top--)->code > 1) -fz_error_stack_slot *fz_push_try(fz_context *ctx); +int fz_push_try(fz_context *ctx); FZ_NORETURN void fz_throw(fz_context *ctx, int errcode, const char *, ...) __printflike(3, 4); FZ_NORETURN void fz_rethrow(fz_context *ctx); FZ_NORETURN void fz_rethrow_message(fz_context *ctx, const char *fmt, ...) __printflike(2, 3); |