Skip to content

Commit

Permalink
Allow for wide chars in needles
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanusz-r7 committed Dec 1, 2023
1 parent 616d785 commit e588bad
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions c/meterpreter/source/tiny-regex-c/re.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,11 @@ int re_compile(const char* pattern, size_t pattern_length, size_t max_regex_obje
} break;
}
}
/* '\\' as last char in pattern -> invalid regular expression. */
/*
else
{
(*out_compiled)[j].type = CHAR;
(*out_compiled)[j].ch = pattern[i];
(*out_compiled)[j].type = CHAR_RE;
(*out_compiled)[j].u.ch = pattern[i];
}
*/
} break;

/* Character class: */
Expand All @@ -150,7 +147,7 @@ int re_compile(const char* pattern, size_t pattern_length, size_t max_regex_obje
{
(*out_compiled)[j].type = INV_CHAR_CLASS;
i += 1; /* Increment i to avoid including '^' in the char-buffer */
if (pattern[i + 1] == 0) /* incomplete pattern, missing non-zero char after '^' */
if (i + 1 == (int)pattern_length) /* incomplete pattern, missing non-zero char after '^' */
{
return 1;
}
Expand All @@ -171,7 +168,7 @@ int re_compile(const char* pattern, size_t pattern_length, size_t max_regex_obje
//fputs("exceeded internal buffer!\n", stderr);
return 1;
}
if (pattern[i + 1] == 0) /* incomplete pattern, missing non-zero char after '\\' */
if (i + 1 == (int)pattern_length) /* incomplete pattern, missing non-zero char after '\\' */
{
return 1;
}
Expand Down Expand Up @@ -202,11 +199,6 @@ int re_compile(const char* pattern, size_t pattern_length, size_t max_regex_obje
(*out_compiled)[j].u.ch = c;
} break;
}
/* no buffer-out-of-bounds access on invalid patterns - see https://github.com/kokke/tiny-regex-c/commit/1a279e04014b70b0695fba559a7c05d55e6ee90b */
if (pattern[i] == 0)
{
return 1;
}

i += 1;
j += 1;
Expand Down

0 comments on commit e588bad

Please sign in to comment.