From: Christos Zoulas Date: Sun, 21 Nov 2004 06:09:43 +0000 (+0000) Subject: Fix thinko. X-Git-Tag: FILE4_11~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=918abb1080bb2f3c0ad6547eed378ea90fecf2bb;p=file Fix thinko. --- diff --git a/src/softmagic.c b/src/softmagic.c index 3cc0c2cf..912215d9 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -39,7 +39,7 @@ #ifndef lint -FILE_RCSID("@(#)$Id: softmagic.c,v 1.70 2004/11/20 23:50:13 christos Exp $") +FILE_RCSID("@(#)$Id: softmagic.c,v 1.71 2004/11/21 06:09:43 christos Exp $") #endif /* lint */ private int match(struct magic_set *, struct magic *, uint32_t, @@ -647,7 +647,13 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir, return 0; } - if (offset + sizeof(*p) <= nbytes) + if (offset >= nbytes) { + (void)memset(p, '\0', sizeof(*p)); + return 0; + } + if (nbytes - offset < sizeof(*p)) + nbytes = nbytes - offset; + else nbytes = sizeof(*p); (void)memcpy(p, s + offset, nbytes); @@ -657,7 +663,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir, * might even cause problems */ if (nbytes < sizeof(*p)) - (void)memset(p + nbytes, 0, sizeof(*p) - nbytes); + (void)memset(p + nbytes, '\0', sizeof(*p) - nbytes); return 0; }