From 241f109a66916bb4a5a8d3caa2167895e87b04ec Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Thu, 23 Aug 2012 13:48:50 +0100 Subject: Fix bug introduced in preceding commit Not handling pdf_jsimp_toString returning NULL Throwing C exceptions in a call issued by v8 Iterating a pointer later used to free a buffer --- pdf/pdf_js.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'pdf') diff --git a/pdf/pdf_js.c b/pdf/pdf_js.c index a086b98c..1ce2c7e9 100644 --- a/pdf/pdf_js.c +++ b/pdf/pdf_js.c @@ -279,30 +279,38 @@ static pdf_jsimp_obj *doc_getField(void *jsctx, void *obj, int argc, pdf_jsimp_o fz_context *ctx = js->doc->ctx; pdf_obj *arr = js->form; pdf_obj *dict = NULL; - int len; - char *utf8, *name, *dot; + int len; + char *utf8, *dot; + char *name = NULL; + char *namep; if (argc != 1) return NULL; - /* Process the fully qualified field name which has - * the partial names delimited by '.' */ - utf8 = pdf_jsimp_toString(js->imp, args[0]); - name = utf8_to_pdf(ctx, utf8); - - /* Pretend there was a preceding '.' to simplify the loop */ - dot = name - 1; - + fz_var(dict); + fz_var(name); fz_try(ctx) { - while (dot && arr) + utf8 = pdf_jsimp_toString(js->imp, args[0]); + + if (utf8) { - name = dot + 1; - dot = strchr(name, '.'); - len = dot ? dot - name : strlen(name); - dict = find_field(arr, name, len); - if (dot) - arr = pdf_dict_gets(dict, "Kids"); + name = utf8_to_pdf(ctx, utf8); + + /* Process the fully qualified field name which has + * the partial names delimited by '.'. Pretend there + * was a preceding '.' to simplify the loop */ + dot = name - 1; + + while (dot && arr) + { + namep = dot + 1; + dot = strchr(namep, '.'); + len = dot ? dot - namep : strlen(namep); + dict = find_field(arr, namep, len); + if (dot) + arr = pdf_dict_gets(dict, "Kids"); + } } } fz_always(ctx) @@ -311,7 +319,8 @@ static pdf_jsimp_obj *doc_getField(void *jsctx, void *obj, int argc, pdf_jsimp_o } fz_catch(ctx) { - fz_rethrow(ctx); + fz_warn(ctx, "doc_getField failed: %s", ctx->error->message); + dict = NULL; } return dict ? pdf_jsimp_new_obj(js->imp, js->fieldtype, dict) : NULL; -- cgit v1.2.3