Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:13.1:Update
python-magic.3341
0003-reduce-recursion-level-from-20-to-10-and-m...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0003-reduce-recursion-level-from-20-to-10-and-make-a-symb.patch of Package python-magic.3341
From 6f737ddfadb596d7d4a993f7ed2141ffd664a81c Mon Sep 17 00:00:00 2001 From: Christos Zoulas <christos@zoulas.com> Date: Sun, 23 Nov 2014 13:54:27 +0000 Subject: [PATCH] - reduce recursion level from 20 to 10 and make a symbolic constant for it. - pull out the guts of saving and restoring the output buffer into functions and take care not to overwrite the error message if an error happened. --- src/file.h | 8 ++++++++ src/funcs.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/softmagic.c | 37 ++++++++++++++++++++++--------------- 3 files changed, 70 insertions(+), 15 deletions(-) --- src/file.h +++ src/file.h 2014-12-17 00:00:00.000000000 +0000 @@ -468,6 +468,14 @@ protected int file_os2_apptype(struct ma #endif /* __EMX__ */ +typedef struct { + char *buf; + uint32_t offset; +} file_pushbuf_t; + +protected file_pushbuf_t *file_push_buffer(struct magic_set *); +protected char *file_pop_buffer(struct magic_set *, file_pushbuf_t *); + #ifndef COMPILE_ONLY extern const char *file_names[]; extern const size_t file_nnames; --- src/funcs.c +++ src/funcs.c 2014-12-17 00:00:00.000000000 +0000 @@ -462,3 +462,43 @@ file_replace(struct magic_set *ms, const return nm; } } + +protected file_pushbuf_t * +file_push_buffer(struct magic_set *ms) +{ + file_pushbuf_t *pb; + + if (ms->event_flags & EVENT_HAD_ERR) + return NULL; + + if ((pb = (CAST(file_pushbuf_t *, malloc(sizeof(*pb))))) == NULL) + return NULL; + + pb->buf = ms->o.buf; + pb->offset = ms->offset; + + ms->o.buf = NULL; + ms->offset = 0; + + return pb; +} + +protected char * +file_pop_buffer(struct magic_set *ms, file_pushbuf_t *pb) +{ + char *rbuf; + + if (ms->event_flags & EVENT_HAD_ERR) { + free(pb->buf); + free(pb); + return NULL; + } + + rbuf = ms->o.buf; + + ms->o.buf = pb->buf; + ms->offset = pb->offset; + + free(pb); + return rbuf; +} --- src/softmagic.c +++ src/softmagic.c 2014-12-17 00:00:00.000000000 +0000 @@ -63,6 +63,9 @@ private void cvt_32(union VALUETYPE *, c private void cvt_64(union VALUETYPE *, const struct magic *); #define OFFSET_OOB(n, o, i) ((n) < (o) || (i) > ((n) - (o))) + +#define MAX_RECURSION_LEVEL 10 + /* * softmagic - lookup one file in parsed, in-memory copy of database * Passed the name and FILE * of one file to be typed. @@ -1124,14 +1127,15 @@ mget(struct magic_set *ms, const unsigne int flip, int recursion_level, int *printed_something, int *need_separator, int *returnval) { - uint32_t soffset, offset = ms->offset; + uint32_t offset = ms->offset; uint32_t count = m->str_range; int rv, oneed_separator, in_type; - char *sbuf, *rbuf; + file_pushbuf_t *pb; + char *rbuf; union VALUETYPE *p = &ms->ms_value; struct mlist ml; - if (recursion_level >= 20) { + if (recursion_level >= MAX_RECURSION_LEVEL) { file_error(ms, 0, "recursion nesting exceeded"); return -1; } @@ -1709,17 +1713,20 @@ mget(struct magic_set *ms, const unsigne return 0; if (OFFSET_OOB(nbytes, offset, 0)) return 0; - sbuf = ms->o.buf; - soffset = ms->offset; - ms->o.buf = NULL; - ms->offset = 0; + + if ((pb = file_push_buffer(ms)) == NULL) + return -1; + rv = file_softmagic(ms, s + offset, nbytes - offset, recursion_level, BINTEST, text); + if ((ms->flags & MAGIC_DEBUG) != 0) fprintf(stderr, "indirect @offs=%u[%d]\n", offset, rv); - rbuf = ms->o.buf; - ms->o.buf = sbuf; - ms->offset = soffset; + + rbuf = file_pop_buffer(ms, pb); + if (rbuf == NULL) + return -1; + if (rv == 1) { if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 && file_printf(ms, m->desc, offset) == -1) @@ -1733,13 +1740,13 @@ mget(struct magic_set *ms, const unsigne case FILE_USE: if (OFFSET_OOB(nbytes, offset, 0)) return 0; - sbuf = m->value.s; - if (*sbuf == '^') { - sbuf++; + rbuf = m->value.s; + if (*rbuf == '^') { + rbuf++; flip = !flip; } - if (file_magicfind(ms, sbuf, &ml) == -1) { - file_error(ms, 0, "cannot find entry `%s'", sbuf); + if (file_magicfind(ms, rbuf, &ml) == -1) { + file_error(ms, 0, "cannot find entry `%s'", rbuf); return -1; }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor