summaryrefslogtreecommitdiff
path: root/src/ipaddrcheck_functions.c
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2025-06-23 17:25:37 +0100
committerGitHub <noreply@github.com>2025-06-23 17:25:37 +0100
commit6075d3d1e211173209dc4ad3fbf01ece0e67764f (patch)
tree38c936a8be4aa01fc17875ac52f87edee7a4400c /src/ipaddrcheck_functions.c
parent8d3275d8b86d0bbb0d57442cceda9bb0208f72df (diff)
parent18de719b19032a5d576bb9b8e5cf3794860eefce (diff)
downloadipaddrcheck-6075d3d1e211173209dc4ad3fbf01ece0e67764f.tar.gz
ipaddrcheck-6075d3d1e211173209dc4ad3fbf01ece0e67764f.zip
Merge pull request #16 from sarthurdev/T7557
T7557: Use PCRE2
Diffstat (limited to 'src/ipaddrcheck_functions.c')
-rw-r--r--src/ipaddrcheck_functions.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/ipaddrcheck_functions.c b/src/ipaddrcheck_functions.c
index d486d07..fb0e654 100644
--- a/src/ipaddrcheck_functions.c
+++ b/src/ipaddrcheck_functions.c
@@ -41,25 +41,31 @@
int regex_matches(const char* regex, const char* str)
{
- int offsets[1];
- pcre *re;
+ pcre2_code *re;
int rc;
- const char *error;
- int erroffset;
+ int out;
+ int error;
+ PCRE2_SIZE erroffset;
- re = pcre_compile(regex, 0, &error, &erroffset, NULL);
+ re = pcre2_compile((PCRE2_SPTR)regex, PCRE2_ZERO_TERMINATED, 0, &error, &erroffset, NULL);
assert(re != NULL);
- rc = pcre_exec(re, NULL, str, strlen(str), 0, 0, offsets, 1);
+ pcre2_match_data *match = pcre2_match_data_create_from_pattern(re, NULL);
+
+ rc = pcre2_match(re, (PCRE2_SPTR)str, strlen(str), 0, 0, match, NULL);
if( rc >= 0)
{
- return RESULT_SUCCESS;
+ out = RESULT_SUCCESS;
}
else
{
- return RESULT_FAILURE;
+ out = RESULT_FAILURE;
}
+
+ pcre2_match_data_free(match);
+ pcre2_code_free(re);
+ return out;
}