From: Christos Zoulas Date: Thu, 28 Feb 2019 12:52:56 +0000 (+0000) Subject: Simplify and always return if not found (found by OSS-fuzz) X-Git-Tag: FILE5_37~57 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dcda2612a5f38a3d9e15c0ac9a7d156d74b3a395;p=file Simplify and always return if not found (found by OSS-fuzz) --- diff --git a/src/softmagic.c b/src/softmagic.c index 9999ef6f..2befe35f 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: softmagic.c,v 1.279 2019/02/27 16:52:23 christos Exp $") +FILE_RCSID("@(#)$File: softmagic.c,v 1.280 2019/02/28 12:52:56 christos Exp $") #endif /* lint */ #include "magic.h" @@ -2066,23 +2066,15 @@ magiccheck(struct magic_set *ms, struct magic *m) #ifdef HAVE_MEMMEM if (slen > 0 && m->str_flags == 0) { const char *found; - if (m->str_range != 0 - && ms->search.s_len >= m->str_range + slen) { - found = memmem(ms->search.s, - m->str_range + slen, m->value.s, slen); - } else { - found = memmem(ms->search.s, - ms->search.s_len, m->value.s, slen); - if (!found) - return 0; - } - if (!found) { - v = 1; - } else { - idx = found - ms->search.s; - ms->search.offset += idx; - ms->search.rm_len = ms->search.s_len - idx; - } + idx = m->str_range + slen; + if (m->str_range == 0 || ms->search.s_len < idx) + idx = ms->search.s_len; + found = memmem(ms->search.s, idx, m->value.s, slen); + if (!found) + return 0; + idx = found - ms->search.s; + ms->search.offset += idx; + ms->search.rm_len = ms->search.s_len - idx; break; } #endif