~ubuntu-branches/ubuntu/precise/graphviz/precise-security

« back to all changes in this revision

Viewing changes to lib/gvc/gvusershape.c

  • Committer: Bazaar Package Importer
  • Author(s): David Claughton
  • Date: 2010-03-24 22:45:18 UTC
  • mfrom: (1.2.7 upstream) (6.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100324224518-do441tthbqjaqjzd
Tags: 2.26.3-4
Add patch to fix segfault in circo. Backported from upstream snapshot
release.  Thanks to Francis Russell for his work on this.
(Closes: #575255)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: gvusershape.c,v 1.36 2008/03/15 23:19:30 ellson Exp $ $Revision: 1.36 $ */
 
1
/* $Id: gvusershape.c,v 1.51 2009/06/03 01:10:53 ellson Exp $ $Revision: 1.51 $ */
2
2
/* vim:set shiftwidth=4 ts=8: */
3
3
 
4
4
/**********************************************************
25
25
#include "types.h"
26
26
#include "logic.h"
27
27
#include "memory.h"
28
 
#include "graph.h"
29
28
#include "agxbuf.h"
 
29
 
 
30
#define _BLD_gvc 1
30
31
#include "utils.h"
31
 
 
32
 
extern shape_desc *find_user_shape(char *);
 
32
#include "gvplugin_loadimage.h"
 
33
 
 
34
 
 
35
extern shape_desc *find_user_shape(const char *);
33
36
 
34
37
static Dict_t *ImageDict;
35
38
 
147
150
    char u[10];
148
151
    char *token;
149
152
    char line[200];
150
 
    bool wFlag = false, hFlag = false;
 
153
    boolean wFlag = FALSE, hFlag = FALSE;
151
154
 
152
155
    fseek(us->f, -strlen(line), SEEK_CUR);
153
156
    while (fgets(line, sizeof(line), us->f) != NULL && (!wFlag || !hFlag)) {
155
158
        while (token != NULL && token[strlen(token)-1] != '>') {
156
159
            if (sscanf(token, "width=\"%lf%2s\"", &n, u) == 2) {
157
160
                w = svg_units_convert(n, u);
158
 
                wFlag = true;
 
161
                wFlag = TRUE;
159
162
                if (hFlag)
160
163
                    break;
161
164
            }
162
165
            if (sscanf(token, "height=\"%lf%2s\"", &n, u) == 2) {
163
166
                h = svg_units_convert(n, u);
164
 
                hFlag = true;
 
167
                hFlag = TRUE;
165
168
                if (wFlag)
166
169
                    break;
167
170
            }
291
294
    char line[BUFSIZ];
292
295
    boolean saw_bb;
293
296
    int lx, ly, ux, uy;
 
297
    char* linep;
294
298
 
295
299
    us->dpi = POINTS_PER_INCH;
296
300
    fseek(us->f, 0, SEEK_SET);
297
301
    saw_bb = FALSE;
298
302
    while (fgets(line, sizeof(line), us->f)) {
299
 
        if (sscanf (line, "%%%%BoundingBox: %d %d %d %d", &lx, &ly, &ux, &uy) == 4) {
 
303
        /* PostScript accepts \r as EOL, so using fgets () and looking for a
 
304
         * bounding box comment at the beginning doesn't work in this case. 
 
305
         * As a heuristic, we first search for a bounding box comment in line.
 
306
         * This obviously fails if not all of the numbers make it into the
 
307
         * current buffer. This shouldn't be a problem, as the comment is
 
308
         * typically near the beginning, and so should be read within the first
 
309
         * BUFSIZ bytes (even on Windows where this is 512).
 
310
         */
 
311
        if (!(linep = strstr (line, "%%BoundingBox:")))
 
312
            continue;
 
313
        if (sscanf (linep, "%%%%BoundingBox: %d %d %d %d", &lx, &ly, &ux, &uy) == 4) {
300
314
            saw_bb = TRUE;
301
315
            break;
302
316
        }
347
361
boolean gvusershape_file_access(usershape_t *us)
348
362
{
349
363
    static int usershape_files_open_cnt;
350
 
    char *fn;
 
364
    const char *fn;
351
365
 
352
366
    assert(us);
353
367
    assert(us->name);
363
377
#endif
364
378
            if (us->f == NULL) {
365
379
                agerr(AGWARN, "%s while opening %s\n", strerror(errno), fn);
366
 
                return false;
 
380
                return FALSE;
367
381
            }
368
382
            if (usershape_files_open_cnt >= MAX_USERSHAPE_FILES_OPEN)
369
 
                us->nocache = true;
 
383
                us->nocache = TRUE;
370
384
            else
371
385
                usershape_files_open_cnt++;
372
386
        }
373
387
    }
374
 
    return true;
 
388
    return TRUE;
375
389
}
376
390
 
377
391
void gvusershape_file_release(usershape_t *us)