summaryrefslogtreecommitdiff
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
parent8d3275d8b86d0bbb0d57442cceda9bb0208f72df (diff)
parent18de719b19032a5d576bb9b8e5cf3794860eefce (diff)
downloadipaddrcheck-6075d3d1e211173209dc4ad3fbf01ece0e67764f.tar.gz
ipaddrcheck-6075d3d1e211173209dc4ad3fbf01ece0e67764f.zip
Merge pull request #16 from sarthurdev/T7557
T7557: Use PCRE2
-rw-r--r--configure.ac2
-rw-r--r--debian/control4
-rw-r--r--src/Makefile.am4
-rw-r--r--src/ipaddrcheck_functions.c22
-rw-r--r--src/ipaddrcheck_functions.h4
-rw-r--r--tests/Makefile.am4
6 files changed, 25 insertions, 15 deletions
diff --git a/configure.ac b/configure.ac
index 567bfd9..482523c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4,7 +4,6 @@ AC_COPYRIGHT([Copyright (c) 2024 VyOS maintainers and contributors.])
#AC_PROG_CC
AM_PROG_CC_C_O
-AC_CHECK_HEADER([pcre.h], [], [AC_MSG_FAILURE([pcre.h is not found.])])
AC_CHECK_HEADER([libcidr.h], [], [AC_MSG_FAILURE([libcidr.h is not found.])])
AM_INIT_AUTOMAKE([gnu no-dist-gzip dist-bzip2 subdir-objects])
@@ -14,5 +13,6 @@ AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile man/Makefile])
AC_CONFIG_HEADERS([src/config.h])
PKG_CHECK_MODULES([CHECK], [check >= 0.9.4])
+PKG_CHECK_MODULES([PCRE2], [libpcre2-8])
AC_OUTPUT
diff --git a/debian/control b/debian/control
index ac61240..bc6785a 100644
--- a/debian/control
+++ b/debian/control
@@ -2,11 +2,11 @@ Source: ipaddrcheck
Section: contrib/net
Priority: extra
Maintainer: VyOS Package Maintainers <maintainers@vyos.net>
-Build-Depends: autoconf, debhelper (>= 9), libpcre3-dev, libcidr-dev, check
+Build-Depends: autoconf, debhelper (>= 9), libpcre2-dev, libcidr-dev, check
Standards-Version: 3.9.6
Package: ipaddrcheck
Architecture: any
-Depends: libpcre3, libcidr0, ${shlibs:Depends}, ${misc:Depends}
+Depends: libpcre2-8-0, libcidr0, ${shlibs:Depends}, ${misc:Depends}
Description: IPv4 and IPv6 address validation utility
A validation utility for IPv4 and IPv6 addresses.
diff --git a/src/Makefile.am b/src/Makefile.am
index 6098ae5..ce8ea59 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,7 @@
AM_CFLAGS = --pedantic -Wall -Werror -std=c99 -O2
-AM_LDFLAGS =
+AM_CPPFLAGS = $(PCRE2_CFLAGS)
ipaddrcheck_SOURCES = ipaddrcheck.c ipaddrcheck_functions.c
-ipaddrcheck_LDADD = -lcidr -lpcre
+ipaddrcheck_LDADD = -lcidr $(PCRE2_LIBS)
bin_PROGRAMS = ipaddrcheck
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;
}
diff --git a/src/ipaddrcheck_functions.h b/src/ipaddrcheck_functions.h
index 9b5e55f..b717d74 100644
--- a/src/ipaddrcheck_functions.h
+++ b/src/ipaddrcheck_functions.h
@@ -23,11 +23,13 @@
#ifndef IPADDRCHECK_FUNCTIONS_H
#define IPADDRCHECK_FUNCTIONS_H
+#define PCRE2_CODE_UNIT_WIDTH 8
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
-#include <pcre.h>
+#include <pcre2.h>
#include <libcidr.h>
#define INVALID_PROTO -1
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5c0a09a..f7b824a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,3 +1,5 @@
+AM_CPPFLAGS = $(PCRE2_CFLAGS)
+
TESTS = check_ipaddrcheck integration_tests.sh
TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) PATH=.:$(top_srcdir)/src:$$PATH
@@ -5,4 +7,4 @@ TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) PATH=.:$(top_srcdir)/src:$$PATH
check_PROGRAMS = check_ipaddrcheck
check_ipaddrcheck_SOURCES = check_ipaddrcheck.c ../src/ipaddrcheck_functions.c
check_ipaddrcheck_CFLAGS = @CHECK_CFLAGS@
-check_ipaddrcheck_LDADD = -lcidr -lpcre @CHECK_LIBS@
+check_ipaddrcheck_LDADD = -lcidr $(PCRE2_LIBS) @CHECK_LIBS@