From 2a0968f653bc03635f42d6628926c157c5e069f8 Mon Sep 17 00:00:00 2001 From: John Ellson Date: Wed, 26 Feb 2014 10:32:09 -0500 Subject: [PATCH] add asserts to track down #2425 --- lib/common/htmltable.c | 2 ++ lib/gvc/gvloadimage.c | 5 ++++ lib/gvc/gvrender.c | 4 +++ lib/gvc/gvusershape.c | 42 ++++++++++++++++++++------------ plugin/pango/gvloadimage_pango.c | 10 ++++++-- 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/lib/common/htmltable.c b/lib/common/htmltable.c index 5df2a5c28..86e5d3562 100644 --- a/lib/common/htmltable.c +++ b/lib/common/htmltable.c @@ -624,6 +624,8 @@ static void emit_html_img(GVJ_t * job, htmlimg_t * cp, htmlenv_t * env) scale = cp->scale; else scale = env->imgscale; + assert(cp->src); + assert(cp->src[0]); gvrender_usershape(job, cp->src, A, 4, TRUE, scale); } diff --git a/lib/gvc/gvloadimage.c b/lib/gvc/gvloadimage.c index 93706a8cf..718b435c2 100644 --- a/lib/gvc/gvloadimage.c +++ b/lib/gvc/gvloadimage.c @@ -51,6 +51,11 @@ void gvloadimage(GVJ_t * job, usershape_t *us, boxf b, boolean filled, const cha gvloadimage_engine_t *gvli; char type[SMALLBUF]; + assert(job); + assert(us); + assert(us->name); + assert(us->name[0]); + strcpy(type, us->stringtype); strcat(type, ":"); strcat(type, target); diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index 607401929..81da00074 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -695,6 +695,10 @@ void gvrender_usershape(GVJ_t * job, char *name, pointf * a, int n, int i; point isz; + assert(job); + assert(name); + assert(name[0]); + if (!(us = gvusershape_find(name))) { if (find_user_shape(name)) { if (gvre && gvre->library_shape) diff --git a/lib/gvc/gvusershape.c b/lib/gvc/gvusershape.c index 880a0350a..d6ecc0df6 100644 --- a/lib/gvc/gvusershape.c +++ b/lib/gvc/gvusershape.c @@ -572,13 +572,17 @@ static Dtdisc_t ImageDictDisc = { usershape_t *gvusershape_find(char *name) { - usershape_t probe; + usershape_t probe, *us; + + assert(name); + assert(name[0]); if (!ImageDict) return NULL; probe.name = name; - return (dtsearch(ImageDict, &probe)); + us = dtsearch(ImageDict, &probe); + return us; } #define MAX_USERSHAPE_FILES_OPEN 50 @@ -589,26 +593,30 @@ boolean gvusershape_file_access(usershape_t *us) assert(us); assert(us->name); + assert(us->name[0]); if (us->f) fseek(us->f, 0, SEEK_SET); else { - if ((fn = safefile(us->name))) { + if (! (fn = safefile(us->name))) { + agerr(AGWARN, "Filename \"%s\" is unsafe\n", us->name); + return FALSE; + } #ifndef WIN32 - us->f = fopen(fn, "r"); + us->f = fopen(fn, "r"); #else - us->f = fopen(fn, "rb"); + us->f = fopen(fn, "rb"); #endif - if (us->f == NULL) { - agerr(AGWARN, "%s while opening %s\n", strerror(errno), fn); - return FALSE; - } - if (usershape_files_open_cnt >= MAX_USERSHAPE_FILES_OPEN) - us->nocache = TRUE; - else - usershape_files_open_cnt++; + if (us->f == NULL) { + agerr(AGWARN, "%s while opening %s\n", strerror(errno), fn); + return FALSE; } + if (usershape_files_open_cnt >= MAX_USERSHAPE_FILES_OPEN) + us->nocache = TRUE; + else + usershape_files_open_cnt++; } + assert(us->f); return TRUE; } @@ -626,6 +634,8 @@ static usershape_t *gvusershape_open (char *name) { usershape_t *us; + assert(name); + if (!ImageDict) ImageDict = dtopen(&ImageDictDisc, Dttree); @@ -637,6 +647,8 @@ static usershape_t *gvusershape_open (char *name) if (!gvusershape_file_access(us)) return NULL; + assert(us->f); + switch(imagetype(us)) { case FT_NULL: if (!(us->data = (void*)find_user_shape(us->name))) @@ -678,11 +690,11 @@ static usershape_t *gvusershape_open (char *name) default: break; } + gvusershape_file_release(us); dtinsert(ImageDict, us); + return us; } - gvusershape_file_release(us); - return us; } diff --git a/plugin/pango/gvloadimage_pango.c b/plugin/pango/gvloadimage_pango.c index 2d2325dfe..3d5b3cab4 100644 --- a/plugin/pango/gvloadimage_pango.c +++ b/plugin/pango/gvloadimage_pango.c @@ -41,8 +41,7 @@ typedef enum { static cairo_status_t reader (void *closure, unsigned char *data, unsigned int length) { - if ((FILE *)closure == NULL) - return CAIRO_STATUS_READ_ERROR; + assert(closure); if (length == fread(data, 1, length, (FILE *)closure) || feof((FILE *)closure)) return CAIRO_STATUS_SUCCESS; @@ -61,6 +60,7 @@ static cairo_surface_t* cairo_loadimage(GVJ_t * job, usershape_t *us) assert(job); assert(us); assert(us->name); + assert(us->name[0]); if (us->data) { if (us->datafree == cairo_freeimage) @@ -74,6 +74,7 @@ static cairo_surface_t* cairo_loadimage(GVJ_t * job, usershape_t *us) if (!surface) { /* read file into cache */ if (!gvusershape_file_access(us)) return NULL; + assert(us->f); switch (us->type) { #ifdef CAIRO_HAS_PNG_FUNCTIONS case FT_PNG: @@ -98,6 +99,11 @@ static void pango_loadimage_cairo(GVJ_t * job, usershape_t *us, boxf b, boolean cairo_t *cr = (cairo_t *) job->context; /* target context */ cairo_surface_t *surface; /* source surface */ + assert(job); + assert(us); + assert(us->name); + assert(us->name[0]); + surface = cairo_loadimage(job, us); if (surface) { cairo_save(cr); -- 2.40.0