Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make regex matching case-insensitive by default #732

Merged
merged 1 commit into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,6 @@ void read_FTLconf(void)
else
logg(" PARSE_ARP_CACHE: Inactive");

// REGEX_IGNORECASE
// defaults to: false
config.regex_ignorecase = false;
buffer = parse_FTLconf(fp, "REGEX_IGNORECASE");

if(buffer != NULL && strcasecmp(buffer, "true") == 0)
config.regex_ignorecase = true;

if(config.regex_ignorecase)
logg(" REGEX_IGNORECASE: Enabled. Regex is case insensitive");
else
logg(" REGEX_IGNORECASE: Disabled. Regex is case sensitive");

// CNAME_DEEP_INSPECT
// defaults to: true
config.cname_inspection = true;
Expand Down
1 change: 0 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ typedef struct {
bool analyze_only_A_AAAA;
bool DBimport;
bool parse_arp_cache;
bool regex_ignorecase;
bool cname_inspection;
} ConfigStruct;

Expand Down
13 changes: 6 additions & 7 deletions src/regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ static char **regexbuffer[2] = { NULL };

const char *regextype[] = { "blacklist", "whitelist" };

// Log Regex failure (most likely a regex syntax error, we include a hint to the error)
static void log_regex_error(const int errcode, const int index, const unsigned char regexid, const char *regexin)
{
// Regex failed for some reason (probably user syntax error)
// Get error string and log it
const size_t length = regerror(errcode, &regex[regexid][index], NULL, 0);
char *buffer = calloc(length,sizeof(char));
Expand All @@ -41,14 +41,13 @@ static void log_regex_error(const int errcode, const int index, const unsigned c
free(buffer);
}

/* Compile regular expressions into data structures that can be used with
regexec() to match against a string */
static bool compile_regex(const char *regexin, const int index, const unsigned char regexid)
{
// compile regular expressions into data structures that
// can be used with regexec to match against a string
int regflags = REG_EXTENDED;
if(config.regex_ignorecase)
regflags |= REG_ICASE;
const int errcode = regcomp(&regex[regexid][index], regexin, regflags);
// We use the extended RegEx flavor (ERE) and specify that matching should
// always be case INsensitive
const int errcode = regcomp(&regex[regexid][index], regexin, REG_EXTENDED | REG_ICASE);
if(errcode != 0)
{
log_regex_error(errcode, index, regexid, regexin);
Expand Down