|
|
a60c34 |
diff -urp file-5.33.orig/src/softmagic.c file-5.33/src/softmagic.c
|
|
|
a60c34 |
--- file-5.33.orig/src/softmagic.c 2020-12-14 12:26:50.286849841 -0500
|
|
|
a60c34 |
+++ file-5.33/src/softmagic.c 2020-12-14 12:35:52.679166211 -0500
|
|
|
a60c34 |
@@ -1748,7 +1748,8 @@ mget(struct magic_set *ms, struct magic
|
|
|
a60c34 |
}
|
|
|
a60c34 |
|
|
|
a60c34 |
private uint64_t
|
|
|
a60c34 |
-file_strncmp(const char *s1, const char *s2, size_t len, uint32_t flags)
|
|
|
a60c34 |
+file_strncmp(const char *s1, const char *s2, size_t len, size_t maxlen,
|
|
|
a60c34 |
+ uint32_t flags)
|
|
|
a60c34 |
{
|
|
|
a60c34 |
/*
|
|
|
a60c34 |
* Convert the source args to unsigned here so that (1) the
|
|
|
a60c34 |
@@ -1760,7 +1761,7 @@ file_strncmp(const char *s1, const char
|
|
|
a60c34 |
const unsigned char *b = (const unsigned char *)s2;
|
|
|
a60c34 |
uint32_t ws = flags & (STRING_COMPACT_WHITESPACE |
|
|
|
a60c34 |
STRING_COMPACT_OPTIONAL_WHITESPACE);
|
|
|
a60c34 |
- const unsigned char *eb = b + (ws ? strlen(s2) : len);
|
|
|
a60c34 |
+ const unsigned char *eb = b + (ws ? maxlen : len);
|
|
|
a60c34 |
uint64_t v;
|
|
|
a60c34 |
|
|
|
a60c34 |
/*
|
|
|
a60c34 |
@@ -1818,7 +1819,8 @@ file_strncmp(const char *s1, const char
|
|
|
a60c34 |
}
|
|
|
a60c34 |
|
|
|
a60c34 |
private uint64_t
|
|
|
a60c34 |
-file_strncmp16(const char *a, const char *b, size_t len, uint32_t flags)
|
|
|
a60c34 |
+file_strncmp16(const char *a, const char *b, size_t len, size_t maxlen,
|
|
|
a60c34 |
+ uint32_t flags)
|
|
|
a60c34 |
{
|
|
|
a60c34 |
/*
|
|
|
a60c34 |
* XXX - The 16-bit string compare probably needs to be done
|
|
|
a60c34 |
@@ -1826,7 +1828,7 @@ file_strncmp16(const char *a, const char
|
|
|
a60c34 |
* At the moment, I am unsure.
|
|
|
a60c34 |
*/
|
|
|
a60c34 |
flags = 0;
|
|
|
a60c34 |
- return file_strncmp(a, b, len, flags);
|
|
|
a60c34 |
+ return file_strncmp(a, b, len, maxlen, flags);
|
|
|
a60c34 |
}
|
|
|
a60c34 |
|
|
|
a60c34 |
private int
|
|
|
a60c34 |
@@ -1954,13 +1956,15 @@ magiccheck(struct magic_set *ms, struct
|
|
|
a60c34 |
case FILE_STRING:
|
|
|
a60c34 |
case FILE_PSTRING:
|
|
|
a60c34 |
l = 0;
|
|
|
a60c34 |
- v = file_strncmp(m->value.s, p->s, (size_t)m->vallen, m->str_flags);
|
|
|
a60c34 |
+ v = file_strncmp(m->value.s, p->s, (size_t)m->vallen,
|
|
|
a60c34 |
+ sizeof(p->s), m->str_flags);
|
|
|
a60c34 |
break;
|
|
|
a60c34 |
|
|
|
a60c34 |
case FILE_BESTRING16:
|
|
|
a60c34 |
case FILE_LESTRING16:
|
|
|
a60c34 |
l = 0;
|
|
|
a60c34 |
- v = file_strncmp16(m->value.s, p->s, (size_t)m->vallen, m->str_flags);
|
|
|
a60c34 |
+ v = file_strncmp16(m->value.s, p->s, (size_t)m->vallen,
|
|
|
a60c34 |
+ sizeof(p->s), m->str_flags);
|
|
|
a60c34 |
break;
|
|
|
a60c34 |
|
|
|
a60c34 |
case FILE_SEARCH: { /* search ms->search.s for the string m->value.s */
|
|
|
a60c34 |
@@ -1979,7 +1983,7 @@ magiccheck(struct magic_set *ms, struct
|
|
|
a60c34 |
return 0;
|
|
|
a60c34 |
|
|
|
a60c34 |
v = file_strncmp(m->value.s, ms->search.s + idx, slen,
|
|
|
a60c34 |
- m->str_flags);
|
|
|
a60c34 |
+ ms->search.s_len - idx, m->str_flags);
|
|
|
a60c34 |
if (v == 0) { /* found match */
|
|
|
a60c34 |
ms->search.offset += idx;
|
|
|
a60c34 |
ms->search.rm_len = ms->search.s_len - idx;
|