Skip to content
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
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
4 changes: 2 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
@@ -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
22 changes: 14 additions & 8 deletions src/ipaddrcheck_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider casting the result of strlen(str) to PCRE2_SIZE (e.g., (PCRE2_SIZE)strlen(str)) to match the expected type for the length parameter in pcre2_match.

Suggested change
rc = pcre2_match(re, (PCRE2_SPTR)str, strlen(str), 0, 0, match, NULL);
rc = pcre2_match(re, (PCRE2_SPTR)str, (PCRE2_SIZE)strlen(str), 0, 0, match, NULL);

Copilot uses AI. Check for mistakes.

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;
}


Expand Down
4 changes: 3 additions & 1 deletion src/ipaddrcheck_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
AM_CPPFLAGS = $(PCRE2_CFLAGS)

TESTS = check_ipaddrcheck integration_tests.sh

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@