diff options
author | obrien <obrien@FreeBSD.org> | 2003-02-28 05:19:36 +0000 |
---|---|---|
committer | obrien <obrien@FreeBSD.org> | 2003-02-28 05:19:36 +0000 |
commit | f35360c37203a2efe4238a8ec8dd5c45cde0820b (patch) | |
tree | 1705752f770500133cc84f6e74036f0089e1421d /contrib/file/softmagic.c | |
parent | 822cce384d16c9a63f80e0c0765717d4a329368d (diff) | |
download | FreeBSD-src-f35360c37203a2efe4238a8ec8dd5c45cde0820b.zip FreeBSD-src-f35360c37203a2efe4238a8ec8dd5c45cde0820b.tar.gz |
Virgin import of Christos Zoulas's FILE 3.41.
* - fix memory allocation problem (Jeff Johnson)
* - fix stack overflow corruption (David Endler)
Diffstat (limited to 'contrib/file/softmagic.c')
-rw-r--r-- | contrib/file/softmagic.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/contrib/file/softmagic.c b/contrib/file/softmagic.c index 8ef5fbf..d1ef94d 100644 --- a/contrib/file/softmagic.c +++ b/contrib/file/softmagic.c @@ -34,7 +34,7 @@ #ifndef lint -FILE_RCSID("@(#)$Id: softmagic.c,v 1.52 2003/02/08 18:33:53 christos Exp $") +FILE_RCSID("@(#)$Id: softmagic.c,v 1.54 2003/02/25 13:04:32 christos Exp $") #endif /* lint */ static int match(struct magic *, uint32_t, unsigned char *, int); @@ -105,7 +105,8 @@ match(struct magic *magic, uint32_t nmagic, unsigned char *s, int nbytes) int firstline = 1; /* a flag to print X\n X\n- X */ if (tmpoff == NULL) - if ((tmpoff = (int32_t *) malloc(tmplen = 20)) == NULL) + if ((tmpoff = (int32_t *) malloc( + (tmplen = 20) * sizeof(*tmpoff))) == NULL) error("out of memory\n"); for (magindex = 0; magindex < nmagic; magindex++) { @@ -137,7 +138,7 @@ match(struct magic *magic, uint32_t nmagic, unsigned char *s, int nbytes) /* and any continuations that match */ if (++cont_level >= tmplen) if ((tmpoff = (int32_t *) realloc(tmpoff, - tmplen += 20)) == NULL) + (tmplen += 20) * sizeof(*tmpoff))) == NULL) error("out of memory\n"); while (magic[magindex+1].cont_level != 0 && ++magindex < nmagic) { @@ -184,7 +185,8 @@ match(struct magic *magic, uint32_t nmagic, unsigned char *s, int nbytes) if (++cont_level >= tmplen) if ((tmpoff = (int32_t *) realloc(tmpoff, - tmplen += 20)) == NULL) + (tmplen += 20) + * sizeof(*tmpoff))) == NULL) error("out of memory\n"); } if (magic[magindex].flag & OFFADD) { |