Skip to content

Commit 74cafd7

Browse files
committed
If requested, limit search length.
1 parent bed7cd6 commit 74cafd7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Diff for: src/softmagic.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "file.h"
3333

3434
#ifndef lint
35-
FILE_RCSID("@(#)$File: softmagic.c,v 1.187 2014/05/13 16:42:17 christos Exp $")
35+
FILE_RCSID("@(#)$File: softmagic.c,v 1.188 2014/05/14 23:15:42 christos Exp $")
3636
#endif /* lint */
3737

3838
#include "magic.h"
@@ -1929,15 +1929,23 @@ magiccheck(struct magic_set *ms, struct magic *m)
19291929
file_regerror(&rx, rc, ms);
19301930
v = (uint64_t)-1;
19311931
} else {
1932+
#ifndef REG_STARTEND
1933+
char c;
1934+
#endif
19321935
regmatch_t pmatch[1];
1936+
size_t slen = ms->search.s_len;
1937+
/* Limit by offset if requested */
1938+
if (m->str_range > 0)
1939+
slen = MIN(slen, m->str_range);
19331940
#ifndef REG_STARTEND
19341941
#define REG_STARTEND 0
1935-
size_t l = ms->search.s_len - 1;
1936-
char c = ms->search.s[l];
1937-
((char *)(intptr_t)ms->search.s)[l] = '\0';
1942+
if (slen != 0)
1943+
slen--;
1944+
c = ms->search.s[slen];
1945+
((char *)(intptr_t)ms->search.s)[slen] = '\0';
19381946
#else
19391947
pmatch[0].rm_so = 0;
1940-
pmatch[0].rm_eo = ms->search.s_len;
1948+
pmatch[0].rm_eo = slen;
19411949
#endif
19421950
rc = file_regexec(&rx, (const char *)ms->search.s,
19431951
1, pmatch, REG_STARTEND);

0 commit comments

Comments
 (0)