From: Christos Zoulas Date: Sun, 25 Mar 2007 03:13:47 +0000 (+0000) Subject: always compile file_check_memory as protected. X-Git-Tag: FILE5_05~629 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e1ac047638376453d5e0dd37260ad8b1d62c083;p=file always compile file_check_memory as protected. --- diff --git a/src/file.h b/src/file.h index 83034527..cc8b4d29 100644 --- a/src/file.h +++ b/src/file.h @@ -27,7 +27,7 @@ */ /* * file.h - definitions for file(1) program - * @(#)$File: file.h,v 1.90 2007/03/12 15:43:21 christos Exp $ + * @(#)$File: file.h,v 1.91 2007/03/25 03:13:47 christos Exp $ */ #ifndef __file_h__ @@ -324,9 +324,7 @@ protected void file_showstr(FILE *, const char *, size_t); protected size_t file_mbswidth(const char *); protected const char *file_getbuffer(struct magic_set *); protected ssize_t sread(int, void *, size_t, int); -#ifdef ENABLE_CONDITIONALS protected int file_check_mem(struct magic_set *, unsigned int); -#endif #ifndef COMPILE_ONLY extern const char *file_names[]; diff --git a/src/funcs.c b/src/funcs.c index c5b812ac..f65bd453 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -39,7 +39,7 @@ #endif #ifndef lint -FILE_RCSID("@(#)$File: funcs.c,v 1.28 2007/03/01 22:14:54 christos Exp $") +FILE_RCSID("@(#)$File: funcs.c,v 1.29 2007/03/25 03:13:47 christos Exp $") #endif /* lint */ #ifndef HAVE_VSNPRINTF @@ -307,6 +307,27 @@ file_getbuffer(struct magic_set *ms) return ms->o.pbuf; } +protected int +file_check_mem(struct magic_set *ms, unsigned int level) +{ + size_t len; + + if (level >= ms->c.len) { + len = (ms->c.len += 20) * sizeof(*ms->c.li); + ms->c.li = (ms->c.li == NULL) ? malloc(len) : + realloc(ms->c.li, len); + if (ms->c.li == NULL) { + file_oomem(ms, len); + return -1; + } + } + ms->c.li[level].got_match = 0; +#ifdef ENABLE_CONDITIONALS + ms->c.li[level].last_match = 0; + ms->c.li[level].last_cond = COND_NONE; +#endif /* ENABLE_CONDITIONALS */ + return 0; +} /* * Yes these wrappers suffer from buffer overflows, but if your OS does not * have the real functions, maybe you should consider replacing your OS? diff --git a/src/softmagic.c b/src/softmagic.c index f49cefc3..6cc0c7dc 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -38,7 +38,7 @@ #ifndef lint -FILE_RCSID("@(#)$File: softmagic.c,v 1.96 2007/03/05 02:41:29 christos Exp $") +FILE_RCSID("@(#)$File: softmagic.c,v 1.97 2007/03/25 03:13:47 christos Exp $") #endif /* lint */ private int match(struct magic_set *, struct magic *, uint32_t, @@ -74,32 +74,6 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes) return 0; } -#ifdef ENABLE_CONDITIONALS -protected int -#else -private int -#endif -file_check_mem(struct magic_set *ms, unsigned int level) -{ - size_t len; - - if (level >= ms->c.len) { - len = (ms->c.len += 20) * sizeof(*ms->c.li); - ms->c.li = (ms->c.li == NULL) ? malloc(len) : - realloc(ms->c.li, len); - if (ms->c.li == NULL) { - file_oomem(ms, len); - return -1; - } - } - ms->c.li[level].got_match = 0; -#ifdef ENABLE_CONDITIONALS - ms->c.li[level].last_match = 0; - ms->c.li[level].last_cond = COND_NONE; -#endif /* ENABLE_CONDITIONALS */ - return 0; -} - /* * Go through the whole list, stopping if you find a match. Process all * the continuations of that match before returning.