switch to pcre2

This commit is contained in:
vanhauser-thc 2022-03-01 14:56:05 +01:00
parent 330e910a02
commit c82e5d51c5
3 changed files with 23 additions and 18 deletions

View file

@ -2,7 +2,7 @@ Changelog for hydra
-------------------
Release 9.4-dev
* your patch?
* Switched from pcre/pcre3 to pcre2 as pcre/pcre3 will be dropped from Debian
Release 9.3

18
configure vendored
View file

@ -380,21 +380,21 @@ if [ "X" = "X$CURSES_PATH" -o "X" = "X$CURSES_IPATH" ]; then
CURSES_IPATH=""
fi
echo "Checking for pcre (libpcre/pcre.h) ..."
echo "Checking for pcre2 (libpcre/pcre.h) ..."
for i in $LIBDIRS ; do
if [ "X" = "X$PCRE_PATH" ]; then
if [ -f "$i/libpcre.so" -o -f "$i/libpcre.dylib" -o -f "$i/libpcre.a" ]; then
if [ -f "$i/libpcre2-8.so" -o -f "$i/libpcre2-8.dylib" -o -f "$i/libpcre2-8.a" ]; then
PCRE_PATH="$i"
fi
fi
if [ "X" = "X$PCRE_PATH" ]; then
TMP_LIB=`/bin/ls $i/libpcre.so* 2> /dev/null | grep libpcre.`
TMP_LIB=`/bin/ls $i/libpcre2*.so* 2> /dev/null | grep libpcre.`
if [ -n "$TMP_LIB" ]; then
PCRE_PATH="$i"
fi
fi
if [ "X" = "X$PCRE_PATH" ]; then
TMP_LIB=`/bin/ls $i/libpcre.dll* 2> /dev/null | grep libpcre.`
TMP_LIB=`/bin/ls $i/libpcre2*.dll* 2> /dev/null | grep libpcre.`
if [ -n "$TMP_LIB" ]; then
PCRE_PATH="$i"
fi
@ -402,20 +402,20 @@ for i in $LIBDIRS ; do
done
for i in $INCDIRS ; do
if [ "X" != "X$PCRE_PATH" ]; then
if [ -f "$i/pcre.h" ]; then
if [ -f "$i/pcre2.h" ]; then
PCRE_IPATH="$i"
fi
fi
done
if [ "X" != "X$DEBUG" ]; then
echo DEBUG: PCRE_PATH=$PCRE_PATH/libpcre
echo DEBUG: PCRE_IPATH=$PCRE_IPATH/pcre.h
echo DEBUG: PCRE_IPATH=$PCRE_IPATH/pcre2.h
fi
if [ -n "$PCRE_PATH" -a -n "$PCRE_IPATH" ]; then
echo " ... found"
echo " ... found"
fi
if [ "X" = "X$PCRE_PATH" -o "X" = "X$PCRE_IPATH" ]; then
echo " ... NOT found, server response checks will be less reliable"
echo " ... NOT found, server response checks will be less reliable"
PCRE_PATH=""
PCRE_IPATH=""
fi
@ -1649,7 +1649,7 @@ if [ -n "$IDN_PATH" ]; then
XLIBS="$XLIBS -lidn"
fi
if [ -n "$PCRE_PATH" ]; then
XLIBS="$XLIBS -lpcre"
XLIBS="$XLIBS -lpcre2-8"
fi
if [ -n "$MYSQL_PATH" ]; then
XLIBS="$XLIBS -lmysqlclient"

View file

@ -7,7 +7,8 @@
#include <openssl/ssl.h>
#endif
#ifdef HAVE_PCRE
#include <pcre.h>
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>
#endif
#define MAX_CONNECT_RETRY 1
@ -1291,19 +1292,23 @@ void hydra_set_srcport(int32_t port) { src_port = port; }
#ifdef HAVE_PCRE
int32_t hydra_string_match(char *str, const char *regex) {
pcre *re = NULL;
int32_t offset_error = 0;
const char *error = NULL;
pcre2_code *re = NULL;
int32_t error_code = 0;
PCRE2_SIZE error_offset;
int32_t rc = 0;
re = pcre_compile(regex, PCRE_CASELESS | PCRE_DOTALL, &error, &offset_error, NULL);
re = pcre2_compile(regex, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS | PCRE2_DOTALL, &error_code, &error_offset, NULL);
if (re == NULL) {
fprintf(stderr, "[ERROR] PCRE compilation failed at offset %d: %s\n", offset_error, error);
fprintf(stderr, "[ERROR] PCRE compilation failed at offset %d: %d\n", error_offset, error_code);
return 0;
}
rc = pcre_exec(re, NULL, str, strlen(str), 0, 0, NULL, 0);
if (rc >= 0) {
pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(re, NULL);
rc = pcre2_match(re, str, PCRE2_ZERO_TERMINATED, 0, 0, match_data, NULL);
pcre2_match_data_free(match_data);
pcre2_code_free(re);
if (rc >= 1) {
return 1;
}
return 0;