1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-13 03:09:02 +00:00

Upgrade libpcre2 to 10.43

This commit is contained in:
dmiller
2024-02-28 16:06:30 +00:00
parent 38aa74ae83
commit 34da72b5f5
50 changed files with 20826 additions and 5158 deletions

View File

@@ -40,25 +40,27 @@ POSSIBILITY OF SUCH DAMAGE.
/* This module is a wrapper that provides a POSIX API to the underlying PCRE2
functions. The operative functions are called pcre2_regcomp(), etc., with
wrappers that use the plain POSIX names. In addition, pcre2posix.h defines the
POSIX names as macros for the pcre2_xxx functions, so any program that includes
it and uses the POSIX names will call the base functions directly. This makes
it easier for an application to be sure it gets the PCRE2 versions in the
presence of other POSIX regex libraries. */
functions. The functions are called pcre2_regcomp(), pcre2_regexec(), etc.
pcre2posix.h defines the POSIX names as macros for the corresonding pcre2_xxx
functions, so any program that includes it and uses the POSIX names will call
the PCRE2 implementations instead. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef PCRE2POSIX_SHARED
#undef PCRE2_STATIC
#endif
/* Ensure that the PCRE2POSIX_EXP_xxx macros are set appropriately for
compiling these functions. This must come before including pcre2posix.h, where
they are set for an application (using these functions) if they have not
previously been set. */
#if defined(_WIN32) && !defined(PCRE2_STATIC)
#if defined(_WIN32) && (defined(PCRE2POSIX_SHARED) || !defined(PCRE2_STATIC))
# define PCRE2POSIX_EXP_DECL extern __declspec(dllexport)
# define PCRE2POSIX_EXP_DEFN __declspec(dllexport)
#endif
@@ -69,6 +71,7 @@ MSVC 10/2010. Except for VC6 (which is missing some fundamentals and fails). */
#if defined(_MSC_VER) && (_MSC_VER < 1900)
#define snprintf _snprintf
#define BROKEN_SNPRINTF
#endif
@@ -160,68 +163,14 @@ static const char *const pstring[] = {
"match failed" /* NOMATCH */
};
#if 0 /* REMOVE THIS CODE */
The code below was created for 10.33 (see ChangeLog 10.33 #4) when the
POSIX functions were given pcre2_... names instead of the traditional POSIX
names. However, it has proved to be more troublesome than useful. There have
been at least two cases where a program links with two others, one of which
uses the POSIX library and the other uses the PCRE2 POSIX functions, thus
causing two instances of the POSIX runctions to exist, leading to trouble. For
10.37 this code is commented out. In due course it can be removed if there are
no issues. The only small worry is the comment below about languages that do
not include pcre2posix.h. If there are any such cases, they will have to use
the PCRE2 names.
/*************************************************
* Wrappers with traditional POSIX names *
*************************************************/
/* Keep defining them to preseve the ABI for applications linked to the pcre2
POSIX library before these names were changed into macros in pcre2posix.h.
This also ensures that the POSIX names are callable from languages that do not
include pcre2posix.h. It is vital to #undef the macro definitions from
pcre2posix.h! */
#undef regerror
PCRE2POSIX_EXP_DECL size_t regerror(int, const regex_t *, char *, size_t);
PCRE2POSIX_EXP_DEFN size_t PCRE2_CALL_CONVENTION
regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
static int message_len(const char *message, int offset)
{
return pcre2_regerror(errcode, preg, errbuf, errbuf_size);
}
char buf[12];
#undef regfree
PCRE2POSIX_EXP_DECL void regfree(regex_t *);
PCRE2POSIX_EXP_DEFN void PCRE2_CALL_CONVENTION
regfree(regex_t *preg)
{
pcre2_regfree(preg);
/* 11 magic number comes from the format below */
return (int)strlen(message) + 11 + snprintf(buf, sizeof(buf), "%d", offset);
}
#undef regcomp
PCRE2POSIX_EXP_DECL int regcomp(regex_t *, const char *, int);
PCRE2POSIX_EXP_DEFN int PCRE2_CALL_CONVENTION
regcomp(regex_t *preg, const char *pattern, int cflags)
{
return pcre2_regcomp(preg, pattern, cflags);
}
#undef regexec
PCRE2POSIX_EXP_DECL int regexec(const regex_t *, const char *, size_t,
regmatch_t *, int);
PCRE2POSIX_EXP_DEFN int PCRE2_CALL_CONVENTION
regexec(const regex_t *preg, const char *string, size_t nmatch,
regmatch_t pmatch[], int eflags)
{
return pcre2_regexec(preg, string, nmatch, pmatch, eflags);
}
#endif
/*************************************************
* Translate error code to string *
*************************************************/
@@ -230,23 +179,64 @@ PCRE2POSIX_EXP_DEFN size_t PCRE2_CALL_CONVENTION
pcre2_regerror(int errcode, const regex_t *preg, char *errbuf,
size_t errbuf_size)
{
int used;
int ret;
const char *message;
size_t len = 0; /* keeps 0 if snprintf is used */
message = (errcode <= 0 || errcode >= (int)(sizeof(pstring)/sizeof(char *)))?
"unknown error code" : pstring[errcode];
if (preg != NULL && (int)preg->re_erroffset != -1)
{
used = snprintf(errbuf, errbuf_size, "%s at offset %-6d", message,
(int)preg->re_erroffset);
/* no need to deal with UB in snprintf */
if (errbuf_size > INT_MAX) errbuf_size = INT_MAX;
/* there are 11 charactes between message and offset,
update message_len() if changed */
ret = snprintf(errbuf, errbuf_size, "%s at offset %d", message,
(int)preg->re_erroffset);
}
else
{
used = snprintf(errbuf, errbuf_size, "%s", message);
len = strlen(message);
if (errbuf_size != 0)
{
strncpy(errbuf, message, errbuf_size);
if (errbuf_size <= len) errbuf[errbuf_size - 1] = '\0';
}
ret = (int)len;
}
return used + 1;
do {
if (ret < 0)
{
#ifdef BROKEN_SNPRINTF
/* _snprintf returns -1 on overflow and doesn't zero terminate */
if (!len)
{
if (ret == -1 && errbuf_size != 0) errbuf[errbuf_size - 1] = '\0';
ret = message_len(message, (int)preg->re_erroffset);
break;
}
#endif
/* snprintf failed, will use a 14 char long message if possible */
ret = 14;
if (errbuf_size != 0)
{
strncpy(errbuf, "internal error", errbuf_size);
if ((int)errbuf_size <= ret) errbuf[errbuf_size - 1] = '\0';
}
}
else if (ret == (int)errbuf_size && !len)
{
/* pre C99 snprintf returns used, so redo ret to fix that */
ret = message_len(message, (int)preg->re_erroffset);
}
} while (0);
return ret + 1;
}