From a1654beda6041acde36062ea12f4669372c449c0 Mon Sep 17 00:00:00 2001 From: kris Date: Thu, 20 Dec 2007 22:24:53 +0000 Subject: [PATCH] Upgrading libpcre from version 7.2 to 7.4. Tested on Linux and Windows --- CHANGELOG | 2 + libpcre/Makefile.am | 1 - libpcre/Makefile.in | 12 +- libpcre/NMAP_MODIFICATIONS | 90 +++-- libpcre/NON-UNIX-USE | 232 ++++++++---- libpcre/README | 17 +- libpcre/config.h.generic | 39 +- libpcre/config.h.in | 46 +-- libpcre/configure | 58 +-- libpcre/configure.ac | 47 ++- libpcre/dftables.c | 13 +- libpcre/pcre.h | 39 +- libpcre/pcre.h.generic | 39 +- libpcre/pcre.h.in | 35 +- libpcre/pcre_chartables.c | 8 +- libpcre/pcre_chartables.c.dist | 8 +- libpcre/pcre_compile.c | 665 +++++++++++++++++++++++++-------- libpcre/pcre_config.c | 14 + libpcre/pcre_dfa_exec.c | 92 +++-- libpcre/pcre_exec.c | 363 ++++++++++++------ libpcre/pcre_fullinfo.c | 20 +- libpcre/pcre_get.c | 8 +- libpcre/pcre_globals.c | 6 + libpcre/pcre_info.c | 10 +- libpcre/pcre_internal.h | 98 ++--- libpcre/pcre_maketables.c | 7 +- libpcre/pcre_newline.c | 10 + libpcre/pcre_ord2utf8.c | 5 + libpcre/pcre_refcount.c | 7 + libpcre/pcre_study.c | 9 +- libpcre/pcre_tables.c | 333 +++++++++++------ libpcre/pcre_try_flipped.c | 7 + libpcre/pcre_ucp_searchfuncs.c | 6 + libpcre/pcre_valid_utf8.c | 48 ++- libpcre/pcre_version.c | 6 + libpcre/pcre_xclass.c | 6 + libpcre/pcreposix.c | 23 +- libpcre/pcreposix.h | 11 +- 38 files changed, 1728 insertions(+), 712 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index dce818f09..7272bf494 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -42,6 +42,8 @@ o Nmap's output options (-oA, -oX, etc.) now support strftime()-like means that "-oX 'scan-%T-%D.xml'" uses an XML file in the form of "scan-144840-121307.xml". [Kris] +o Upgraded the shipped LibPCRE from version 7.2 to 7.4 [Kris] + o Added a new NSE script (MySQLinfo) which prints MySQL server information such as the protocol and version numbers, status, thread id, capabilities, and password salt. [Kris] diff --git a/libpcre/Makefile.am b/libpcre/Makefile.am index 8e422f98a..d56075d66 100644 --- a/libpcre/Makefile.am +++ b/libpcre/Makefile.am @@ -80,4 +80,3 @@ nodist_libpcre_a_SOURCES = pcre_chartables.c # A compatibility line, the old build system worked with 'make test' test: check ; -## end Makefile.am diff --git a/libpcre/Makefile.in b/libpcre/Makefile.in index 990628e8c..6d6c5b968 100644 --- a/libpcre/Makefile.in +++ b/libpcre/Makefile.in @@ -40,10 +40,12 @@ noinst_PROGRAMS = $(am__EXEEXT_1) @WITH_REBUILD_CHARTABLES_TRUE@am__append_1 = dftables subdir = . DIST_COMMON = README $(am__configure_deps) $(include_HEADERS) \ - $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ - $(srcdir)/config.h.in $(srcdir)/pcre-config.in \ - $(srcdir)/pcre.h.in $(top_srcdir)/configure AUTHORS INSTALL \ - config.guess config.sub depcomp install-sh missing + $(srcdir)/../config.guess $(srcdir)/../config.sub \ + $(srcdir)/../depcomp $(srcdir)/../install-sh \ + $(srcdir)/../missing $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in $(srcdir)/config.h.in \ + $(srcdir)/pcre-config.in $(srcdir)/pcre.h.in \ + $(top_srcdir)/configure AUTHORS INSTALL ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ @@ -92,7 +94,7 @@ dftables_LDADD = $(LDADD) binSCRIPT_INSTALL = $(INSTALL_SCRIPT) SCRIPTS = $(bin_SCRIPTS) DEFAULT_INCLUDES = -I.@am__isrc@ -depcomp = $(SHELL) $(top_srcdir)/depcomp +depcomp = $(SHELL) $(top_srcdir)/../depcomp am__depfiles_maybe = depfiles COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) diff --git a/libpcre/NMAP_MODIFICATIONS b/libpcre/NMAP_MODIFICATIONS index b25d32516..e3d3f95e7 100644 --- a/libpcre/NMAP_MODIFICATIONS +++ b/libpcre/NMAP_MODIFICATIONS @@ -1,4 +1,4 @@ -This directory conains a version of LibPCRE 7.2 that has been stripped +This directory contains a version of LibPCRE 7.4 that has been stripped down to less than a third of its original uncompressed size. So if you want docs, tests and such, you should go to the PCRE website at http://www.pcre.org . Here are the changes for the Nmap version: @@ -30,13 +30,14 @@ makevp_c.txt makevp_l.txt pcregexp.pas ltmain.sh +CleanTxt ChangeLog NEWS HACKING COPYING [Look at LICENCE] o Got rid of the C++ wrapper, which included this step: - rm -f *.cc pcrecpparg.h.in pcrecpp.h pcre_scanner.h pcre_stringpiece.h.in + rm -f *.cc pcrecpparg.h.in pcrecpp.h pcrecpp_internal.h pcre_scanner.h pcre_stringpiece.h.in o Copied pcre.h.generic to pcre.h and pcre_chartables.c.dist to, you guessed it, pcre_chartables.c (for Windows). Running ./configure in @@ -56,17 +57,17 @@ o Stripped down Makefile.am and configure.ac substantially to remove o Removed config.sub, config.guess, depcomp, install-sh, and missing. These files are found in the parent (i.e., Nmap's) directory. -o Comment out some build configuration lines from pcre-internal.h because Nmap +o Comment out some build configuration lines from pcre_internal.h because Nmap builds a static library: ---- pcre-7.2/pcre_internal.h 2007-06-12 08:39:55.000000000 -0500 -+++ libpcre/pcre_internal.h 2007-08-15 18:56:18.000000000 -0500 -@@ -112,15 +112,19 @@ PCRE_EXP_DATA_DEFN only if they are not +--- pcre-7.4/pcre_internal.h 2007-09-13 04:22:27.000000000 -0500 ++++ libpcre/pcre_internal.h 2007-12-19 22:28:33.000000000 -0600 +@@ -108,15 +108,19 @@ PCRE_EXP_DATA_DEFN only if they are not #ifndef PCRE_EXP_DECL # ifdef _WIN32 +/* COMMENTED OUT AS IT'S COMPILED STATICALLY - # ifdef DLL_EXPORT + # ifndef PCRE_STATIC # define PCRE_EXP_DECL extern __declspec(dllexport) # define PCRE_EXP_DEFN __declspec(dllexport) # define PCRE_EXP_DATA_DEFN __declspec(dllexport) @@ -78,74 +79,71 @@ o Comment out some build configuration lines from pcre-internal.h because Nmap +/* # endif +*/ - # # else # ifdef __cplusplus + # define PCRE_EXP_DECL extern "C" ...and pcre.h.in/pcre.h.generic/pcre.h: ---- pcre-7.2/pcre.h.in 2007-06-04 05:18:02.000000000 -0500 -+++ libpcre/pcre.h.in 2007-08-15 19:24:46.000000000 -0500 +--- pcre-7.4/pcre.h.in 2007-09-11 06:24:35.000000000 -0500 ++++ libpcre/pcre.h.in 2007-12-19 22:30:32.000000000 -0600 @@ -51,6 +51,7 @@ imported have to be identified as such. export setting is defined in pcre_internal.h, which includes this file. So we - don't change an existing definition of PCRE_EXP_DECL. */ + don't change existing definitions of PCRE_EXP_DECL and PCRECPP_EXP_DECL. */ +/* - #ifndef PCRE_EXP_DECL - # ifdef _WIN32 - # ifndef PCRE_STATIC -@@ -58,6 +59,7 @@ don't change an existing definition of P + #if defined(_WIN32) && !defined(PCRE_STATIC) + # ifndef PCRE_EXP_DECL + # define PCRE_EXP_DECL extern __declspec(dllimport) +@@ -64,6 +65,7 @@ don't change existing definitions of PCR # endif # endif #endif +*/ /* By default, we use the standard "extern" declarations. */ - + ..and pcreposix.h: ---- pcre-7.2/pcreposix.h 2007-04-04 09:04:40.000000000 -0500 -+++ libpcre/pcreposix.h 2007-08-15 20:31:42.000000000 -0500 -@@ -109,12 +109,14 @@ typedef struct { - imported have to be identified as such. When building PCRE, the appropriate - export settings are needed. */ +--- pcre-7.4/pcreposix.h 2007-08-01 04:06:39.000000000 -0500 ++++ libpcre/pcreposix.h 2007-12-19 22:31:14.000000000 -0600 +@@ -110,10 +110,12 @@ imported have to be identified as such. + export settings are needed, and are set in pcreposix.c before including this + file. */ +/* - #ifdef _WIN32 - # ifndef PCREPOSIX_STATIC - # define PCREPOSIX_EXP_DECL extern __declspec(dllimport) - # define PCREPOSIX_EXP_DEFN __declspec(dllimport) - # endif + #if defined(_WIN32) && !defined(PCRE_STATIC) && !defined(PCREPOSIX_EXP_DECL) + # define PCREPOSIX_EXP_DECL extern __declspec(dllimport) + # define PCREPOSIX_EXP_DEFN __declspec(dllimport) #endif +*/ /* By default, we use the standard "extern" declarations. */ - - -o Added pcre_winconfig.h, and include it in pcre_internal.h instead of config.h: - ---- pcre-7.2/pcre_internal.h 2007-06-12 08:39:55.000000000 -0500 -+++ libpcre/pcre_internal.h 2007-08-15 20:33:48.000000000 -0500 -@@ -69,7 +69,11 @@ be absolutely sure we get our version. * - - /* Get the definitions provided by running "configure" */ - -+#ifdef WIN32 -+#include "pcre_winconfig.h" -+#else - #include "config.h" -+#endif - - /* Standard C headers plus the external interface definition. The only time - setjmp and stdarg are used is when NO_RECURSE is set. */ -o Change the pcre.h #include in pcre_internal.h from to "pcre.h". - This seems to be needed on Windows. +o Added pcre_winconfig.h for Windows. LibPCRE used to include config.h in + pcre_internal.h, and we'd include this winconfig there instead of config.h + if WIN32 is defined. Now, however, they've moved config.h includes to a + bunch of different files, so we have to change them. We could remove the + other includes and move it back to pcre_internal.h, but they must've moved + them for a reason, so we'll follow them. Occurrences of + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + get changed to + +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + o Regenerated everything with 'automake; aclocal; autoconf' diff --git a/libpcre/NON-UNIX-USE b/libpcre/NON-UNIX-USE index a10c7041a..fe6cd0230 100644 --- a/libpcre/NON-UNIX-USE +++ b/libpcre/NON-UNIX-USE @@ -7,14 +7,16 @@ This document contains the following sections: Generic instructions for the PCRE C library The C++ wrapper functions Building for virtual Pascal + Stack size in Windows environments Comments about Win32 builds + Building PCRE with CMake Building under Windows with BCC5.5 Building PCRE on OpenVMS GENERAL -I (Philip Hazel) have no knowledge of Windows or VMS sytems and how their +I (Philip Hazel) have no experience of Windows or VMS sytems and how their libraries work. The items in the PCRE distribution and Makefile that relate to anything other than Unix-like systems are untested by me. @@ -29,88 +31,116 @@ library consists entirely of code written in Standard C, and so should compile successfully on any system that has a Standard C compiler and library. The C++ wrapper functions are a separate issue (see below). -The PCRE distribution contains some experimental support for "cmake", but this -is incomplete and not documented. However if you are a "cmake" user you might -like to try building with "cmake". +The PCRE distribution includes support for CMake. This support is relatively +new, but has already been used successfully to build PCRE in multiple build +environments on Windows. There are some instructions in the section entitled +"Building PCRE with CMake" below. GENERIC INSTRUCTIONS FOR THE PCRE C LIBRARY The following are generic comments about building the PCRE C library "by hand". -(1) Copy or rename the file config.h.generic as config.h, and edit the macro - settings that it contains to whatever is appropriate for your environment. - In particular, if you want to force a specific value for newline, you can - define the NEWLINE macro. + (1) Copy or rename the file config.h.generic as config.h, and edit the macro + settings that it contains to whatever is appropriate for your environment. + In particular, if you want to force a specific value for newline, you can + define the NEWLINE macro. When you compile any of the PCRE modules, you + must specify -DHAVE_CONFIG_H to your compiler so that config.h is included + in the sources. - An alternative approach is not to edit config.h, but to use -D on the - compiler command line to make any changes that you need. + An alternative approach is not to edit config.h, but to use -D on the + compiler command line to make any changes that you need to the + configuration options. In this case -DHAVE_CONFIG_H must not be set. - NOTE: There have been occasions when the way in which certain parameters in - config.h are used has changed between releases. (In the configure/make - world, this is handled automatically.) When upgrading to a new release, you - are strongly advised to review config.h.generic before re-using what you - had previously. + NOTE: There have been occasions when the way in which certain parameters + in config.h are used has changed between releases. (In the configure/make + world, this is handled automatically.) When upgrading to a new release, + you are strongly advised to review config.h.generic before re-using what + you had previously. -(2) Copy or rename the file pcre.h.generic as pcre.h. + (2) Copy or rename the file pcre.h.generic as pcre.h. -(3) EITHER: - Copy or rename file pcre_chartables.c.dist as pcre_chartables.c. + (3) EITHER: + Copy or rename file pcre_chartables.c.dist as pcre_chartables.c. - OR: - Compile dftables.c as a stand-alone program, and then run it with the - single argument "pcre_chartables.c". This generates a set of standard - character tables and writes them to that file. The tables are generated - using the default C locale for your system. If you want to use a locale - that is specified by LC_xxx environment variables, add the -L option to - the dftables command. You must use this method if you are building on - a system that uses EBCDIC code. + OR: + Compile dftables.c as a stand-alone program (using -DHAVE_CONFIG_H if + you have set up config.h), and then run it with the single argument + "pcre_chartables.c". This generates a set of standard character tables + and writes them to that file. The tables are generated using the default + C locale for your system. If you want to use a locale that is specified + by LC_xxx environment variables, add the -L option to the dftables + command. You must use this method if you are building on a system that + uses EBCDIC code. - The tables in pcre_chartables.c are defaults. The caller of PCRE can - specify alternative tables at run time. + The tables in pcre_chartables.c are defaults. The caller of PCRE can + specify alternative tables at run time. -(4) Compile the following source files: + (4) Ensure that you have the following header files: - pcre_chartables.c - pcre_compile.c - pcre_config.c - pcre_dfa_exec.c - pcre_exec.c - pcre_fullinfo.c - pcre_get.c - pcre_globals.c - pcre_info.c - pcre_maketables.c - pcre_newline.c - pcre_ord2utf8.c - pcre_refcount.c - pcre_study.c - pcre_tables.c - pcre_try_flipped.c - pcre_ucp_searchfuncs.c - pcre_valid_utf8.c - pcre_version.c - pcre_xclass.c + pcre_internal.h + ucp.h + ucpinternal.h + ucptable.h - Now link them all together into an object library in whichever form your - system keeps such libraries. This is the basic PCRE C library. If your - system has static and shared libraries, you may have to do this once for - each type. + (5) Also ensure that you have the following file, which is #included as source + when building a debugging version of PCRE and is also used by pcretest. -(5) Similarly, compile pcreposix.c and link it (on its own) as the pcreposix - library. + pcre_printint.src -(6) Compile the test program pcretest.c. This needs the functions in the - pcre and pcreposix libraries when linking. + (6) Compile the following source files, setting -DHAVE_CONFIG_H as a compiler + option if you have set up config.h with your configuration, or else use + other -D settings to change the configuration as required. -(7) Run pcretest on the testinput files in the testdata directory, and check - that the output matches the corresponding testoutput files. Note that the - supplied files are in Unix format, with just LF characters as line - terminators. You may need to edit them to change this if your system uses a - different convention. + pcre_chartables.c + pcre_compile.c + pcre_config.c + pcre_dfa_exec.c + pcre_exec.c + pcre_fullinfo.c + pcre_get.c + pcre_globals.c + pcre_info.c + pcre_maketables.c + pcre_newline.c + pcre_ord2utf8.c + pcre_refcount.c + pcre_study.c + pcre_tables.c + pcre_try_flipped.c + pcre_ucp_searchfuncs.c + pcre_valid_utf8.c + pcre_version.c + pcre_xclass.c -(8) If you want to use the pcregrep command, compile and link pcregrep.c; it - uses only the basic PCRE library (it does not need the pcreposix library). + Make sure that you include -I. in the compiler command (or equivalent for + an unusual compiler) so that all included PCRE header files are first + sought in the current directory. Otherwise you run the risk of picking up + a previously-installed file from somewhere else. + + (7) Now link all the compiled code into an object library in whichever form + your system keeps such libraries. This is the basic PCRE C library. If + your system has static and shared libraries, you may have to do this once + for each type. + + (8) Similarly, compile pcreposix.c (remembering -DHAVE_CONFIG_H if necessary) + and link the result (on its own) as the pcreposix library. + + (9) Compile the test program pcretest.c (again, don't forget -DHAVE_CONFIG_H). + This needs the functions in the pcre and pcreposix libraries when linking. + It also needs the pcre_printint.src source file, which it #includes. + +(10) Run pcretest on the testinput files in the testdata directory, and check + that the output matches the corresponding testoutput files. Note that the + supplied files are in Unix format, with just LF characters as line + terminators. You may need to edit them to change this if your system uses + a different convention. If you are using Windows, you probably should use + the wintestinput3 file instead of testinput3 (and the corresponding output + file). This is a locale test; wintestinput3 sets the locale to "french" + rather than "fr_FR", and there some minor output differences. + +(11) If you want to use the pcregrep command, compile and link pcregrep.c; it + uses only the basic PCRE library (it does not need the pcreposix library). THE C++ WRAPPER FUNCTIONS @@ -131,7 +161,23 @@ additional files. The following files in the distribution are for building PCRE for use with VP/Borland: makevp_c.txt, makevp_l.txt, makevp.bat, pcregexp.pas. -COMMENTS ABOUT WIN32 BUILDS +STACK SIZE IN WINDOWS ENVIRONMENTS + +The default processor stack size of 1Mb in some Windows environments is too +small for matching patterns that need much recursion. In particular, test 2 may +fail because of this. Normally, running out of stack causes a crash, but there +have been cases where the test program has just died silently. See your linker +documentation for how to increase stack size if you experience problems. The +Linux default of 8Mb is a reasonable choice for the stack, though even that can +be too small for some pattern/subject combinations. + +PCRE has a compile configuration option to disable the use of stack for +recursion so that heap is used instead. However, pattern matching is +significantly slower when this is done. There is more about stack usage in the +"pcrestack" documentation. + + +COMMENTS ABOUT WIN32 BUILDS (see also "BUILDING PCRE WITH CMAKE" below) There are two ways of building PCRE using the "configure, make, make install" paradigm on Windows systems: using MinGW or using Cygwin. These are not at all @@ -206,6 +252,60 @@ terminators in order to get some of the tests to work. We hope to improve things in this area in future. +BUILDING PCRE WITH CMAKE + +CMake is an alternative build facility that can be used instead of the +traditional Unix "configure". CMake version 2.4.7 supports Borland makefiles, +MinGW makefiles, MSYS makefiles, NMake makefiles, UNIX makefiles, Visual Studio +6, Visual Studio 7, Visual Studio 8, and Watcom W8. The following instructions +were contributed by a PCRE user. + +1. Download CMake 2.4.7 or above from http://www.cmake.org/, install and ensure + that cmake\bin is on your path. + +2. Unzip (retaining folder structure) the PCRE source tree into a source + directory such as C:\pcre. + +3. Create a new, empty build directory: C:\pcre\build\ + +4. Run CMakeSetup from the Shell envirornment of your build tool, e.g., Msys + for Msys/MinGW or Visual Studio Command Prompt for VC/VC++ + +5. Enter C:\pcre\pcre-xx and C:\pcre\build for the source and build + directories, respectively + +6. Hit the "Configure" button. + +7. Select the particular IDE / build tool that you are using (Visual Studio, + MSYS makefiles, MinGW makefiles, etc.) + +8. The GUI will then list several configuration options. This is where you can + enable UTF-8 support, etc. + +9. Hit "Configure" again. The adjacent "OK" button should now be active. + +10. Hit "OK". + +11. The build directory should now contain a usable build system, be it a + solution file for Visual Studio, makefiles for MinGW, etc. + +Testing with RunTest.bat + +1. Copy RunTest.bat into the directory where pcretest.exe has been created. + +2. Edit RunTest.bat and insert a line that indentifies the relative location of + the pcre source, e.g.: + + set srcdir=..\pcre-7.4-RC3 + +3. Run RunTest.bat from a command shell environment. Test outputs will + automatically be compared to expected results, and discrepancies will + identified in the console output. + +4. To test pcrecpp, run pcrecpp_unittest.exe, pcre_stringpiece_unittest.exe and + pcre_scanner_unittest.exe. + + BUILDING UNDER WINDOWS WITH BCC5.5 Michael Roy sent these comments about building PCRE under Windows with BCC5.5: @@ -284,5 +384,5 @@ $! Locale could not be set to fr $! ========================= -Last Updated: 13 June 2007 +Last Updated: 21 September 2007 **** diff --git a/libpcre/README b/libpcre/README index 2f4d3c577..dabf24375 100644 --- a/libpcre/README +++ b/libpcre/README @@ -103,7 +103,9 @@ Building PCRE on non-Unix systems For a non-Unix system, please read the comments in the file NON-UNIX-USE, though if your system supports the use of "configure" and "make" you may be -able to build PCRE in the same way as for Unix-like systems. +able to build PCRE in the same way as for Unix-like systems. PCRE can also be +configured in many platform environments using the GUI facility of CMake's +CMakeSetup. It creates Makefiles, solution files, etc. PCRE has been compiled on many different operating systems. It should be straightforward to build PCRE on any system that has a Standard C compiler and @@ -184,6 +186,12 @@ library. You can read more about them in the pcrebuild man page. --enable-newline-is-any, many tests should succeed, but there may be some failures. +. By default, the sequence \R in a pattern matches any Unicode line ending + sequence. This is independent of the option specifying what PCRE considers to + be the end of a line (see above). However, the caller of PCRE can restrict \R + to match only CR, LF, or CRLF. You can make this the default by adding + --enable-bsr-anycrlf to the "configure" command (bsr = "backslash R"). + . When called via the POSIX interface, PCRE uses malloc() to get additional storage for processing capturing parentheses if there are more than 10 of them in a pattern. You can increase this threshold by setting, for example, @@ -500,7 +508,10 @@ in the comparison output, it means that locale is not available on your system, despite being listed by "locale". This does not mean that PCRE is broken. [If you are trying to run this test on Windows, you may be able to get it to -work by changing "fr_FR" to "french" everywhere it occurs.] +work by changing "fr_FR" to "french" everywhere it occurs. Alternatively, use +RunTest.bat. The version of RunTest.bat included with PCRE 7.4 and above uses +Windows versions of test 2. More info on using RunTest.bat is included in the +document entitled NON-UNIX-USE.] The fourth test checks the UTF-8 support. It is not run automatically unless PCRE is built with UTF-8 support. To do this you must set --enable-utf8 when @@ -714,4 +725,4 @@ The distribution should contain the following files: Philip Hazel Email local part: ph10 Email domain: cam.ac.uk -Last updated: 24 April 2007 +Last updated: 21 September 2007 diff --git a/libpcre/config.h.generic b/libpcre/config.h.generic index 0656ac219..b6d7ab8f3 100644 --- a/libpcre/config.h.generic +++ b/libpcre/config.h.generic @@ -9,13 +9,24 @@ it to run on SunOS4 and other "close to standard" systems. If you are going to build PCRE "by hand" on a system without "configure" you should copy the distributed config.h.generic to config.h, and then set up the -macros the way you need them. Alternatively, you can avoid editing by using -D -on the compiler command line to set the macro values. +macro definitions the way you need them. You must then add -DHAVE_CONFIG_H to +all of your compile commands, so that config.h is included at the start of +every source. + +Alternatively, you can avoid editing by using -D on the compiler command line +to set the macro values. In this case, you do not have to set -DHAVE_CONFIG_H. PCRE uses memmove() if HAVE_MEMMOVE is set to 1; otherwise it uses bcopy() if HAVE_BCOPY is set to 1. If your system has neither bcopy() nor memmove(), set them both to 0; an emulation function will be used. */ +/* By default, the \R escape sequence matches any Unicode line ending + character or sequence of characters. If BSR_ANYCRLF is defined, this is + changed so that backslash-R matches only CR, LF, or CRLF. The build- time + default can be overridden by the user of PCRE at runtime. On systems that + support it, "configure" can be used to override the default. */ +/* #undef BSR_ANYCRLF */ + /* If you are compiling for a system that uses EBCDIC instead of ASCII character codes, define this macro as 1. On systems that can use "configure", this can be done via --enable-ebcdic. */ @@ -130,6 +141,9 @@ them both to 0; an emulation function will be used. */ /* Define to 1 if you have the header file. */ /* #undef HAVE_WINDOWS_H */ +/* Define to 1 if you have the `_strtoi64' function. */ +/* #undef HAVE__STRTOI64 */ + /* The value of LINK_SIZE determines the number of bytes used to store links as offsets within the compiled regex. The default is 2, which allows for compiled patterns up to 64K long. This covers the vast majority of cases. @@ -164,13 +178,6 @@ them both to 0; an emulation function will be used. */ #define MATCH_LIMIT_RECURSION MATCH_LIMIT #endif -/* This limit is parameterized just in case anybody ever wants to change it. - Care must be taken if it is increased, because it guards against integer - overflow caused by enormously large patterns. */ -#ifndef MAX_DUPLENGTH -#define MAX_DUPLENGTH 30000 -#endif - /* This limit is parameterized just in case anybody ever wants to change it. Care must be taken if it is increased, because it guards against integer overflow caused by enormously large patterns. */ @@ -185,10 +192,10 @@ them both to 0; an emulation function will be used. */ #define MAX_NAME_SIZE 32 #endif -/* The value of NEWLINE determines the newline character sequence. On - Unix-like systems, "configure" can be used to override the default, which - is 10. The possible values are 10 (LF), 13 (CR), 3338 (CRLF), -1 (ANY), or - -2 (ANYCRLF). */ +/* The value of NEWLINE determines the newline character sequence. On systems + that support it, "configure" can be used to override the default, which is + 10. The possible values are 10 (LF), 13 (CR), 3338 (CRLF), -1 (ANY), or -2 + (ANYCRLF). */ #ifndef NEWLINE #define NEWLINE 10 #endif @@ -213,13 +220,13 @@ them both to 0; an emulation function will be used. */ #define PACKAGE_NAME "PCRE" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "PCRE 7.2" +#define PACKAGE_STRING "PCRE 7.4" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "pcre" /* Define to the version of this package. */ -#define PACKAGE_VERSION "7.2" +#define PACKAGE_VERSION "7.4" /* If you are compiling for a system other than a Unix-like system or @@ -261,7 +268,7 @@ them both to 0; an emulation function will be used. */ /* Version number of package */ #ifndef VERSION -#define VERSION "7.2" +#define VERSION "7.4" #endif /* Define to empty if `const' does not conform to ANSI C. */ diff --git a/libpcre/config.h.in b/libpcre/config.h.in index 4145c54c7..72340fd7d 100644 --- a/libpcre/config.h.in +++ b/libpcre/config.h.in @@ -8,13 +8,24 @@ it to run on SunOS4 and other "close to standard" systems. If you are going to build PCRE "by hand" on a system without "configure" you should copy the distributed config.h.generic to config.h, and then set up the -macros the way you need them. Alternatively, you can avoid editing by using -D -on the compiler command line to set the macro values. +macro definitions the way you need them. You must then add -DHAVE_CONFIG_H to +all of your compile commands, so that config.h is included at the start of +every source. + +Alternatively, you can avoid editing by using -D on the compiler command line +to set the macro values. In this case, you do not have to set -DHAVE_CONFIG_H. PCRE uses memmove() if HAVE_MEMMOVE is set to 1; otherwise it uses bcopy() if HAVE_BCOPY is set to 1. If your system has neither bcopy() nor memmove(), set them both to 0; an emulation function will be used. */ +/* By default, the \R escape sequence matches any Unicode line ending + character or sequence of characters. If BSR_ANYCRLF is defined, this is + changed so that backslash-R matches only CR, LF, or CRLF. The build- time + default can be overridden by the user of PCRE at runtime. On systems that + support it, "configure" can be used to override the default. */ +#undef BSR_ANYCRLF + /* If you are compiling for a system that uses EBCDIC instead of ASCII character codes, define this macro as 1. On systems that can use "configure", this can be done via --enable-ebcdic. */ @@ -23,15 +34,9 @@ them both to 0; an emulation function will be used. */ /* Define to 1 if you have the `bcopy' function. */ #undef HAVE_BCOPY -/* Define to 1 if you have the header file. */ -#undef HAVE_BITS_TYPE_TRAITS_H - /* Define to 1 if you have the header file. */ #undef HAVE_DIRENT_H -/* Define to 1 if you have the header file. */ -#undef HAVE_DLFCN_H - /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H @@ -56,9 +61,6 @@ them both to 0; an emulation function will be used. */ /* Define to 1 if you have the `strerror' function. */ #undef HAVE_STRERROR -/* Define to 1 if you have the header file. */ -#undef HAVE_STRING - /* Define to 1 if you have the header file. */ #undef HAVE_STRINGS_H @@ -77,9 +79,6 @@ them both to 0; an emulation function will be used. */ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H -/* Define to 1 if you have the header file. */ -#undef HAVE_TYPE_TRAITS_H - /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H @@ -89,6 +88,9 @@ them both to 0; an emulation function will be used. */ /* Define to 1 if you have the header file. */ #undef HAVE_WINDOWS_H +/* Define to 1 if you have the `_strtoi64' function. */ +#undef HAVE__STRTOI64 + /* The value of LINK_SIZE determines the number of bytes used to store links as offsets within the compiled regex. The default is 2, which allows for compiled patterns up to 64K long. This covers the vast majority of cases. @@ -97,6 +99,9 @@ them both to 0; an emulation function will be used. */ "configure" can be used to override this default. */ #undef LINK_SIZE +/* Mac OS X on Intel */ +#undef MACOSX + /* The value of MATCH_LIMIT determines the default number of times the internal match() function can be called during a single execution of pcre_exec(). There is a runtime interface for setting a different limit. @@ -117,11 +122,6 @@ them both to 0; an emulation function will be used. */ "configure" can be used to override the default. */ #undef MATCH_LIMIT_RECURSION -/* This limit is parameterized just in case anybody ever wants to change it. - Care must be taken if it is increased, because it guards against integer - overflow caused by enormously large patterns. */ -#undef MAX_DUPLENGTH - /* This limit is parameterized just in case anybody ever wants to change it. Care must be taken if it is increased, because it guards against integer overflow caused by enormously large patterns. */ @@ -132,10 +132,10 @@ them both to 0; an emulation function will be used. */ overflow caused by enormously large patterns. */ #undef MAX_NAME_SIZE -/* The value of NEWLINE determines the newline character sequence. On - Unix-like systems, "configure" can be used to override the default, which - is 10. The possible values are 10 (LF), 13 (CR), 3338 (CRLF), -1 (ANY), or - -2 (ANYCRLF). */ +/* The value of NEWLINE determines the newline character sequence. On systems + that support it, "configure" can be used to override the default, which is + 10. The possible values are 10 (LF), 13 (CR), 3338 (CRLF), -1 (ANY), or -2 + (ANYCRLF). */ #undef NEWLINE /* PCRE uses recursive function calls to handle backtracking while matching. diff --git a/libpcre/configure b/libpcre/configure index 5e1dd9c4a..3b3c064b1 100755 --- a/libpcre/configure +++ b/libpcre/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.61 for PCRE 7.2. +# Generated by GNU Autoconf 2.61 for PCRE 7.4. # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. @@ -572,8 +572,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='PCRE' PACKAGE_TARNAME='pcre' -PACKAGE_VERSION='7.2' -PACKAGE_STRING='PCRE 7.2' +PACKAGE_VERSION='7.4' +PACKAGE_STRING='PCRE 7.4' PACKAGE_BUGREPORT='' ac_unique_file="pcre.h.in" @@ -1226,7 +1226,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures PCRE 7.2 to adapt to many kinds of systems. +\`configure' configures PCRE 7.4 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1296,7 +1296,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of PCRE 7.2:";; + short | recursive ) echo "Configuration of PCRE 7.4:";; esac cat <<\_ACEOF @@ -1318,8 +1318,10 @@ Optional Features: --enable-newline-is-anycrlf use CR, LF, or CRLF as newline sequence --enable-newline-is-any use any valid Unicode newline sequence - --enable-ebcdic assume EBCDIC coding rather than ASCII (implies - --enable-rebuild-chartables) + --enable-bsr-anycrlf \R matches only CR, LF, CRLF by default + --enable-ebcdic assume EBCDIC coding rather than ASCII; use this + only in (uncommon) EBCDIC environments; it implies + --enable-rebuild-chartables --disable-stack-for-recursion don't use stack recursion when matching @@ -1407,7 +1409,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -PCRE configure 7.2 +PCRE configure 7.4 generated by GNU Autoconf 2.61 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -1421,7 +1423,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by PCRE $as_me 7.2, which was +It was created by PCRE $as_me 7.4, which was generated by GNU Autoconf 2.61. Invocation command line was $ $0 $@ @@ -2112,7 +2114,7 @@ fi # Define the identity of the package. PACKAGE='pcre' - VERSION='7.2' + VERSION='7.4' cat >>confdefs.h <<_ACEOF @@ -3563,9 +3565,9 @@ fi PCRE_MAJOR="7" -PCRE_MINOR="2" +PCRE_MINOR="4" PCRE_PRERELEASE="" -PCRE_DATE="2007-06-19" +PCRE_DATE="2007-09-21" @@ -3636,6 +3638,15 @@ fi enable_newline="$ac_pcre_newline" +# Handle --enable-bsr-anycrlf +# Check whether --enable-bsr-anycrlf was given. +if test "${enable_bsr_anycrlf+set}" = set; then + enableval=$enable_bsr_anycrlf; +else + enable_bsr_anycrlf=no +fi + + # Handle --enable-ebcdic # Check whether --enable-ebcdic was given. if test "${enable_ebcdic+set}" = set; then @@ -4861,7 +4872,8 @@ fi -for ac_func in bcopy memmove strerror strtoq strtoll + +for ac_func in bcopy memmove strerror strtoq strtoll _strtoi64 do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` { echo "$as_me:$LINENO: checking for $ac_func" >&5 @@ -4996,6 +5008,14 @@ cat >>confdefs.h <<_ACEOF _ACEOF +if test "$enable_bsr_anycrlf" = "yes"; then + +cat >>confdefs.h <<\_ACEOF +#define BSR_ANYCRLF +_ACEOF + +fi + cat >>confdefs.h <<_ACEOF #define LINK_SIZE $with_link_size @@ -5033,12 +5053,6 @@ _ACEOF -cat >>confdefs.h <<\_ACEOF -#define MAX_DUPLENGTH 30000 -_ACEOF - - - if test "$enable_ebcdic" = "yes"; then @@ -5141,7 +5155,7 @@ cat >>confdefs.h <<\_ACEOF #define MACOSX _ACEOF - CFLAGS="$CFLAGS -fno-thread-jumps" + CFLAGS="$CFLAGS -fno-jump-threads" ;; esac @@ -5584,7 +5598,7 @@ exec 6>&1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by PCRE $as_me 7.2, which was +This file was extended by PCRE $as_me 7.4, which was generated by GNU Autoconf 2.61. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -5637,7 +5651,7 @@ Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -PCRE config.status 7.2 +PCRE config.status 7.4 configured by $0, generated by GNU Autoconf 2.61, with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/libpcre/configure.ac b/libpcre/configure.ac index 22b529848..f98559bd9 100644 --- a/libpcre/configure.ac +++ b/libpcre/configure.ac @@ -7,9 +7,9 @@ dnl be defined as -RC2, for example. For real releases, it should be defined dnl empty. m4_define(pcre_major, [7]) -m4_define(pcre_minor, [2]) +m4_define(pcre_minor, [4]) m4_define(pcre_prerelease, []) -m4_define(pcre_date, [2007-06-19]) +m4_define(pcre_date, [2007-09-21]) AC_PREREQ(2.57) AC_INIT(PCRE, pcre_major.pcre_minor[]pcre_prerelease, , pcre) @@ -110,10 +110,16 @@ AC_ARG_ENABLE(newline-is-any, ac_pcre_newline=any) enable_newline="$ac_pcre_newline" +# Handle --enable-bsr-anycrlf +AC_ARG_ENABLE(bsr-anycrlf, + AS_HELP_STRING([--enable-bsr-anycrlf], + [\R matches only CR, LF, CRLF by default]), + , enable_bsr_anycrlf=no) + # Handle --enable-ebcdic AC_ARG_ENABLE(ebcdic, AS_HELP_STRING([--enable-ebcdic], - [assume EBCDIC coding rather than ASCII (implies --enable-rebuild-chartables)]), + [assume EBCDIC coding rather than ASCII; use this only in (uncommon) EBCDIC environments; it implies --enable-rebuild-chartables]), , enable_ebcdic=no) # Handle --disable-stack-for-recursion @@ -205,8 +211,12 @@ it to run on SunOS4 and other "close to standard" systems. If you are going to build PCRE "by hand" on a system without "configure" you should copy the distributed config.h.generic to config.h, and then set up the -macros the way you need them. Alternatively, you can avoid editing by using -D -on the compiler command line to set the macro values. +macro definitions the way you need them. You must then add -DHAVE_CONFIG_H to +all of your compile commands, so that config.h is included at the start of +every source. + +Alternatively, you can avoid editing by using -D on the compiler command line +to set the macro values. In this case, you do not have to set -DHAVE_CONFIG_H. PCRE uses memmove() if HAVE_MEMMOVE is set to 1; otherwise it uses bcopy() if HAVE_BCOPY is set to 1. If your system has neither bcopy() nor memmove(), set @@ -239,7 +249,7 @@ AC_SUBST(pcre_have_ulong_long) # Checks for library functions. -AC_CHECK_FUNCS(bcopy memmove strerror strtoq strtoll) +AC_CHECK_FUNCS(bcopy memmove strerror strtoq strtoll _strtoi64) # This facilitates -ansi builds under Linux dnl AC_DEFINE([_GNU_SOURCE], [], [Enable GNU extensions in glibc]) @@ -275,9 +285,19 @@ fi AC_DEFINE_UNQUOTED([NEWLINE], [$ac_pcre_newline_value], [ The value of NEWLINE determines the newline character sequence. On - Unix-like systems, "configure" can be used to override the default, - which is 10. The possible values are 10 (LF), 13 (CR), 3338 (CRLF), - -1 (ANY), or -2 (ANYCRLF).]) + systems that support it, "configure" can be used to override the + default, which is 10. The possible values are 10 (LF), 13 (CR), + 3338 (CRLF), -1 (ANY), or -2 (ANYCRLF).]) + +if test "$enable_bsr_anycrlf" = "yes"; then + AC_DEFINE([BSR_ANYCRLF], [], [ + By default, the \R escape sequence matches any Unicode line ending + character or sequence of characters. If BSR_ANYCRLF is defined, this is + changed so that backslash-R matches only CR, LF, or CRLF. The build- + time default can be overridden by the user of PCRE at runtime. On + systems that support it, "configure" can be used to override the + default.]) +fi AC_DEFINE_UNQUOTED([LINK_SIZE], [$with_link_size], [ The value of LINK_SIZE determines the number of bytes used to store @@ -330,11 +350,6 @@ AC_DEFINE([MAX_NAME_COUNT], [10000], [ change it. Care must be taken if it is increased, because it guards against integer overflow caused by enormously large patterns.]) -AC_DEFINE([MAX_DUPLENGTH], [30000], [ - This limit is parameterized just in case anybody ever wants to - change it. Care must be taken if it is increased, because it guards - against integer overflow caused by enormously large patterns.]) - AH_VERBATIM([PCRE_EXP_DEFN], [ /* If you are compiling for a system other than a Unix-like system or Win32, and it needs some magic to be inserted before the definition @@ -354,14 +369,14 @@ if test "$enable_ebcdic" = "yes"; then "configure", this can be done via --enable-ebcdic.]) fi -dnl Mac OS X on Intel hack to remove thread jumps +dnl Mac OS X on Intel hack to remove jump threads AC_CANONICAL_HOST case "$host" in i386-apple-darwin*) macosx=yes AC_DEFINE(MACOSX, [], [Mac OS X on Intel]) - CFLAGS="$CFLAGS -fno-thread-jumps" + CFLAGS="$CFLAGS -fno-jump-threads" ;; esac diff --git a/libpcre/dftables.c b/libpcre/dftables.c index baa56a15c..20baddacf 100644 --- a/libpcre/dftables.c +++ b/libpcre/dftables.c @@ -43,6 +43,12 @@ character tables for PCRE. The tables are built according to the current locale. Now that pcre_maketables is a function visible to the outside world, we make use of its code from here in order to be consistent. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include #include #include @@ -99,12 +105,17 @@ fprintf(f, "tables are passed to PCRE by the application that calls it. The tables\n" "are used only for characters whose code values are less than 256.\n\n"); fprintf(f, - "The following #include is present because without it gcc 4.x may remove\n" + "The following #includes are present because without them gcc 4.x may remove\n" "the array definition from the final binary if PCRE is built into a static\n" "library and dead code stripping is activated. This leads to link errors.\n" "Pulling in the header ensures that the array gets flagged as \"someone\n" "outside this compilation unit might reference this\" and so it will always\n" "be supplied to the linker. */\n\n" + "#ifdef WIN32\n" + "#include \"pcre_winconfig.h\"\n" + "#else\n" + "#include \"config.h\"\n" + "#endif\n\n" "#include \"pcre_internal.h\"\n\n"); fprintf(f, "const unsigned char _pcre_default_tables[] = {\n\n" diff --git a/libpcre/pcre.h b/libpcre/pcre.h index acbf28c52..533f9198a 100644 --- a/libpcre/pcre.h +++ b/libpcre/pcre.h @@ -42,20 +42,26 @@ POSSIBILITY OF SUCH DAMAGE. /* The current PCRE version information. */ #define PCRE_MAJOR 7 -#define PCRE_MINOR 2 +#define PCRE_MINOR 4 #define PCRE_PRERELEASE -#define PCRE_DATE 2007-06-19 +#define PCRE_DATE 2007-09-21 /* When an application links to a PCRE DLL in Windows, the symbols that are imported have to be identified as such. When building PCRE, the appropriate export setting is defined in pcre_internal.h, which includes this file. So we -don't change an existing definition of PCRE_EXP_DECL. */ +don't change existing definitions of PCRE_EXP_DECL and PCRECPP_EXP_DECL. */ /* -#ifndef PCRE_EXP_DECL -# ifdef _WIN32 -# ifndef PCRE_STATIC -# define PCRE_EXP_DECL extern __declspec(dllimport) +#if defined(_WIN32) && !defined(PCRE_STATIC) +# ifndef PCRE_EXP_DECL +# define PCRE_EXP_DECL extern __declspec(dllimport) +# endif +# ifdef __cplusplus +# ifndef PCRECPP_EXP_DECL +# define PCRECPP_EXP_DECL extern __declspec(dllimport) +# endif +# ifndef PCRECPP_EXP_DEFN +# define PCRECPP_EXP_DEFN __declspec(dllimport) # endif # endif #endif @@ -65,9 +71,18 @@ don't change an existing definition of PCRE_EXP_DECL. */ #ifndef PCRE_EXP_DECL # ifdef __cplusplus -# define PCRE_EXP_DECL extern "C" +# define PCRE_EXP_DECL extern "C" # else -# define PCRE_EXP_DECL extern +# define PCRE_EXP_DECL extern +# endif +#endif + +#ifdef __cplusplus +# ifndef PCRECPP_EXP_DECL +# define PCRECPP_EXP_DECL extern +# endif +# ifndef PCRECPP_EXP_DEFN +# define PCRECPP_EXP_DEFN # endif #endif @@ -109,6 +124,8 @@ extern "C" { #define PCRE_NEWLINE_CRLF 0x00300000 #define PCRE_NEWLINE_ANY 0x00400000 #define PCRE_NEWLINE_ANYCRLF 0x00500000 +#define PCRE_BSR_ANYCRLF 0x00800000 +#define PCRE_BSR_UNICODE 0x01000000 /* Exec-time and get/set-time error codes */ @@ -134,7 +151,7 @@ extern "C" { #define PCRE_ERROR_DFA_WSSIZE (-19) #define PCRE_ERROR_DFA_RECURSE (-20) #define PCRE_ERROR_RECURSIONLIMIT (-21) -#define PCRE_ERROR_NULLWSLIMIT (-22) +#define PCRE_ERROR_NULLWSLIMIT (-22) /* No longer actually used */ #define PCRE_ERROR_BADNEWLINE (-23) /* Request types for pcre_fullinfo() */ @@ -154,6 +171,7 @@ extern "C" { #define PCRE_INFO_DEFAULT_TABLES 11 #define PCRE_INFO_OKPARTIAL 12 #define PCRE_INFO_JCHANGED 13 +#define PCRE_INFO_HASCRORLF 14 /* Request types for pcre_config(). Do not re-arrange, in order to remain compatible. */ @@ -166,6 +184,7 @@ compatible. */ #define PCRE_CONFIG_STACKRECURSE 5 #define PCRE_CONFIG_UNICODE_PROPERTIES 6 #define PCRE_CONFIG_MATCH_LIMIT_RECURSION 7 +#define PCRE_CONFIG_BSR 8 /* Bit flags for the pcre_extra structure. Do not re-arrange or redefine these bits, just add new ones on the end, in order to remain compatible. */ diff --git a/libpcre/pcre.h.generic b/libpcre/pcre.h.generic index acbf28c52..533f9198a 100644 --- a/libpcre/pcre.h.generic +++ b/libpcre/pcre.h.generic @@ -42,20 +42,26 @@ POSSIBILITY OF SUCH DAMAGE. /* The current PCRE version information. */ #define PCRE_MAJOR 7 -#define PCRE_MINOR 2 +#define PCRE_MINOR 4 #define PCRE_PRERELEASE -#define PCRE_DATE 2007-06-19 +#define PCRE_DATE 2007-09-21 /* When an application links to a PCRE DLL in Windows, the symbols that are imported have to be identified as such. When building PCRE, the appropriate export setting is defined in pcre_internal.h, which includes this file. So we -don't change an existing definition of PCRE_EXP_DECL. */ +don't change existing definitions of PCRE_EXP_DECL and PCRECPP_EXP_DECL. */ /* -#ifndef PCRE_EXP_DECL -# ifdef _WIN32 -# ifndef PCRE_STATIC -# define PCRE_EXP_DECL extern __declspec(dllimport) +#if defined(_WIN32) && !defined(PCRE_STATIC) +# ifndef PCRE_EXP_DECL +# define PCRE_EXP_DECL extern __declspec(dllimport) +# endif +# ifdef __cplusplus +# ifndef PCRECPP_EXP_DECL +# define PCRECPP_EXP_DECL extern __declspec(dllimport) +# endif +# ifndef PCRECPP_EXP_DEFN +# define PCRECPP_EXP_DEFN __declspec(dllimport) # endif # endif #endif @@ -65,9 +71,18 @@ don't change an existing definition of PCRE_EXP_DECL. */ #ifndef PCRE_EXP_DECL # ifdef __cplusplus -# define PCRE_EXP_DECL extern "C" +# define PCRE_EXP_DECL extern "C" # else -# define PCRE_EXP_DECL extern +# define PCRE_EXP_DECL extern +# endif +#endif + +#ifdef __cplusplus +# ifndef PCRECPP_EXP_DECL +# define PCRECPP_EXP_DECL extern +# endif +# ifndef PCRECPP_EXP_DEFN +# define PCRECPP_EXP_DEFN # endif #endif @@ -109,6 +124,8 @@ extern "C" { #define PCRE_NEWLINE_CRLF 0x00300000 #define PCRE_NEWLINE_ANY 0x00400000 #define PCRE_NEWLINE_ANYCRLF 0x00500000 +#define PCRE_BSR_ANYCRLF 0x00800000 +#define PCRE_BSR_UNICODE 0x01000000 /* Exec-time and get/set-time error codes */ @@ -134,7 +151,7 @@ extern "C" { #define PCRE_ERROR_DFA_WSSIZE (-19) #define PCRE_ERROR_DFA_RECURSE (-20) #define PCRE_ERROR_RECURSIONLIMIT (-21) -#define PCRE_ERROR_NULLWSLIMIT (-22) +#define PCRE_ERROR_NULLWSLIMIT (-22) /* No longer actually used */ #define PCRE_ERROR_BADNEWLINE (-23) /* Request types for pcre_fullinfo() */ @@ -154,6 +171,7 @@ extern "C" { #define PCRE_INFO_DEFAULT_TABLES 11 #define PCRE_INFO_OKPARTIAL 12 #define PCRE_INFO_JCHANGED 13 +#define PCRE_INFO_HASCRORLF 14 /* Request types for pcre_config(). Do not re-arrange, in order to remain compatible. */ @@ -166,6 +184,7 @@ compatible. */ #define PCRE_CONFIG_STACKRECURSE 5 #define PCRE_CONFIG_UNICODE_PROPERTIES 6 #define PCRE_CONFIG_MATCH_LIMIT_RECURSION 7 +#define PCRE_CONFIG_BSR 8 /* Bit flags for the pcre_extra structure. Do not re-arrange or redefine these bits, just add new ones on the end, in order to remain compatible. */ diff --git a/libpcre/pcre.h.in b/libpcre/pcre.h.in index 6b157900b..66ff21e5a 100644 --- a/libpcre/pcre.h.in +++ b/libpcre/pcre.h.in @@ -49,13 +49,19 @@ POSSIBILITY OF SUCH DAMAGE. /* When an application links to a PCRE DLL in Windows, the symbols that are imported have to be identified as such. When building PCRE, the appropriate export setting is defined in pcre_internal.h, which includes this file. So we -don't change an existing definition of PCRE_EXP_DECL. */ +don't change existing definitions of PCRE_EXP_DECL and PCRECPP_EXP_DECL. */ /* -#ifndef PCRE_EXP_DECL -# ifdef _WIN32 -# ifndef PCRE_STATIC -# define PCRE_EXP_DECL extern __declspec(dllimport) +#if defined(_WIN32) && !defined(PCRE_STATIC) +# ifndef PCRE_EXP_DECL +# define PCRE_EXP_DECL extern __declspec(dllimport) +# endif +# ifdef __cplusplus +# ifndef PCRECPP_EXP_DECL +# define PCRECPP_EXP_DECL extern __declspec(dllimport) +# endif +# ifndef PCRECPP_EXP_DEFN +# define PCRECPP_EXP_DEFN __declspec(dllimport) # endif # endif #endif @@ -65,9 +71,18 @@ don't change an existing definition of PCRE_EXP_DECL. */ #ifndef PCRE_EXP_DECL # ifdef __cplusplus -# define PCRE_EXP_DECL extern "C" +# define PCRE_EXP_DECL extern "C" # else -# define PCRE_EXP_DECL extern +# define PCRE_EXP_DECL extern +# endif +#endif + +#ifdef __cplusplus +# ifndef PCRECPP_EXP_DECL +# define PCRECPP_EXP_DECL extern +# endif +# ifndef PCRECPP_EXP_DEFN +# define PCRECPP_EXP_DEFN # endif #endif @@ -109,6 +124,8 @@ extern "C" { #define PCRE_NEWLINE_CRLF 0x00300000 #define PCRE_NEWLINE_ANY 0x00400000 #define PCRE_NEWLINE_ANYCRLF 0x00500000 +#define PCRE_BSR_ANYCRLF 0x00800000 +#define PCRE_BSR_UNICODE 0x01000000 /* Exec-time and get/set-time error codes */ @@ -134,7 +151,7 @@ extern "C" { #define PCRE_ERROR_DFA_WSSIZE (-19) #define PCRE_ERROR_DFA_RECURSE (-20) #define PCRE_ERROR_RECURSIONLIMIT (-21) -#define PCRE_ERROR_NULLWSLIMIT (-22) +#define PCRE_ERROR_NULLWSLIMIT (-22) /* No longer actually used */ #define PCRE_ERROR_BADNEWLINE (-23) /* Request types for pcre_fullinfo() */ @@ -154,6 +171,7 @@ extern "C" { #define PCRE_INFO_DEFAULT_TABLES 11 #define PCRE_INFO_OKPARTIAL 12 #define PCRE_INFO_JCHANGED 13 +#define PCRE_INFO_HASCRORLF 14 /* Request types for pcre_config(). Do not re-arrange, in order to remain compatible. */ @@ -166,6 +184,7 @@ compatible. */ #define PCRE_CONFIG_STACKRECURSE 5 #define PCRE_CONFIG_UNICODE_PROPERTIES 6 #define PCRE_CONFIG_MATCH_LIMIT_RECURSION 7 +#define PCRE_CONFIG_BSR 8 /* Bit flags for the pcre_extra structure. Do not re-arrange or redefine these bits, just add new ones on the end, in order to remain compatible. */ diff --git a/libpcre/pcre_chartables.c b/libpcre/pcre_chartables.c index 6494d8e98..f57bf3b26 100644 --- a/libpcre/pcre_chartables.c +++ b/libpcre/pcre_chartables.c @@ -14,12 +14,18 @@ example ISO-8859-1. When dftables is run, it creates these tables in the current locale. If PCRE is configured with --enable-rebuild-chartables, this happens automatically. -The following #include is present because without it gcc 4.x may remove the +The following #includes are present because without the gcc 4.x may remove the array definition from the final binary if PCRE is built into a static library and dead code stripping is activated. This leads to link errors. Pulling in the header ensures that the array gets flagged as "someone outside this compilation unit might reference this" and so it will always be supplied to the linker. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" const unsigned char _pcre_default_tables[] = { diff --git a/libpcre/pcre_chartables.c.dist b/libpcre/pcre_chartables.c.dist index 6494d8e98..f57bf3b26 100644 --- a/libpcre/pcre_chartables.c.dist +++ b/libpcre/pcre_chartables.c.dist @@ -14,12 +14,18 @@ example ISO-8859-1. When dftables is run, it creates these tables in the current locale. If PCRE is configured with --enable-rebuild-chartables, this happens automatically. -The following #include is present because without it gcc 4.x may remove the +The following #includes are present because without the gcc 4.x may remove the array definition from the final binary if PCRE is built into a static library and dead code stripping is activated. This leads to link errors. Pulling in the header ensures that the array gets flagged as "someone outside this compilation unit might reference this" and so it will always be supplied to the linker. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" const unsigned char _pcre_default_tables[] = { diff --git a/libpcre/pcre_compile.c b/libpcre/pcre_compile.c index c191539c8..b504cdce0 100644 --- a/libpcre/pcre_compile.c +++ b/libpcre/pcre_compile.c @@ -42,11 +42,16 @@ POSSIBILITY OF SUCH DAMAGE. supporting internal functions that are not used by other modules. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #define NLBLOCK cd /* Block containing newline information */ #define PSSTART start_pattern /* Field containing processed string start */ #define PSEND end_pattern /* Field containing processed string end */ - #include "pcre_internal.h" @@ -62,6 +67,13 @@ used by pcretest. DEBUG is not defined when building a production library. */ #define SETBIT(a,b) a[b/8] |= (1 << (b%8)) +/* Maximum length value to check against when making sure that the integer that +holds the compiled pattern length does not overflow. We make it a bit less than +INT_MAX to allow for adding in group terminating bytes, so that we don't have +to check them every time. */ + +#define OFLOW_MAX (INT_MAX - 20) + /************************************************* * Code parameters and static tables * @@ -120,7 +132,7 @@ static const short int escapes[] = { /* B8 */ 0, 0, 0, 0, 0, ']', '=', '-', /* C0 */ '{',-ESC_A, -ESC_B, -ESC_C, -ESC_D,-ESC_E, 0, -ESC_G, /* C8 */-ESC_H, 0, 0, 0, 0, 0, 0, 0, -/* D0 */ '}', 0, 0, 0, 0, 0, 0, -ESC_P, +/* D0 */ '}', 0, -ESC_K, 0, 0, 0, 0, -ESC_P, /* D8 */-ESC_Q,-ESC_R, 0, 0, 0, 0, 0, 0, /* E0 */ '\\', 0, -ESC_S, 0, 0,-ESC_V, -ESC_W, -ESC_X, /* E8 */ 0,-ESC_Z, 0, 0, 0, 0, 0, 0, @@ -130,14 +142,47 @@ static const short int escapes[] = { #endif -/* Tables of names of POSIX character classes and their lengths. The list is -terminated by a zero length entry. The first three must be alpha, lower, upper, -as this is assumed for handling case independence. */ +/* Table of special "verbs" like (*PRUNE). This is a short table, so it is +searched linearly. Put all the names into a single string, in order to reduce +the number of relocations when a shared library is dynamically linked. */ -static const char *const posix_names[] = { - "alpha", "lower", "upper", - "alnum", "ascii", "blank", "cntrl", "digit", "graph", - "print", "punct", "space", "word", "xdigit" }; +typedef struct verbitem { + int len; + int op; +} verbitem; + +static const char verbnames[] = + "ACCEPT\0" + "COMMIT\0" + "F\0" + "FAIL\0" + "PRUNE\0" + "SKIP\0" + "THEN"; + +static verbitem verbs[] = { + { 6, OP_ACCEPT }, + { 6, OP_COMMIT }, + { 1, OP_FAIL }, + { 4, OP_FAIL }, + { 5, OP_PRUNE }, + { 4, OP_SKIP }, + { 4, OP_THEN } +}; + +static int verbcount = sizeof(verbs)/sizeof(verbitem); + + +/* Tables of names of POSIX character classes and their lengths. The names are +now all in a single string, to reduce the number of relocations when a shared +library is dynamically loaded. The list of lengths is terminated by a zero +length entry. The first three must be alpha, lower, upper, as this is assumed +for handling case independence. */ + +static const char posix_names[] = + "alpha\0" "lower\0" "upper\0" "alnum\0" "ascii\0" "blank\0" + "cntrl\0" "digit\0" "graph\0" "print\0" "punct\0" "space\0" + "word\0" "xdigit"; static const uschar posix_name_lengths[] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 6, 0 }; @@ -176,80 +221,88 @@ static const int posix_class_maps[] = { /* The texts of compile-time error messages. These are "char *" because they are passed to the outside world. Do not ever re-use any error number, because they are documented. Always add a new error instead. Messages marked DEAD below -are no longer used. */ +are no longer used. This used to be a table of strings, but in order to reduce +the number of relocations needed when a shared library is loaded dynamically, +it is now one long string. We cannot use a table of offsets, because the +lengths of inserts such as XSTRING(MAX_NAME_SIZE) are not known. Instead, we +simply count through to the one we want - this isn't a performance issue +because these strings are used only when there is a compilation error. */ -static const char *error_texts[] = { - "no error", - "\\ at end of pattern", - "\\c at end of pattern", - "unrecognized character follows \\", - "numbers out of order in {} quantifier", +static const char error_texts[] = + "no error\0" + "\\ at end of pattern\0" + "\\c at end of pattern\0" + "unrecognized character follows \\\0" + "numbers out of order in {} quantifier\0" /* 5 */ - "number too big in {} quantifier", - "missing terminating ] for character class", - "invalid escape sequence in character class", - "range out of order in character class", - "nothing to repeat", + "number too big in {} quantifier\0" + "missing terminating ] for character class\0" + "invalid escape sequence in character class\0" + "range out of order in character class\0" + "nothing to repeat\0" /* 10 */ - "operand of unlimited repeat could match the empty string", /** DEAD **/ - "internal error: unexpected repeat", - "unrecognized character after (?", - "POSIX named classes are supported only within a class", - "missing )", + "operand of unlimited repeat could match the empty string\0" /** DEAD **/ + "internal error: unexpected repeat\0" + "unrecognized character after (?\0" + "POSIX named classes are supported only within a class\0" + "missing )\0" /* 15 */ - "reference to non-existent subpattern", - "erroffset passed as NULL", - "unknown option bit(s) set", - "missing ) after comment", - "parentheses nested too deeply", /** DEAD **/ + "reference to non-existent subpattern\0" + "erroffset passed as NULL\0" + "unknown option bit(s) set\0" + "missing ) after comment\0" + "parentheses nested too deeply\0" /** DEAD **/ /* 20 */ - "regular expression too large", - "failed to get memory", - "unmatched parentheses", - "internal error: code overflow", - "unrecognized character after (?<", + "regular expression is too large\0" + "failed to get memory\0" + "unmatched parentheses\0" + "internal error: code overflow\0" + "unrecognized character after (?<\0" /* 25 */ - "lookbehind assertion is not fixed length", - "malformed number or name after (?(", - "conditional group contains more than two branches", - "assertion expected after (?(", - "(?R or (?[+-]digits must be followed by )", + "lookbehind assertion is not fixed length\0" + "malformed number or name after (?(\0" + "conditional group contains more than two branches\0" + "assertion expected after (?(\0" + "(?R or (?[+-]digits must be followed by )\0" /* 30 */ - "unknown POSIX class name", - "POSIX collating elements are not supported", - "this version of PCRE is not compiled with PCRE_UTF8 support", - "spare error", /** DEAD **/ - "character value in \\x{...} sequence is too large", + "unknown POSIX class name\0" + "POSIX collating elements are not supported\0" + "this version of PCRE is not compiled with PCRE_UTF8 support\0" + "spare error\0" /** DEAD **/ + "character value in \\x{...} sequence is too large\0" /* 35 */ - "invalid condition (?(0)", - "\\C not allowed in lookbehind assertion", - "PCRE does not support \\L, \\l, \\N, \\U, or \\u", - "number after (?C is > 255", - "closing ) for (?C expected", + "invalid condition (?(0)\0" + "\\C not allowed in lookbehind assertion\0" + "PCRE does not support \\L, \\l, \\N, \\U, or \\u\0" + "number after (?C is > 255\0" + "closing ) for (?C expected\0" /* 40 */ - "recursive call could loop indefinitely", - "unrecognized character after (?P", - "syntax error in subpattern name (missing terminator)", - "two named subpatterns have the same name", - "invalid UTF-8 string", + "recursive call could loop indefinitely\0" + "unrecognized character after (?P\0" + "syntax error in subpattern name (missing terminator)\0" + "two named subpatterns have the same name\0" + "invalid UTF-8 string\0" /* 45 */ - "support for \\P, \\p, and \\X has not been compiled", - "malformed \\P or \\p sequence", - "unknown property name after \\P or \\p", - "subpattern name is too long (maximum " XSTRING(MAX_NAME_SIZE) " characters)", - "too many named subpatterns (maximum " XSTRING(MAX_NAME_COUNT) ")", + "support for \\P, \\p, and \\X has not been compiled\0" + "malformed \\P or \\p sequence\0" + "unknown property name after \\P or \\p\0" + "subpattern name is too long (maximum " XSTRING(MAX_NAME_SIZE) " characters)\0" + "too many named subpatterns (maximum " XSTRING(MAX_NAME_COUNT) ")\0" /* 50 */ - "repeated subpattern is too long", - "octal value is greater than \\377 (not in UTF-8 mode)", - "internal error: overran compiling workspace", - "internal error: previously-checked referenced subpattern not found", - "DEFINE group contains more than one branch", + "repeated subpattern is too long\0" /** DEAD **/ + "octal value is greater than \\377 (not in UTF-8 mode)\0" + "internal error: overran compiling workspace\0" + "internal error: previously-checked referenced subpattern not found\0" + "DEFINE group contains more than one branch\0" /* 55 */ - "repeating a DEFINE group is not allowed", - "inconsistent NEWLINE options", - "\\g is not followed by a braced name or an optionally braced non-zero number", - "(?+ or (?- or (?(+ or (?(- must be followed by a non-zero number" -}; + "repeating a DEFINE group is not allowed\0" + "inconsistent NEWLINE options\0" + "\\g is not followed by a braced name or an optionally braced non-zero number\0" + "(?+ or (?- or (?(+ or (?(- must be followed by a non-zero number\0" + "(*VERB) with an argument is not supported\0" + /* 60 */ + "(*VERB) not recognized\0" + "number is too big"; /* Table to identify digits and hex digits. This is used when compiling @@ -384,6 +437,28 @@ static BOOL +/************************************************* +* Find an error text * +*************************************************/ + +/* The error texts are now all in one long string, to save on relocations. As +some of the text is of unknown length, we can't use a table of offsets. +Instead, just count through the strings. This is not a performance issue +because it happens only when there has been a compilation error. + +Argument: the error number +Returns: pointer to the error string +*/ + +static const char * +find_error_text(int n) +{ +const char *s = error_texts; +for (; n > 0; n--) while (*s++ != 0); +return s; +} + + /************************************************* * Handle escapes * *************************************************/ @@ -405,7 +480,7 @@ Arguments: Returns: zero or positive => a data character negative => a special escape sequence - on error, errorptr is set + on error, errorcodeptr is set */ static int @@ -490,10 +565,16 @@ else while ((digitab[ptr[1]] & ctype_digit) != 0) c = c * 10 + *(++ptr) - '0'; + if (c < 0) + { + *errorcodeptr = ERR61; + break; + } + if (c == 0 || (braced && *(++ptr) != '}')) { *errorcodeptr = ERR57; - return 0; + break; } if (negated) @@ -501,7 +582,7 @@ else if (c > bracount) { *errorcodeptr = ERR15; - return 0; + break; } c = bracount - (c - 1); } @@ -530,6 +611,11 @@ else c -= '0'; while ((digitab[ptr[1]] & ctype_digit) != 0) c = c * 10 + *(++ptr) - '0'; + if (c < 0) + { + *errorcodeptr = ERR61; + break; + } if (c < 10 || c <= bracount) { c = -(ESC_REF + c); @@ -625,7 +711,7 @@ else if (c == 0) { *errorcodeptr = ERR2; - return 0; + break; } #ifndef EBCDIC /* ASCII coding */ @@ -701,7 +787,7 @@ if (c == '{') *negptr = TRUE; ptr++; } - for (i = 0; i < sizeof(name) - 1; i++) + for (i = 0; i < (int)sizeof(name) - 1; i++) { c = *(++ptr); if (c == 0) goto ERROR_RETURN; @@ -730,7 +816,7 @@ top = _pcre_utt_size; while (bot < top) { i = (bot + top) >> 1; - c = strcmp(name, _pcre_utt[i].name); + c = strcmp(name, _pcre_utt_names + _pcre_utt[i].name_offset); if (c == 0) { *dptr = _pcre_utt[i].value; @@ -904,6 +990,7 @@ for (; *ptr != 0; ptr++) { while (*(++ptr) != ']') { + if (*ptr == 0) return -1; if (*ptr == '\\') { if (*(++ptr) == 0) return -1; @@ -931,7 +1018,7 @@ for (; *ptr != 0; ptr++) /* An opening parens must now be a real metacharacter */ if (*ptr != '(') continue; - if (ptr[1] != '?') + if (ptr[1] != '?' && ptr[1] != '*') { count++; if (name == NULL && count == lorn) return count; @@ -1059,7 +1146,6 @@ for (;;) { int d; register int op = *cc; - switch (op) { case OP_CBRA: @@ -1148,6 +1234,7 @@ for (;;) case OP_TYPEEXACT: branchlength += GET2(cc,1); + if (cc[3] == OP_PROP || cc[3] == OP_NOTPROP) cc += 2; cc += 4; break; @@ -1256,13 +1343,42 @@ for (;;) code += _pcre_OP_lengths[c]; } + /* Otherwise, we can get the item's length from the table, except that for + repeated character types, we have to test for \p and \P, which have an extra + two bytes of parameters. */ + + else + { + switch(c) + { + case OP_TYPESTAR: + case OP_TYPEMINSTAR: + case OP_TYPEPLUS: + case OP_TYPEMINPLUS: + case OP_TYPEQUERY: + case OP_TYPEMINQUERY: + case OP_TYPEPOSSTAR: + case OP_TYPEPOSPLUS: + case OP_TYPEPOSQUERY: + if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2; + break; + + case OP_TYPEUPTO: + case OP_TYPEMINUPTO: + case OP_TYPEEXACT: + case OP_TYPEPOSUPTO: + if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2; + break; + } + + /* Add in the fixed length from the table */ + + code += _pcre_OP_lengths[c]; + /* In UTF-8 mode, opcodes that are followed by a character may be followed by a multi-byte character. The length in the table is a minimum, so we have to arrange to skip the extra bytes. */ - else - { - code += _pcre_OP_lengths[c]; #ifdef SUPPORT_UTF8 if (utf8) switch(c) { @@ -1320,14 +1436,42 @@ for (;;) if (c == OP_XCLASS) code += GET(code, 1); - /* Otherwise, we get the item's length from the table. In UTF-8 mode, opcodes - that are followed by a character may be followed by a multi-byte character. - The length in the table is a minimum, so we have to arrange to skip the extra - bytes. */ + /* Otherwise, we can get the item's length from the table, except that for + repeated character types, we have to test for \p and \P, which have an extra + two bytes of parameters. */ else { + switch(c) + { + case OP_TYPESTAR: + case OP_TYPEMINSTAR: + case OP_TYPEPLUS: + case OP_TYPEMINPLUS: + case OP_TYPEQUERY: + case OP_TYPEMINQUERY: + case OP_TYPEPOSSTAR: + case OP_TYPEPOSPLUS: + case OP_TYPEPOSQUERY: + if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2; + break; + + case OP_TYPEPOSUPTO: + case OP_TYPEUPTO: + case OP_TYPEMINUPTO: + case OP_TYPEEXACT: + if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2; + break; + } + + /* Add in the fixed length from the table */ + code += _pcre_OP_lengths[c]; + + /* In UTF-8 mode, opcodes that are followed by a character may be followed + by a multi-byte character. The length in the table is a minimum, so we have + to arrange to skip the extra bytes. */ + #ifdef SUPPORT_UTF8 if (utf8) switch(c) { @@ -1399,7 +1543,7 @@ for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE /* For other groups, scan the branches. */ - if (c == OP_BRA || c == OP_CBRA || c == OP_ONCE) + if (c == OP_BRA || c == OP_CBRA || c == OP_ONCE || c == OP_COND) { BOOL empty_branch; if (GET(code, 1) == 0) return TRUE; /* Hit unclosed bracket */ @@ -1423,11 +1567,15 @@ for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE switch (c) { - /* Check for quantifiers after a class */ + /* Check for quantifiers after a class. XCLASS is used for classes that + cannot be represented just by a bit map. This includes negated single + high-valued characters. The length in _pcre_OP_lengths[] is zero; the + actual length is stored in the compiled code, so we must update "code" + here. */ #ifdef SUPPORT_UTF8 case OP_XCLASS: - ccode = code + GET(code, 1); + ccode = code += GET(code, 1); goto CHECK_CLASS_REPEAT; #endif @@ -1489,6 +1637,26 @@ for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE case OP_TYPEEXACT: return FALSE; + /* These are going to continue, as they may be empty, but we have to + fudge the length for the \p and \P cases. */ + + case OP_TYPESTAR: + case OP_TYPEMINSTAR: + case OP_TYPEPOSSTAR: + case OP_TYPEQUERY: + case OP_TYPEMINQUERY: + case OP_TYPEPOSQUERY: + if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2; + break; + + /* Same for these */ + + case OP_TYPEUPTO: + case OP_TYPEMINUPTO: + case OP_TYPEPOSUPTO: + if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2; + break; + /* End of branch */ case OP_KET: @@ -1605,11 +1773,13 @@ Returns: a value representing the name, or -1 if unknown static int check_posix_name(const uschar *ptr, int len) { +const char *pn = posix_names; register int yield = 0; while (posix_name_lengths[yield] != 0) { if (len == posix_name_lengths[yield] && - strncmp((const char *)ptr, posix_names[yield], len) == 0) return yield; + strncmp((const char *)ptr, pn, len) == 0) return yield; + pn += posix_name_lengths[yield] + 1; yield++; } return -1; @@ -1651,6 +1821,7 @@ adjust_recurse(uschar *group, int adjust, BOOL utf8, compile_data *cd, uschar *save_hwm) { uschar *ptr = group; + while ((ptr = (uschar *)find_recurse(ptr, utf8)) != NULL) { int offset; @@ -2255,6 +2426,15 @@ for (;; ptr++) */ if (code < last_code) code = last_code; + + /* Paranoid check for integer overflow */ + + if (OFLOW_MAX - *lengthptr < code - last_code) + { + *errorcodeptr = ERR20; + goto FAILED; + } + *lengthptr += code - last_code; DPRINTF(("length=%d added %d c=%c\n", *lengthptr, code - last_code, c)); @@ -2367,6 +2547,11 @@ for (;; ptr++) *ptrptr = ptr; if (lengthptr != NULL) { + if (OFLOW_MAX - *lengthptr < code - last_code) + { + *errorcodeptr = ERR20; + goto FAILED; + } *lengthptr += code - last_code; /* To include callout length */ DPRINTF((">> end branch\n")); } @@ -2429,16 +2614,23 @@ for (;; ptr++) goto FAILED; } - /* If the first character is '^', set the negation flag and skip it. */ + /* If the first character is '^', set the negation flag and skip it. Also, + if the first few characters (either before or after ^) are \Q\E or \E we + skip them too. This makes for compatibility with Perl. */ - if ((c = *(++ptr)) == '^') + negate_class = FALSE; + for (;;) { - negate_class = TRUE; c = *(++ptr); - } - else - { - negate_class = FALSE; + if (c == '\\') + { + if (ptr[1] == 'E') ptr++; + else if (strncmp((const char *)ptr+1, "Q\\E", 3) == 0) ptr += 3; + else break; + } + else if (!negate_class && c == '^') + negate_class = TRUE; + else break; } /* Keep a count of chars with values < 256 so that we can optimize the case @@ -2579,7 +2771,7 @@ for (;; ptr++) of the specials, which just set a flag. The sequence \b is a special case. Inside a class (and only there) it is treated as backspace. Elsewhere it marks a word boundary. Other escapes have preset maps ready - to or into the one we are building. We assume they have more than one + to 'or' into the one we are building. We assume they have more than one character in them, so set class_charcount bigger than one. */ if (c == '\\') @@ -2599,6 +2791,7 @@ for (;; ptr++) else inescq = TRUE; continue; } + else if (-c == ESC_E) continue; /* Ignore orphan \E */ if (c < 0) { @@ -2825,6 +3018,12 @@ for (;; ptr++) oldptr = ptr; + /* Remember \r or \n */ + + if (c == '\r' || c == '\n') cd->external_flags |= PCRE_HASCRORLF; + + /* Check for range */ + if (!inescq && ptr[1] == '-') { int d; @@ -2892,6 +3091,10 @@ for (;; ptr++) if (d == c) goto LONE_SINGLE_CHARACTER; /* A few lines below */ + /* Remember \r or \n */ + + if (d == '\r' || d == '\n') cd->external_flags |= PCRE_HASCRORLF; + /* In UTF-8 mode, if the upper limit is > 255, or > 127 for caseless matching, we have to use an XCLASS with extra data items. Caseless matching for characters > 127 is available only if UCP support is @@ -3045,12 +3248,34 @@ for (;; ptr++) goto FAILED; } + +/* This code has been disabled because it would mean that \s counts as +an explicit \r or \n reference, and that's not really what is wanted. Now +we set the flag only if there is a literal "\r" or "\n" in the class. */ + +#if 0 + /* Remember whether \r or \n are in this class */ + + if (negate_class) + { + if ((classbits[1] & 0x24) != 0x24) cd->external_flags |= PCRE_HASCRORLF; + } + else + { + if ((classbits[1] & 0x24) != 0) cd->external_flags |= PCRE_HASCRORLF; + } +#endif + + /* If class_charcount is 1, we saw precisely one character whose value is - less than 256. In non-UTF-8 mode we can always optimize. In UTF-8 mode, we - can optimize the negative case only if there were no characters >= 128 - because OP_NOT and the related opcodes like OP_NOTSTAR operate on - single-bytes only. This is an historical hangover. Maybe one day we can - tidy these opcodes to handle multi-byte characters. + less than 256. As long as there were no characters >= 128 and there was no + use of \p or \P, in other words, no use of any XCLASS features, we can + optimize. + + In UTF-8 mode, we can optimize the negative case only if there were no + characters >= 128 because OP_NOT and the related opcodes like OP_NOTSTAR + operate on single-bytes only. This is an historical hangover. Maybe one day + we can tidy these opcodes to handle multi-byte characters. The optimization throws away the bit map. We turn the item into a 1-character OP_CHAR[NC] if it's positive, or OP_NOT if it's negative. Note @@ -3060,10 +3285,8 @@ for (;; ptr++) reqbyte, save the previous value for reinstating. */ #ifdef SUPPORT_UTF8 - if (class_charcount == 1 && - (!utf8 || - (!class_utf8 && (!negate_class || class_lastchar < 128)))) - + if (class_charcount == 1 && !class_utf8 && + (!utf8 || !negate_class || class_lastchar < 128)) #else if (class_charcount == 1) #endif @@ -3335,7 +3558,7 @@ for (;; ptr++) /* All real repeats make it impossible to handle partial matching (maybe one day we will be able to remove this restriction). */ - if (repeat_max != 1) cd->nopartial = TRUE; + if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; /* Combine the op_type with the repeat_type */ @@ -3485,7 +3708,7 @@ for (;; ptr++) /* All real repeats make it impossible to handle partial matching (maybe one day we will be able to remove this restriction). */ - if (repeat_max != 1) cd->nopartial = TRUE; + if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; if (repeat_min == 0 && repeat_max == -1) *code++ = OP_CRSTAR + repeat_type; @@ -3521,14 +3744,6 @@ for (;; ptr++) goto FAILED; } - /* This is a paranoid check to stop integer overflow later on */ - - if (len > MAX_DUPLENGTH) - { - *errorcodeptr = ERR50; - goto FAILED; - } - /* If the maximum repeat count is unlimited, find the end of the bracket by scanning through from the start, and compute the offset back to it from the current code pointer. There may be an OP_OPT setting following @@ -3617,10 +3832,21 @@ for (;; ptr++) if (repeat_min > 1) { /* In the pre-compile phase, we don't actually do the replication. We - just adjust the length as if we had. */ + just adjust the length as if we had. Do some paranoid checks for + potential integer overflow. */ if (lengthptr != NULL) - *lengthptr += (repeat_min - 1)*length_prevgroup; + { + int delta = (repeat_min - 1)*length_prevgroup; + if ((double)(repeat_min - 1)*(double)length_prevgroup > + (double)INT_MAX || + OFLOW_MAX - *lengthptr < delta) + { + *errorcodeptr = ERR20; + goto FAILED; + } + *lengthptr += delta; + } /* This is compiling for real */ @@ -3658,11 +3884,23 @@ for (;; ptr++) /* In the pre-compile phase, we don't actually do the replication. We just adjust the length as if we had. For each repetition we must add 1 to the length for BRAZERO and for all but the last repetition we must - add 2 + 2*LINKSIZE to allow for the nesting that occurs. */ + add 2 + 2*LINKSIZE to allow for the nesting that occurs. Do some + paranoid checks to avoid integer overflow. */ if (lengthptr != NULL && repeat_max > 0) - *lengthptr += repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) - - 2 - 2*LINK_SIZE; /* Last one doesn't nest */ + { + int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) - + 2 - 2*LINK_SIZE; /* Last one doesn't nest */ + if ((double)repeat_max * + (double)(length_prevgroup + 1 + 2 + 2*LINK_SIZE) + > (double)INT_MAX || + OFLOW_MAX - *lengthptr < delta) + { + *errorcodeptr = ERR20; + goto FAILED; + } + *lengthptr += delta; + } /* This is compiling for real */ @@ -3814,9 +4052,7 @@ for (;; ptr++) /* ===================================================================*/ /* Start of nested parenthesized sub-expression, or comment or lookahead or lookbehind or option setting or condition or all the other extended - parenthesis forms. First deal with the specials; all are introduced by ?, - and the appearance of any of them means that this is not a capturing - group. */ + parenthesis forms. */ case '(': newoptions = options; @@ -3825,7 +4061,46 @@ for (;; ptr++) save_hwm = cd->hwm; reset_bracount = FALSE; - if (*(++ptr) == '?') + /* First deal with various "verbs" that can be introduced by '*'. */ + + if (*(++ptr) == '*' && (cd->ctypes[ptr[1]] & ctype_letter) != 0) + { + int i, namelen; + const char *vn = verbnames; + const uschar *name = ++ptr; + previous = NULL; + while ((cd->ctypes[*++ptr] & ctype_letter) != 0); + if (*ptr == ':') + { + *errorcodeptr = ERR59; /* Not supported */ + goto FAILED; + } + if (*ptr != ')') + { + *errorcodeptr = ERR60; + goto FAILED; + } + namelen = ptr - name; + for (i = 0; i < verbcount; i++) + { + if (namelen == verbs[i].len && + strncmp((char *)name, vn, namelen) == 0) + { + *code = verbs[i].op; + if (*code++ == OP_ACCEPT) cd->had_accept = TRUE; + break; + } + vn += verbs[i].len + 1; + } + if (i < verbcount) continue; + *errorcodeptr = ERR60; + goto FAILED; + } + + /* Deal with the extended parentheses; all are introduced by '?', and the + appearance of any of them means that this is not a capturing group. */ + + else if (*ptr == '?') { int i, set, unset, namelen; int *optset; @@ -4067,8 +4342,14 @@ for (;; ptr++) /* ------------------------------------------------------------ */ case '!': /* Negative lookahead */ - bravalue = OP_ASSERT_NOT; ptr++; + if (*ptr == ')') /* Optimize (?!) */ + { + *code++ = OP_FAIL; + previous = NULL; + continue; + } + bravalue = OP_ASSERT_NOT; break; @@ -4426,7 +4707,7 @@ for (;; ptr++) case 'J': /* Record that it changed in the external options */ *optset |= PCRE_DUPNAMES; - cd->external_options |= PCRE_JCHANGED; + cd->external_flags |= PCRE_JCHANGED; break; case 'i': *optset |= PCRE_CASELESS; break; @@ -4617,23 +4898,29 @@ for (;; ptr++) goto FAILED; } - /* In the pre-compile phase, update the length by the length of the nested - group, less the brackets at either end. Then reduce the compiled code to - just the brackets so that it doesn't use much memory if it is duplicated by - a quantifier. */ + /* In the pre-compile phase, update the length by the length of the group, + less the brackets at either end. Then reduce the compiled code to just a + set of non-capturing brackets so that it doesn't use much memory if it is + duplicated by a quantifier.*/ if (lengthptr != NULL) { + if (OFLOW_MAX - *lengthptr < length_prevgroup - 2 - 2*LINK_SIZE) + { + *errorcodeptr = ERR20; + goto FAILED; + } *lengthptr += length_prevgroup - 2 - 2*LINK_SIZE; - code++; + *code++ = OP_BRA; PUTINC(code, 0, 1 + LINK_SIZE); *code++ = OP_KET; PUTINC(code, 0, 1 + LINK_SIZE); + break; /* No need to waste time with special character handling */ } /* Otherwise update the main code pointer to the end of the group. */ - else code = tempcode; + code = tempcode; /* For a DEFINE group, required and first character settings are not relevant. */ @@ -4837,6 +5124,11 @@ for (;; ptr++) *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARNC : OP_CHAR; for (c = 0; c < mclength; c++) *code++ = mcbuffer[c]; + /* Remember if \r or \n were seen */ + + if (mcbuffer[0] == '\r' || mcbuffer[0] == '\n') + cd->external_flags |= PCRE_HASCRORLF; + /* Set the first and required bytes appropriately. If no previous first byte, set it from this character, but revert to none on a zero repeat. Otherwise, leave the firstbyte value alone, and don't change it on a zero @@ -5119,7 +5411,15 @@ for (;;) *ptrptr = ptr; *firstbyteptr = firstbyte; *reqbyteptr = reqbyte; - if (lengthptr != NULL) *lengthptr += length; + if (lengthptr != NULL) + { + if (OFLOW_MAX - *lengthptr < length) + { + *errorcodeptr = ERR20; + return FALSE; + } + *lengthptr += length; + } return TRUE; } @@ -5428,6 +5728,7 @@ real_pcre *re; int length = 1; /* For final END opcode */ int firstbyte, reqbyte, newline; int errorcode = 0; +int skipatstart = 0; #ifdef SUPPORT_UTF8 BOOL utf8; #endif @@ -5506,13 +5807,55 @@ cd->fcc = tables + fcc_offset; cd->cbits = tables + cbits_offset; cd->ctypes = tables + ctypes_offset; +/* Check for global one-time settings at the start of the pattern, and remember +the offset for later. */ + +while (ptr[skipatstart] == '(' && ptr[skipatstart+1] == '*') + { + int newnl = 0; + int newbsr = 0; + + if (strncmp((char *)(ptr+skipatstart+2), "CR)", 3) == 0) + { skipatstart += 5; newnl = PCRE_NEWLINE_CR; } + else if (strncmp((char *)(ptr+skipatstart+2), "LF)", 3) == 0) + { skipatstart += 5; newnl = PCRE_NEWLINE_LF; } + else if (strncmp((char *)(ptr+skipatstart+2), "CRLF)", 5) == 0) + { skipatstart += 7; newnl = PCRE_NEWLINE_CR + PCRE_NEWLINE_LF; } + else if (strncmp((char *)(ptr+skipatstart+2), "ANY)", 4) == 0) + { skipatstart += 6; newnl = PCRE_NEWLINE_ANY; } + else if (strncmp((char *)(ptr+skipatstart+2), "ANYCRLF)", 8) == 0) + { skipatstart += 10; newnl = PCRE_NEWLINE_ANYCRLF; } + + else if (strncmp((char *)(ptr+skipatstart+2), "BSR_ANYCRLF)", 12) == 0) + { skipatstart += 14; newbsr = PCRE_BSR_ANYCRLF; } + else if (strncmp((char *)(ptr+skipatstart+2), "BSR_UNICODE)", 12) == 0) + { skipatstart += 14; newbsr = PCRE_BSR_UNICODE; } + + if (newnl != 0) + options = (options & ~PCRE_NEWLINE_BITS) | newnl; + else if (newbsr != 0) + options = (options & ~(PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) | newbsr; + else break; + } + +/* Check validity of \R options. */ + +switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) + { + case 0: + case PCRE_BSR_ANYCRLF: + case PCRE_BSR_UNICODE: + break; + default: errorcode = ERR56; goto PCRE_EARLY_ERROR_RETURN; + } + /* Handle different types of newline. The three bits give seven cases. The current code allows for fixed one- or two-byte sequences, plus "any" and "anycrlf". */ -switch (options & (PCRE_NEWLINE_CRLF | PCRE_NEWLINE_ANY)) +switch (options & PCRE_NEWLINE_BITS) { - case 0: newline = NEWLINE; break; /* Compile-time default */ + case 0: newline = NEWLINE; break; /* Build-time default */ case PCRE_NEWLINE_CR: newline = '\r'; break; case PCRE_NEWLINE_LF: newline = '\n'; break; case PCRE_NEWLINE_CR+ @@ -5575,8 +5918,8 @@ cd->hwm = cworkspace; cd->start_pattern = (const uschar *)pattern; cd->end_pattern = (const uschar *)(pattern + strlen(pattern)); cd->req_varyopt = 0; -cd->nopartial = FALSE; cd->external_options = options; +cd->external_flags = 0; /* Now do the pre-compile. On error, errorcode will be set non-zero, so we don't need to look at the result of the function here. The initial options have @@ -5584,6 +5927,7 @@ been put into the cd block so that they can be changed if an option setting is found within the regex right at the beginning. Bringing initial option settings outside can help speed up starting point checks. */ +ptr += skipatstart; code = cworkspace; *code = OP_BRA; (void)compile_regex(cd->external_options, cd->external_options & PCRE_IMS, @@ -5614,14 +5958,16 @@ if (re == NULL) goto PCRE_EARLY_ERROR_RETURN; } -/* Put in the magic number, and save the sizes, initial options, and character -table pointer. NULL is used for the default character tables. The nullpad field -is at the end; it's there to help in the case when a regex compiled on a system -with 4-byte pointers is run on another with 8-byte pointers. */ +/* Put in the magic number, and save the sizes, initial options, internal +flags, and character table pointer. NULL is used for the default character +tables. The nullpad field is at the end; it's there to help in the case when a +regex compiled on a system with 4-byte pointers is run on another with 8-byte +pointers. */ re->magic_number = MAGIC_NUMBER; re->size = size; re->options = cd->external_options; +re->flags = cd->external_flags; re->dummy1 = 0; re->first_byte = 0; re->req_byte = 0; @@ -5646,21 +5992,22 @@ codestart = cd->name_table + re->name_entry_size * re->name_count; cd->start_code = codestart; cd->hwm = cworkspace; cd->req_varyopt = 0; -cd->nopartial = FALSE; +cd->had_accept = FALSE; /* Set up a starting, non-extracting bracket, then compile the expression. On error, errorcode will be set non-zero, so we don't need to look at the result of the function here. */ -ptr = (const uschar *)pattern; +ptr = (const uschar *)pattern + skipatstart; code = (uschar *)codestart; *code = OP_BRA; (void)compile_regex(re->options, re->options & PCRE_IMS, &code, &ptr, &errorcode, FALSE, FALSE, 0, &firstbyte, &reqbyte, NULL, cd, NULL); re->top_bracket = cd->bracount; re->top_backref = cd->top_backref; +re->flags = cd->external_flags; -if (cd->nopartial) re->options |= PCRE_NOPARTIAL; +if (cd->had_accept) reqbyte = -1; /* Must disable after (*ACCEPT) */ /* If not reached end of pattern on success, there's an excess bracket. */ @@ -5702,7 +6049,7 @@ if (errorcode != 0) PCRE_EARLY_ERROR_RETURN: *erroroffset = ptr - (const uschar *)pattern; PCRE_EARLY_ERROR_RETURN2: - *errorptr = error_texts[errorcode]; + *errorptr = find_error_text(errorcode); if (errorcodeptr != NULL) *errorcodeptr = errorcode; return NULL; } @@ -5731,10 +6078,10 @@ if ((re->options & PCRE_ANCHORED) == 0) int ch = firstbyte & 255; re->first_byte = ((firstbyte & REQ_CASELESS) != 0 && cd->fcc[ch] == ch)? ch : firstbyte; - re->options |= PCRE_FIRSTSET; + re->flags |= PCRE_FIRSTSET; } else if (is_startline(codestart, 0, cd->backref_map)) - re->options |= PCRE_STARTLINE; + re->flags |= PCRE_STARTLINE; } } @@ -5748,7 +6095,7 @@ if (reqbyte >= 0 && int ch = reqbyte & 255; re->req_byte = ((reqbyte & REQ_CASELESS) != 0 && cd->fcc[ch] == ch)? (reqbyte & ~REQ_CASELESS) : reqbyte; - re->options |= PCRE_REQCHSET; + re->flags |= PCRE_REQCHSET; } /* Print out the compiled data if debugging is enabled. This is never the @@ -5759,21 +6106,9 @@ case when building a production library. */ printf("Length = %d top_bracket = %d top_backref = %d\n", length, re->top_bracket, re->top_backref); -if (re->options != 0) - { - printf("%s%s%s%s%s%s%s%s%s\n", - ((re->options & PCRE_NOPARTIAL) != 0)? "nopartial " : "", - ((re->options & PCRE_ANCHORED) != 0)? "anchored " : "", - ((re->options & PCRE_CASELESS) != 0)? "caseless " : "", - ((re->options & PCRE_EXTENDED) != 0)? "extended " : "", - ((re->options & PCRE_MULTILINE) != 0)? "multiline " : "", - ((re->options & PCRE_DOTALL) != 0)? "dotall " : "", - ((re->options & PCRE_DOLLAR_ENDONLY) != 0)? "endonly " : "", - ((re->options & PCRE_EXTRA) != 0)? "extra " : "", - ((re->options & PCRE_UNGREEDY) != 0)? "ungreedy " : ""); - } +printf("Options=%08x\n", re->options); -if ((re->options & PCRE_FIRSTSET) != 0) +if ((re->flags & PCRE_FIRSTSET) != 0) { int ch = re->first_byte & 255; const char *caseless = ((re->first_byte & REQ_CASELESS) == 0)? @@ -5782,7 +6117,7 @@ if ((re->options & PCRE_FIRSTSET) != 0) else printf("First char = \\x%02x%s\n", ch, caseless); } -if ((re->options & PCRE_REQCHSET) != 0) +if ((re->flags & PCRE_REQCHSET) != 0) { int ch = re->req_byte & 255; const char *caseless = ((re->req_byte & REQ_CASELESS) == 0)? @@ -5799,7 +6134,7 @@ was compiled can be seen. */ if (code - codestart > length) { (pcre_free)(re); - *errorptr = error_texts[ERR23]; + *errorptr = find_error_text(ERR23); *erroroffset = ptr - (uschar *)pattern; if (errorcodeptr != NULL) *errorcodeptr = ERR23; return NULL; diff --git a/libpcre/pcre_config.c b/libpcre/pcre_config.c index 52d259466..bfb8e1252 100644 --- a/libpcre/pcre_config.c +++ b/libpcre/pcre_config.c @@ -41,6 +41,12 @@ POSSIBILITY OF SUCH DAMAGE. /* This module contains the external function pcre_config(). */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" @@ -83,6 +89,14 @@ switch (what) *((int *)where) = NEWLINE; break; + case PCRE_CONFIG_BSR: +#ifdef BSR_ANYCRLF + *((int *)where) = 1; +#else + *((int *)where) = 0; +#endif + break; + case PCRE_CONFIG_LINK_SIZE: *((int *)where) = LINK_SIZE; break; diff --git a/libpcre/pcre_dfa_exec.c b/libpcre/pcre_dfa_exec.c index 87f9746af..48d7e62b4 100644 --- a/libpcre/pcre_dfa_exec.c +++ b/libpcre/pcre_dfa_exec.c @@ -44,6 +44,12 @@ FSM). This is NOT Perl- compatible, but it has advantages in certain applications. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #define NLBLOCK md /* Block containing newline information */ #define PSSTART start_subject /* Field containing processed string start */ #define PSEND end_subject /* Field containing processed string end */ @@ -126,7 +132,9 @@ static uschar coptable[] = { 0, /* CREF */ 0, /* RREF */ 0, /* DEF */ - 0, 0 /* BRAZERO, BRAMINZERO */ + 0, 0, /* BRAZERO, BRAMINZERO */ + 0, 0, 0, 0, /* PRUNE, SKIP, THEN, COMMIT */ + 0, 0 /* FAIL, ACCEPT */ }; /* These 2 tables allow for compact code for testing for \D, \d, \S, \s, \W, @@ -1074,15 +1082,20 @@ for (;;) int ncount = 0; switch (c) { - case 0x000d: - if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; - /* Fall through */ - case 0x000a: case 0x000b: case 0x000c: case 0x0085: case 0x2028: case 0x2029: + if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break; + goto ANYNL01; + + case 0x000d: + if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; + /* Fall through */ + + ANYNL01: + case 0x000a: if (count > 0 && codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSPLUS) { active_count--; /* Remove non-match possibility */ @@ -1091,6 +1104,7 @@ for (;;) count++; ADD_NEW_DATA(-state_offset, count, ncount); break; + default: break; } @@ -1307,15 +1321,20 @@ for (;;) int ncount = 0; switch (c) { - case 0x000d: - if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; - /* Fall through */ - case 0x000a: case 0x000b: case 0x000c: case 0x0085: case 0x2028: case 0x2029: + if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break; + goto ANYNL02; + + case 0x000d: + if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; + /* Fall through */ + + ANYNL02: + case 0x000a: if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSSTAR || codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSQUERY) { @@ -1324,6 +1343,7 @@ for (;;) } ADD_NEW_DATA(-(state_offset + count), 0, ncount); break; + default: break; } @@ -1539,15 +1559,20 @@ for (;;) int ncount = 0; switch (c) { - case 0x000d: - if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; - /* Fall through */ - case 0x000a: case 0x000b: case 0x000c: case 0x0085: case 0x2028: case 0x2029: + if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break; + goto ANYNL03; + + case 0x000d: + if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; + /* Fall through */ + + ANYNL03: + case 0x000a: if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSUPTO) { active_count--; /* Remove non-match possibility */ @@ -1558,6 +1583,7 @@ for (;;) else { ADD_NEW_DATA(-state_offset, count, ncount); } break; + default: break; } @@ -1738,14 +1764,17 @@ for (;;) case OP_ANYNL: if (clen > 0) switch(c) { - case 0x000a: case 0x000b: case 0x000c: case 0x0085: case 0x2028: case 0x2029: + if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break; + + case 0x000a: ADD_NEW(state_offset + 1, 0); break; + case 0x000d: if (ptr + 1 < end_subject && ptr[1] == 0x0a) { @@ -2568,6 +2597,18 @@ md->end_subject = end_subject; md->moptions = options; md->poptions = re->options; +/* If the BSR option is not set at match time, copy what was set +at compile time. */ + +if ((md->moptions & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) == 0) + { + if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0) + md->moptions |= re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE); +#ifdef BSR_ANYCRLF + else md->moptions |= PCRE_BSR_ANYCRLF; +#endif + } + /* Handle different types of newline. The three bits give eight cases. If nothing is set at run time, whatever was used at compile time applies. */ @@ -2638,7 +2679,7 @@ if (md->tables == NULL) md->tables = _pcre_default_tables; used in a loop when finding where to start. */ lcc = md->tables + lcc_offset; -startline = (re->options & PCRE_STARTLINE) != 0; +startline = (re->flags & PCRE_STARTLINE) != 0; firstline = (re->options & PCRE_FIRSTLINE) != 0; /* Set up the first character to match, if available. The first_byte value is @@ -2649,7 +2690,7 @@ studied, there may be a bitmap of possible first characters. */ if (!anchored) { - if ((re->options & PCRE_FIRSTSET) != 0) + if ((re->flags & PCRE_FIRSTSET) != 0) { first_byte = re->first_byte & 255; if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE) @@ -2666,7 +2707,7 @@ if (!anchored) /* For anchored or unanchored matches, there may be a "last known required character" set. */ -if ((re->options & PCRE_REQCHSET) != 0) +if ((re->flags & PCRE_REQCHSET) != 0) { req_byte = re->req_byte & 255; req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0; @@ -2836,16 +2877,17 @@ for (;;) } if (current_subject > end_subject) break; - /* If we have just passed a CR and the newline option is CRLF or ANY or - ANYCRLF, and we are now at a LF, advance the match position by one more - character. */ + /* If we have just passed a CR and we are now at a LF, and the pattern does + not contain any explicit matches for \r or \n, and the newline option is CRLF + or ANY or ANYCRLF, advance the match position by one more character. */ if (current_subject[-1] == '\r' && - (md->nltype == NLTYPE_ANY || - md->nltype == NLTYPE_ANYCRLF || - md->nllen == 2) && - current_subject < end_subject && - *current_subject == '\n') + current_subject < end_subject && + *current_subject == '\n' && + (re->flags & PCRE_HASCRORLF) == 0 && + (md->nltype == NLTYPE_ANY || + md->nltype == NLTYPE_ANYCRLF || + md->nllen == 2)) current_subject++; } /* "Bumpalong" loop */ diff --git a/libpcre/pcre_exec.c b/libpcre/pcre_exec.c index a749a216e..f12d3e069 100644 --- a/libpcre/pcre_exec.c +++ b/libpcre/pcre_exec.c @@ -42,6 +42,12 @@ POSSIBILITY OF SUCH DAMAGE. pattern matching using an NFA algorithm, trying to mimic Perl as closely as possible. There are also some static supporting functions. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #define NLBLOCK md /* Block containing newline information */ #define PSSTART start_subject /* Field containing processed string start */ #define PSEND end_subject /* Field containing processed string end */ @@ -53,16 +59,10 @@ possible. There are also some static supporting functions. */ #undef min #undef max -/* The chain of eptrblocks for tail recursions uses memory in stack workspace, -obtained at top level, the size of which is defined by EPTR_WORK_SIZE. */ - -#define EPTR_WORK_SIZE (1000) - /* Flag bits for the match() function */ #define match_condassert 0x01 /* Called to check a condition assertion */ #define match_cbegroup 0x02 /* Could-be-empty unlimited repeat group */ -#define match_tail_recursed 0x04 /* Tail recursive call */ /* Non-error returns from the match() function. Error returns are externally defined PCRE_ERROR_xxx codes, which are all negative. */ @@ -70,6 +70,14 @@ defined PCRE_ERROR_xxx codes, which are all negative. */ #define MATCH_MATCH 1 #define MATCH_NOMATCH 0 +/* Special internal returns from the match() function. Make them sufficiently +negative to avoid the external error codes. */ + +#define MATCH_COMMIT (-999) +#define MATCH_PRUNE (-998) +#define MATCH_SKIP (-997) +#define MATCH_THEN (-996) + /* Maximum number of ints of offset to save on the stack for recursive calls. If the offset vector is bigger, malloc is used. This should be a multiple of 3, because the offset vector is always a multiple of 3 long. */ @@ -205,15 +213,15 @@ variable instead of being passed in the frame. **************************************************************************** ***************************************************************************/ - -/* Numbers for RMATCH calls */ +/* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN +below must be updated in sync. */ enum { RM1=1, RM2, RM3, RM4, RM5, RM6, RM7, RM8, RM9, RM10, RM11, RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20, RM21, RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30, RM31, RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40, - RM41, RM42, RM43, RM44, RM45, RM46, RM47 }; - + RM41, RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50, + RM51, RM52, RM53, RM54 }; /* These versions of the macros use the stack, as normal. There are debugging versions and production versions. Note that the "rw" argument of RMATCH isn't @@ -384,7 +392,6 @@ Arguments: match_condassert - this is an assertion condition match_cbegroup - this is the start of an unlimited repeat group that can match an empty string - match_tail_recursed - this is a tail_recursed group rdepth the recursion depth Returns: MATCH_MATCH if matched ) these values are >= 0 @@ -586,22 +593,16 @@ original_ims = ims; /* Save for resetting on ')' */ string, the match_cbegroup flag is set. When this is the case, add the current subject pointer to the chain of such remembered pointers, to be checked when we hit the closing ket, in order to break infinite loops that match no characters. -When match() is called in other circumstances, don't add to the chain. If this -is a tail recursion, use a block from the workspace, as the one on the stack is -already used. */ +When match() is called in other circumstances, don't add to the chain. The +match_cbegroup flag must NOT be used with tail recursion, because the memory +block that is used is on the stack, so a new one may be required for each +match(). */ if ((flags & match_cbegroup) != 0) { - eptrblock *p; - if ((flags & match_tail_recursed) != 0) - { - if (md->eptrn >= EPTR_WORK_SIZE) RRETURN(PCRE_ERROR_NULLWSLIMIT); - p = md->eptrchain + md->eptrn++; - } - else p = &newptrb; - p->epb_saved_eptr = eptr; - p->epb_prev = eptrb; - eptrb = p; + newptrb.epb_saved_eptr = eptr; + newptrb.epb_prev = eptrb; + eptrb = &newptrb; } /* Now start processing the opcodes. */ @@ -621,6 +622,34 @@ for (;;) switch(op) { + case OP_FAIL: + RRETURN(MATCH_NOMATCH); + + case OP_PRUNE: + RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, + ims, eptrb, flags, RM51); + if (rrc != MATCH_NOMATCH) RRETURN(rrc); + RRETURN(MATCH_PRUNE); + + case OP_COMMIT: + RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, + ims, eptrb, flags, RM52); + if (rrc != MATCH_NOMATCH) RRETURN(rrc); + RRETURN(MATCH_COMMIT); + + case OP_SKIP: + RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, + ims, eptrb, flags, RM53); + if (rrc != MATCH_NOMATCH) RRETURN(rrc); + md->start_match_ptr = eptr; /* Pass back current position */ + RRETURN(MATCH_SKIP); + + case OP_THEN: + RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, + ims, eptrb, flags, RM54); + if (rrc != MATCH_NOMATCH) RRETURN(rrc); + RRETURN(MATCH_THEN); + /* Handle a capturing bracket. If there is space in the offset vector, save the current subject position in the working slot at the top of the vector. We mustn't change the current values of the data slot, because they may be @@ -662,7 +691,7 @@ for (;;) { RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, eptrb, flags, RM1); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); + if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); md->capture_last = save_capture_last; ecode += GET(ecode, 1); } @@ -677,15 +706,22 @@ for (;;) RRETURN(MATCH_NOMATCH); } - /* Insufficient room for saving captured contents. Treat as a non-capturing - bracket. */ + /* FALL THROUGH ... Insufficient room for saving captured contents. Treat + as a non-capturing bracket. */ + + /* VVVVVVVVVVVVVVVVVVVVVVVVV */ + /* VVVVVVVVVVVVVVVVVVVVVVVVV */ DPRINTF(("insufficient capture room: treat as non-capturing\n")); + /* VVVVVVVVVVVVVVVVVVVVVVVVV */ + /* VVVVVVVVVVVVVVVVVVVVVVVVV */ + /* Non-capturing bracket. Loop for all the alternatives. When we get to the final alternative within the brackets, we would return the result of a recursive call to match() whatever happened. We can reduce stack usage by - turning this into a tail recursion. */ + turning this into a tail recursion, except in the case when match_cbegroup + is set.*/ case OP_BRA: case OP_SBRA: @@ -693,12 +729,20 @@ for (;;) flags = (op >= OP_SBRA)? match_cbegroup : 0; for (;;) { - if (ecode[GET(ecode, 1)] != OP_ALT) + if (ecode[GET(ecode, 1)] != OP_ALT) /* Final alternative */ { - ecode += _pcre_OP_lengths[*ecode]; - flags |= match_tail_recursed; - DPRINTF(("bracket 0 tail recursion\n")); - goto TAIL_RECURSE; + if (flags == 0) /* Not a possibly empty group */ + { + ecode += _pcre_OP_lengths[*ecode]; + DPRINTF(("bracket 0 tail recursion\n")); + goto TAIL_RECURSE; + } + + /* Possibly empty group; can't use tail recursion. */ + + RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, + eptrb, flags, RM48); + RRETURN(rrc); } /* For non-final alternatives, continue the loop for a NOMATCH result; @@ -706,7 +750,7 @@ for (;;) RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, eptrb, flags, RM2); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); + if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); ecode += GET(ecode, 1); } /* Control never reaches here. */ @@ -754,7 +798,7 @@ for (;;) ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2); while (*ecode == OP_ALT) ecode += GET(ecode, 1); } - else if (rrc != MATCH_NOMATCH) + else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) { RRETURN(rrc); /* Need braces because of following else */ } @@ -766,25 +810,36 @@ for (;;) } /* We are now at the branch that is to be obeyed. As there is only one, - we can use tail recursion to avoid using another stack frame. If the second - alternative doesn't exist, we can just plough on. */ + we can use tail recursion to avoid using another stack frame, except when + match_cbegroup is required for an unlimited repeat of a possibly empty + group. If the second alternative doesn't exist, we can just plough on. */ if (condition || *ecode == OP_ALT) { ecode += 1 + LINK_SIZE; - flags = match_tail_recursed | ((op == OP_SCOND)? match_cbegroup : 0); - goto TAIL_RECURSE; + if (op == OP_SCOND) /* Possibly empty group */ + { + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49); + RRETURN(rrc); + } + else /* Group must match something */ + { + flags = 0; + goto TAIL_RECURSE; + } } - else + else /* Condition false & no 2nd alternative */ { ecode += 1 + LINK_SIZE; } break; - /* End of the pattern. If we are in a top-level recursion, we should - restore the offsets appropriately and continue from after the call. */ + /* End of the pattern, either real or forced. If we are in a top-level + recursion, we should restore the offsets appropriately and continue from + after the call. */ + case OP_ACCEPT: case OP_END: if (md->recursive != NULL && md->recursive->group_num == 0) { @@ -805,7 +860,7 @@ for (;;) if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH); md->end_match_ptr = eptr; /* Record where we ended */ md->end_offset_top = offset_top; /* and how many extracts were taken */ - md->start_match_ptr = mstart; /* and the start (\K can modify) */ + md->start_match_ptr = mstart; /* and the start (\K can modify) */ RRETURN(MATCH_MATCH); /* Change option settings */ @@ -829,7 +884,7 @@ for (;;) RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, RM4); if (rrc == MATCH_MATCH) break; - if (rrc != MATCH_NOMATCH) RRETURN(rrc); + if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); ecode += GET(ecode, 1); } while (*ecode == OP_ALT); @@ -856,7 +911,7 @@ for (;;) RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, RM5); if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); + if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); ecode += GET(ecode,1); } while (*ecode == OP_ALT); @@ -880,7 +935,7 @@ for (;;) { eptr--; if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); - BACKCHAR(eptr) + BACKCHAR(eptr); } } else @@ -993,7 +1048,7 @@ for (;;) (pcre_free)(new_recursive.offset_save); RRETURN(MATCH_MATCH); } - else if (rrc != MATCH_NOMATCH) + else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) { DPRINTF(("Recursion gave error %d\n", rrc)); RRETURN(rrc); @@ -1027,10 +1082,9 @@ for (;;) do { - RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, - eptrb, 0, RM7); + RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7); if (rrc == MATCH_MATCH) break; - if (rrc != MATCH_NOMATCH) RRETURN(rrc); + if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); ecode += GET(ecode,1); } while (*ecode == OP_ALT); @@ -1073,11 +1127,10 @@ for (;;) if (*ecode == OP_KETRMIN) { - RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, - RM8); + RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8); if (rrc != MATCH_NOMATCH) RRETURN(rrc); ecode = prev; - flags = match_tail_recursed; + flags = 0; goto TAIL_RECURSE; } else /* OP_KETRMAX */ @@ -1085,7 +1138,7 @@ for (;;) RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9); if (rrc != MATCH_NOMATCH) RRETURN(rrc); ecode += 1 + LINK_SIZE; - flags = match_tail_recursed; + flags = 0; goto TAIL_RECURSE; } /* Control never gets here */ @@ -1216,17 +1269,21 @@ for (;;) /* The repeating kets try the rest of the pattern or restart from the preceding bracket, in the appropriate order. In the second case, we can use - tail recursion to avoid using another stack frame. */ + tail recursion to avoid using another stack frame, unless we have an + unlimited repeat of a group that can match an empty string. */ flags = (*prev >= OP_SBRA)? match_cbegroup : 0; if (*ecode == OP_KETRMIN) { - RMATCH(eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, - RM12); + RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12); if (rrc != MATCH_NOMATCH) RRETURN(rrc); + if (flags != 0) /* Could match an empty string */ + { + RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50); + RRETURN(rrc); + } ecode = prev; - flags |= match_tail_recursed; goto TAIL_RECURSE; } else /* OP_KETRMAX */ @@ -1234,7 +1291,7 @@ for (;;) RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13); if (rrc != MATCH_NOMATCH) RRETURN(rrc); ecode += 1 + LINK_SIZE; - flags = match_tail_recursed; + flags = 0; goto TAIL_RECURSE; } /* Control never gets here */ @@ -1471,12 +1528,16 @@ for (;;) case 0x000d: if (eptr < md->end_subject && *eptr == 0x0a) eptr++; break; + case 0x000a: + break; + case 0x000b: case 0x000c: case 0x0085: case 0x2028: case 0x2029: + if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); break; } ecode++; @@ -2033,7 +2094,7 @@ for (;;) RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (eptr-- == pp) break; /* Stop if tried at original pos */ - BACKCHAR(eptr) + if (utf8) BACKCHAR(eptr); } RRETURN(MATCH_NOMATCH); } @@ -2899,12 +2960,16 @@ for (;;) case 0x000d: if (eptr < md->end_subject && *eptr == 0x0a) eptr++; break; + case 0x000a: + break; + case 0x000b: case 0x000c: case 0x0085: case 0x2028: case 0x2029: + if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); break; } } @@ -3038,9 +3103,9 @@ for (;;) for (i = 1; i <= min; i++) { if (eptr >= md->end_subject || - (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0)) + (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)) RRETURN(MATCH_NOMATCH); - while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; + while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80); } break; @@ -3058,9 +3123,9 @@ for (;;) for (i = 1; i <= min; i++) { if (eptr >= md->end_subject || - (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0)) + (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)) RRETURN(MATCH_NOMATCH); - while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; + while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80); } break; @@ -3117,9 +3182,12 @@ for (;;) if (eptr < md->end_subject && *eptr == 0x0a) eptr++; break; case 0x000a: + break; + case 0x000b: case 0x000c: case 0x0085: + if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); break; } } @@ -3371,11 +3439,14 @@ for (;;) if (eptr < md->end_subject && *eptr == 0x0a) eptr++; break; case 0x000a: + break; + case 0x000b: case 0x000c: case 0x0085: case 0x2028: case 0x2029: + if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); break; } break; @@ -3527,10 +3598,14 @@ for (;;) case 0x000d: if (eptr < md->end_subject && *eptr == 0x0a) eptr++; break; + case 0x000a: + break; + case 0x000b: case 0x000c: case 0x0085: + if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); break; } break; @@ -3702,7 +3777,7 @@ for (;;) RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (eptr-- == pp) break; /* Stop if tried at original pos */ - BACKCHAR(eptr); + if (utf8) BACKCHAR(eptr); } } @@ -3741,9 +3816,9 @@ for (;;) for (;;) /* Move back over one extended */ { int len = 1; - BACKCHAR(eptr); if (!utf8) c = *eptr; else { + BACKCHAR(eptr); GETCHARLEN(c, eptr, len); } prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); @@ -3764,11 +3839,6 @@ for (;;) switch(ctype) { case OP_ANY: - - /* Special code is required for UTF8, but when the maximum is - unlimited we don't need it, so we repeat the non-UTF8 code. This is - probably worth it, because .* is quite a common idiom. */ - if (max < INT_MAX) { if ((ims & PCRE_DOTALL) == 0) @@ -3801,15 +3871,12 @@ for (;;) { if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; eptr++; + while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; } - break; } else { - c = max - min; - if (c > (unsigned int)(md->end_subject - eptr)) - c = md->end_subject - eptr; - eptr += c; + eptr = md->end_subject; } } break; @@ -3836,8 +3903,10 @@ for (;;) } else { - if (c != 0x000a && c != 0x000b && c != 0x000c && - c != 0x0085 && c != 0x2028 && c != 0x2029) + if (c != 0x000a && + (md->bsr_anycrlf || + (c != 0x000b && c != 0x000c && + c != 0x0085 && c != 0x2028 && c != 0x2029))) break; eptr += len; } @@ -3990,7 +4059,7 @@ for (;;) } } else -#endif +#endif /* SUPPORT_UTF8 */ /* Not UTF-8 mode */ { @@ -4027,7 +4096,9 @@ for (;;) } else { - if (c != 0x000a && c != 0x000b && c != 0x000c && c != 0x0085) + if (c != 0x000a && + (md->bsr_anycrlf || + (c != 0x000b && c != 0x000c && c != 0x0085))) break; eptr++; } @@ -4177,11 +4248,17 @@ HEAP_RETURN: switch (frame->Xwhere) { LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8) - LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(16) - LBL(17) LBL(18) LBL(19) LBL(20) LBL(21) LBL(22) LBL(23) LBL(24) - LBL(25) LBL(26) LBL(27) LBL(28) LBL(29) LBL(30) LBL(31) LBL(32) - LBL(33) LBL(34) LBL(35) LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) - LBL(41) LBL(42) LBL(43) LBL(44) LBL(45) LBL(46) LBL(47) + LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17) + LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33) + LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52) + LBL(53) LBL(54) +#ifdef SUPPORT_UTF8 + LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30) + LBL(32) LBL(34) LBL(42) LBL(46) +#ifdef SUPPORT_UCP + LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45) +#endif /* SUPPORT_UCP */ +#endif /* SUPPORT_UTF8 */ default: DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere)); return PCRE_ERROR_INTERNAL; @@ -4298,7 +4375,6 @@ const uschar *start_bits = NULL; USPTR start_match = (USPTR)subject + start_offset; USPTR end_subject; USPTR req_byte_ptr = start_match - 1; -eptrblock eptrchain[EPTR_WORK_SIZE]; pcre_study_data internal_study; const pcre_study_data *study; @@ -4361,7 +4437,7 @@ if (re->magic_number != MAGIC_NUMBER) /* Set up other data */ anchored = ((re->options | options) & PCRE_ANCHORED) != 0; -startline = (re->options & PCRE_STARTLINE) != 0; +startline = (re->flags & PCRE_STARTLINE) != 0; firstline = (re->options & PCRE_FIRSTLINE) != 0; /* The code starts after the real_pcre block and the capture name table. */ @@ -4384,16 +4460,41 @@ md->partial = (options & PCRE_PARTIAL) != 0; md->hitend = FALSE; md->recursive = NULL; /* No recursion at top level */ -md->eptrchain = eptrchain; /* Make workspace generally available */ md->lcc = tables + lcc_offset; md->ctypes = tables + ctypes_offset; +/* Handle different \R options. */ + +switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) + { + case 0: + if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0) + md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0; + else +#ifdef BSR_ANYCRLF + md->bsr_anycrlf = TRUE; +#else + md->bsr_anycrlf = FALSE; +#endif + break; + + case PCRE_BSR_ANYCRLF: + md->bsr_anycrlf = TRUE; + break; + + case PCRE_BSR_UNICODE: + md->bsr_anycrlf = FALSE; + break; + + default: return PCRE_ERROR_BADNEWLINE; + } + /* Handle different types of newline. The three bits give eight cases. If nothing is set at run time, whatever was used at compile time applies. */ -switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : (pcre_uint32)options) & - PCRE_NEWLINE_BITS) +switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : + (pcre_uint32)options) & PCRE_NEWLINE_BITS) { case 0: newline = NEWLINE; break; /* Compile-time default */ case PCRE_NEWLINE_CR: newline = '\r'; break; @@ -4432,7 +4533,7 @@ else /* Partial matching is supported only for a restricted set of regexes at the moment. */ -if (md->partial && (re->options & PCRE_NOPARTIAL) != 0) +if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0) return PCRE_ERROR_BADPARTIAL; /* Check a UTF-8 string if required. Unfortunately there's no way of passing @@ -4509,7 +4610,7 @@ studied, there may be a bitmap of possible first characters. */ if (!anchored) { - if ((re->options & PCRE_FIRSTSET) != 0) + if ((re->flags & PCRE_FIRSTSET) != 0) { first_byte = re->first_byte & 255; if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE) @@ -4524,7 +4625,7 @@ if (!anchored) /* For anchored or unanchored matches, there may be a "last known required character" set. */ -if ((re->options & PCRE_REQCHSET) != 0) +if ((re->flags & PCRE_REQCHSET) != 0) { req_byte = re->req_byte & 255; req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0; @@ -4540,6 +4641,7 @@ the loop runs just once. */ for(;;) { USPTR save_end_subject = end_subject; + USPTR new_start_match; /* Reset the maximum number of extractions we might see. */ @@ -4680,15 +4782,48 @@ for(;;) /* OK, we can now run the match. */ - md->start_match_ptr = start_match; /* Insurance */ + md->start_match_ptr = start_match; md->match_call_count = 0; - md->eptrn = 0; /* Next free eptrchain slot */ - rc = match(start_match, md->start_code, start_match, 2, md, - ims, NULL, 0, 0); + rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0); - /* Any return other than MATCH_NOMATCH breaks the loop. */ + switch(rc) + { + /* NOMATCH and PRUNE advance by one character. THEN at this level acts + exactly like PRUNE. */ - if (rc != MATCH_NOMATCH) break; + case MATCH_NOMATCH: + case MATCH_PRUNE: + case MATCH_THEN: + new_start_match = start_match + 1; +#ifdef SUPPORT_UTF8 + if (utf8) + while(new_start_match < end_subject && (*new_start_match & 0xc0) == 0x80) + new_start_match++; +#endif + break; + + /* SKIP passes back the next starting point explicitly. */ + + case MATCH_SKIP: + new_start_match = md->start_match_ptr; + break; + + /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */ + + case MATCH_COMMIT: + rc = MATCH_NOMATCH; + goto ENDLOOP; + + /* Any other return is some kind of error. */ + + default: + goto ENDLOOP; + } + + /* Control reaches here for the various types of "no match at this point" + result. Reset the code to MATCH_NOMATCH for subsequent checking. */ + + rc = MATCH_NOMATCH; /* If PCRE_FIRSTLINE is set, the match must happen before or at the first newline in the subject (though it may continue over the newline). Therefore, @@ -4696,30 +4831,26 @@ for(;;) if (firstline && IS_NEWLINE(start_match)) break; - /* Advance the match position by one character. */ + /* Advance to new matching position */ - start_match++; -#ifdef SUPPORT_UTF8 - if (utf8) - while(start_match < end_subject && (*start_match & 0xc0) == 0x80) - start_match++; -#endif + start_match = new_start_match; /* Break the loop if the pattern is anchored or if we have passed the end of the subject. */ if (anchored || start_match > end_subject) break; - /* If we have just passed a CR and the newline option is CRLF or ANY or - ANYCRLF, and we are now at a LF, advance the match position by one more - character. */ + /* If we have just passed a CR and we are now at a LF, and the pattern does + not contain any explicit matches for \r or \n, and the newline option is CRLF + or ANY or ANYCRLF, advance the match position by one more character. */ if (start_match[-1] == '\r' && - (md->nltype == NLTYPE_ANY || - md->nltype == NLTYPE_ANYCRLF || - md->nllen == 2) && - start_match < end_subject && - *start_match == '\n') + start_match < end_subject && + *start_match == '\n' && + (re->flags & PCRE_HASCRORLF) == 0 && + (md->nltype == NLTYPE_ANY || + md->nltype == NLTYPE_ANYCRLF || + md->nllen == 2)) start_match++; } /* End of for(;;) "bumpalong" loop */ @@ -4729,7 +4860,7 @@ for(;;) /* We reach here when rc is not MATCH_NOMATCH, or if one of the stopping conditions is true: -(1) The pattern is anchored; +(1) The pattern is anchored or the match was failed by (*COMMIT); (2) We are past the end of the subject; @@ -4744,6 +4875,8 @@ processing, copy those that we can. In this case there need not be overflow if certain parts of the pattern were not used, even though there are more capturing parentheses than vector slots. */ +ENDLOOP: + if (rc == MATCH_MATCH) { if (using_temporary_offsets) diff --git a/libpcre/pcre_fullinfo.c b/libpcre/pcre_fullinfo.c index 797eddecf..fc34fd756 100644 --- a/libpcre/pcre_fullinfo.c +++ b/libpcre/pcre_fullinfo.c @@ -42,6 +42,12 @@ POSSIBILITY OF SUCH DAMAGE. information about a compiled pattern. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" @@ -106,8 +112,8 @@ switch (what) case PCRE_INFO_FIRSTBYTE: *((int *)where) = - ((re->options & PCRE_FIRSTSET) != 0)? re->first_byte : - ((re->options & PCRE_STARTLINE) != 0)? -1 : -2; + ((re->flags & PCRE_FIRSTSET) != 0)? re->first_byte : + ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2; break; /* Make sure we pass back the pointer to the bit vector in the external @@ -121,7 +127,7 @@ switch (what) case PCRE_INFO_LASTLITERAL: *((int *)where) = - ((re->options & PCRE_REQCHSET) != 0)? re->req_byte : -1; + ((re->flags & PCRE_REQCHSET) != 0)? re->req_byte : -1; break; case PCRE_INFO_NAMEENTRYSIZE: @@ -141,11 +147,15 @@ switch (what) break; case PCRE_INFO_OKPARTIAL: - *((int *)where) = (re->options & PCRE_NOPARTIAL) == 0; + *((int *)where) = (re->flags & PCRE_NOPARTIAL) == 0; break; case PCRE_INFO_JCHANGED: - *((int *)where) = (re->options & PCRE_JCHANGED) != 0; + *((int *)where) = (re->flags & PCRE_JCHANGED) != 0; + break; + + case PCRE_INFO_HASCRORLF: + *((int *)where) = (re->flags & PCRE_HASCRORLF) != 0; break; default: return PCRE_ERROR_BADOPTION; diff --git a/libpcre/pcre_get.c b/libpcre/pcre_get.c index ba0c8cb21..6b96906b4 100644 --- a/libpcre/pcre_get.c +++ b/libpcre/pcre_get.c @@ -43,6 +43,12 @@ from the subject string after a regex match has succeeded. The original idea for these functions came from Scott Wimer. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" @@ -185,7 +191,7 @@ const real_pcre *re = (const real_pcre *)code; int entrysize; char *first, *last; uschar *entry; -if ((re->options & (PCRE_DUPNAMES | PCRE_JCHANGED)) == 0) +if ((re->options & PCRE_DUPNAMES) == 0 && (re->flags & PCRE_JCHANGED) == 0) return pcre_get_stringnumber(code, stringname); entrysize = pcre_get_stringtable_entries(code, stringname, &first, &last); if (entrysize <= 0) return entrysize; diff --git a/libpcre/pcre_globals.c b/libpcre/pcre_globals.c index dbde57e02..81f0f8862 100644 --- a/libpcre/pcre_globals.c +++ b/libpcre/pcre_globals.c @@ -46,6 +46,12 @@ indirection. These values can be changed by the caller, but are shared between all threads. However, when compiling for Virtual Pascal, things are done differently, and global variables are not used (see pcre.in). */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" #ifndef VPCOMPAT diff --git a/libpcre/pcre_info.c b/libpcre/pcre_info.c index 52ac23f70..8e53e1414 100644 --- a/libpcre/pcre_info.c +++ b/libpcre/pcre_info.c @@ -43,6 +43,12 @@ information about a compiled pattern. However, use of this function is now deprecated, as it has been superseded by pcre_fullinfo(). */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" @@ -81,8 +87,8 @@ if (re->magic_number != MAGIC_NUMBER) } if (optptr != NULL) *optptr = (int)(re->options & PUBLIC_OPTIONS); if (first_byte != NULL) - *first_byte = ((re->options & PCRE_FIRSTSET) != 0)? re->first_byte : - ((re->options & PCRE_STARTLINE) != 0)? -1 : -2; + *first_byte = ((re->flags & PCRE_FIRSTSET) != 0)? re->first_byte : + ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2; return re->top_bracket; } diff --git a/libpcre/pcre_internal.h b/libpcre/pcre_internal.h index 6ef019bb1..ca0c3efa6 100644 --- a/libpcre/pcre_internal.h +++ b/libpcre/pcre_internal.h @@ -67,14 +67,6 @@ be absolutely sure we get our version. */ #endif -/* Get the definitions provided by running "configure" */ - -#ifdef WIN32 -#include "pcre_winconfig.h" -#else -#include "config.h" -#endif - /* Standard C headers plus the external interface definition. The only time setjmp and stdarg are used is when NO_RECURSE is set. */ @@ -117,7 +109,7 @@ PCRE_EXP_DATA_DEFN only if they are not already set. */ #ifndef PCRE_EXP_DECL # ifdef _WIN32 /* COMMENTED OUT AS IT'S COMPILED STATICALLY -# ifdef DLL_EXPORT +# ifndef PCRE_STATIC # define PCRE_EXP_DECL extern __declspec(dllexport) # define PCRE_EXP_DEFN __declspec(dllexport) # define PCRE_EXP_DATA_DEFN __declspec(dllexport) @@ -129,7 +121,6 @@ PCRE_EXP_DATA_DEFN only if they are not already set. */ /* # endif */ -# # else # ifdef __cplusplus # define PCRE_EXP_DECL extern "C" @@ -371,7 +362,9 @@ capturing parenthesis numbers in back references. */ /* When UTF-8 encoding is being used, a character is no longer just a single byte. The macros for character handling generate simple sequences when used in -byte-mode, and more complicated ones for UTF-8 characters. */ +byte-mode, and more complicated ones for UTF-8 characters. BACKCHAR should +never be called in byte mode. To make sure it can never even appear when UTF-8 +support is omitted, we don't even define it. */ #ifndef SUPPORT_UTF8 #define GETCHAR(c, eptr) c = *eptr; @@ -379,7 +372,7 @@ byte-mode, and more complicated ones for UTF-8 characters. */ #define GETCHARINC(c, eptr) c = *eptr++; #define GETCHARINCTEST(c, eptr) c = *eptr++; #define GETCHARLEN(c, eptr, len) c = *eptr; -#define BACKCHAR(eptr) +/* #define BACKCHAR(eptr) */ #else /* SUPPORT_UTF8 */ @@ -472,9 +465,10 @@ if there are extra bytes. This is called when we know we are in UTF-8 mode. */ } /* If the pointer is not at the start of a character, move it back until -it is. Called only in UTF-8 mode. */ +it is. This is called only in UTF-8 mode - we don't put a test within the macro +because almost all calls are already within a block of UTF-8 only code. */ -#define BACKCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr--; +#define BACKCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr-- #endif @@ -491,17 +485,16 @@ Standard C system should have one. */ #define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL) -/* Private options flags start at the most significant end of the four bytes. -The public options defined in pcre.h start at the least significant end. Make -sure they don't overlap! The bits are getting a bit scarce now -- when we run -out, there is a dummy word in the structure that could be used for the private -bits. */ +/* Private flags containing information about the compiled regex. They used to +live at the top end of the options word, but that got almost full, so now they +are in a 16-bit flags word. */ -#define PCRE_NOPARTIAL 0x80000000 /* can't use partial with this regex */ -#define PCRE_FIRSTSET 0x40000000 /* first_byte is set */ -#define PCRE_REQCHSET 0x20000000 /* req_byte is set */ -#define PCRE_STARTLINE 0x10000000 /* start after \n for multiline */ -#define PCRE_JCHANGED 0x08000000 /* j option changes within regex */ +#define PCRE_NOPARTIAL 0x0001 /* can't use partial with this regex */ +#define PCRE_FIRSTSET 0x0002 /* first_byte is set */ +#define PCRE_REQCHSET 0x0004 /* req_byte is set */ +#define PCRE_STARTLINE 0x0008 /* start after \n for multiline */ +#define PCRE_JCHANGED 0x0010 /* j option used in regex */ +#define PCRE_HASCRORLF 0x0020 /* explicit \r or \n in pattern */ /* Options for the "extra" block produced by pcre_study(). */ @@ -517,15 +510,16 @@ time, run time, or study time, respectively. */ (PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \ PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY|PCRE_UTF8| \ PCRE_NO_AUTO_CAPTURE|PCRE_NO_UTF8_CHECK|PCRE_AUTO_CALLOUT|PCRE_FIRSTLINE| \ - PCRE_DUPNAMES|PCRE_NEWLINE_BITS) + PCRE_DUPNAMES|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE) #define PUBLIC_EXEC_OPTIONS \ (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \ - PCRE_PARTIAL|PCRE_NEWLINE_BITS) + PCRE_PARTIAL|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE) #define PUBLIC_DFA_EXEC_OPTIONS \ (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \ - PCRE_PARTIAL|PCRE_DFA_SHORTEST|PCRE_DFA_RESTART|PCRE_NEWLINE_BITS) + PCRE_PARTIAL|PCRE_DFA_SHORTEST|PCRE_DFA_RESTART|PCRE_NEWLINE_BITS| \ + PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE) #define PUBLIC_STUDY_OPTIONS 0 /* None defined */ @@ -618,14 +612,9 @@ enum { ESC_A = 1, ESC_G, ESC_K, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, ESC_V, ESC_v, ESC_X, ESC_Z, ESC_z, ESC_E, ESC_Q, ESC_k, ESC_REF }; -/* Opcode table: OP_BRA must be last, as all values >= it are used for brackets -that extract substrings. Starting from 1 (i.e. after OP_END), the values up to +/* Opcode table: Starting from 1 (i.e. after OP_END), the values up to OP_EOD must correspond in order to the list of escapes immediately above. -To keep stored, compiled patterns compatible, new opcodes should be added -immediately before OP_BRA, where (since release 7.0) a gap is left for this -purpose. - *** NOTE NOTE NOTE *** Whenever this list is updated, the two macro definitions that follow must also be updated to match. There is also a table called "coptable" in pcre_dfa_exec.c that must be updated. */ @@ -752,7 +741,7 @@ enum { as there's a test for >= ONCE for a subpattern that isn't an assertion. */ OP_ONCE, /* 92 Atomic group */ - OP_BRA, /* 83 Start of non-capturing bracket */ + OP_BRA, /* 93 Start of non-capturing bracket */ OP_CBRA, /* 94 Start of capturing bracket */ OP_COND, /* 95 Conditional group */ @@ -768,7 +757,19 @@ enum { OP_DEF, /* 101 The DEFINE condition */ OP_BRAZERO, /* 102 These two must remain together and in this */ - OP_BRAMINZERO /* 103 order. */ + OP_BRAMINZERO, /* 103 order. */ + + /* These are backtracking control verbs */ + + OP_PRUNE, /* 104 */ + OP_SKIP, /* 105 */ + OP_THEN, /* 106 */ + OP_COMMIT, /* 107 */ + + /* These are forced failure and success verbs */ + + OP_FAIL, /* 108 */ + OP_ACCEPT /* 109 */ }; @@ -791,8 +792,9 @@ for debugging. The macro is referenced only in pcre_printint.c. */ "class", "nclass", "xclass", "Ref", "Recurse", "Callout", \ "Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not", \ "AssertB", "AssertB not", "Reverse", \ - "Once", "Bra 0", "Bra", "Cond", "SBra 0", "SBra", "SCond", \ - "Cond ref", "Cond rec", "Cond def", "Brazero", "Braminzero" + "Once", "Bra", "CBra", "Cond", "SBra", "SCBra", "SCond", \ + "Cond ref", "Cond rec", "Cond def", "Brazero", "Braminzero", \ + "*PRUNE", "*SKIP", "*THEN", "*COMMIT", "*FAIL", "*ACCEPT" /* This macro defines the length of fixed length operations in the compiled @@ -856,6 +858,8 @@ in UTF-8 mode. The code that uses this table must know about such things. */ 3, /* RREF */ \ 1, /* DEF */ \ 1, 1, /* BRAZERO, BRAMINZERO */ \ + 1, 1, 1, 1, /* PRUNE, SKIP, THEN, COMMIT, */ \ + 1, 1 /* FAIL, ACCEPT */ /* A magic value for OP_RREF to indicate the "any recursion" condition. */ @@ -870,7 +874,8 @@ enum { ERR0, ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, ERR20, ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29, ERR30, ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39, ERR40, ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49, - ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58 }; + ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59, + ERR60, ERR61 }; /* The real format of the start of the pcre block; the index of names and the code vector run on as long as necessary after the end. We store an explicit @@ -892,9 +897,9 @@ NOTE NOTE NOTE: typedef struct real_pcre { pcre_uint32 magic_number; pcre_uint32 size; /* Total that was malloced */ - pcre_uint32 options; - pcre_uint32 dummy1; /* For future use, maybe */ - + pcre_uint32 options; /* Public options */ + pcre_uint16 flags; /* Private flags */ + pcre_uint16 dummy1; /* For future use */ pcre_uint16 top_bracket; pcre_uint16 top_backref; pcre_uint16 first_byte; @@ -937,8 +942,9 @@ typedef struct compile_data { int top_backref; /* Maximum back reference */ unsigned int backref_map; /* Bitmap of low back refs */ int external_options; /* External (initial) options */ + int external_flags; /* External flag bits to be set */ int req_varyopt; /* "After variable item" flag for reqbyte */ - BOOL nopartial; /* Set TRUE if partial won't work */ + BOOL had_accept; /* (*ACCEPT) encountered */ int nltype; /* Newline type */ int nllen; /* Newline string length */ uschar nl[4]; /* Newline string when fixed length */ @@ -997,6 +1003,7 @@ typedef struct match_data { BOOL notempty; /* Empty string match not wanted */ BOOL partial; /* PARTIAL flag */ BOOL hitend; /* Hit the end of the subject at some point */ + BOOL bsr_anycrlf; /* \R is just any CRLF, not full Unicode */ const uschar *start_code; /* For use when recursing */ USPTR start_subject; /* Start of the subject string */ USPTR end_subject; /* End of the subject string */ @@ -1061,10 +1068,12 @@ total length. */ #define tables_length (ctypes_offset + 256) /* Layout of the UCP type table that translates property names into types and -codes. */ +codes. Each entry used to point directly to a name, but to reduce the number of +relocations in shared libraries, it now has an offset into a single string +instead. */ typedef struct { - const char *name; + pcre_uint16 name_offset; pcre_uint16 type; pcre_uint16 value; } ucp_type_table; @@ -1082,6 +1091,7 @@ extern const uschar _pcre_utf8_table4[]; extern const int _pcre_utf8_table1_size; +extern const char _pcre_utt_names[]; extern const ucp_type_table _pcre_utt[]; extern const int _pcre_utt_size; diff --git a/libpcre/pcre_maketables.c b/libpcre/pcre_maketables.c index 9963e13fb..b21cf4c5b 100644 --- a/libpcre/pcre_maketables.c +++ b/libpcre/pcre_maketables.c @@ -45,7 +45,12 @@ compilation of dftables.c, in which case the macro DFTABLES is defined. */ #ifndef DFTABLES -#include "pcre_internal.h" +# ifdef WIN32 +# include "pcre_winconfig.h" +# else +# include "config.h" +# endif +# include "pcre_internal.h" #endif diff --git a/libpcre/pcre_newline.c b/libpcre/pcre_newline.c index ae66c730f..5e6520e89 100644 --- a/libpcre/pcre_newline.c +++ b/libpcre/pcre_newline.c @@ -47,6 +47,12 @@ and NLTYPE_ANY. The full list of Unicode newline characters is taken from http://unicode.org/unicode/reports/tr18/. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" @@ -124,12 +130,16 @@ _pcre_was_newline(const uschar *ptr, int type, const uschar *startptr, { int c; ptr--; +#ifdef SUPPORT_UTF8 if (utf8) { BACKCHAR(ptr); GETCHAR(c, ptr); } else c = *ptr; +#else /* no UTF-8 support */ +c = *ptr; +#endif /* SUPPORT_UTF8 */ if (type == NLTYPE_ANYCRLF) switch(c) { diff --git a/libpcre/pcre_ord2utf8.c b/libpcre/pcre_ord2utf8.c index a72761285..c8742f165 100644 --- a/libpcre/pcre_ord2utf8.c +++ b/libpcre/pcre_ord2utf8.c @@ -41,6 +41,11 @@ POSSIBILITY OF SUCH DAMAGE. /* This file contains a private PCRE function that converts an ordinal character value into a UTF8 string. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif #include "pcre_internal.h" diff --git a/libpcre/pcre_refcount.c b/libpcre/pcre_refcount.c index 8339019db..104bffd36 100644 --- a/libpcre/pcre_refcount.c +++ b/libpcre/pcre_refcount.c @@ -43,6 +43,13 @@ auxiliary function that can be used to maintain a reference count in a compiled pattern data block. This might be helpful in applications where the block is shared by different users. */ + +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" diff --git a/libpcre/pcre_study.c b/libpcre/pcre_study.c index 3cf5b5954..2e3248ad8 100644 --- a/libpcre/pcre_study.c +++ b/libpcre/pcre_study.c @@ -42,6 +42,12 @@ POSSIBILITY OF SUCH DAMAGE. supporting functions. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" @@ -523,7 +529,8 @@ code = (uschar *)re + re->name_table_offset + a multiline pattern that matches only at "line starts", no further processing at present. */ -if ((re->options & (PCRE_ANCHORED|PCRE_FIRSTSET|PCRE_STARTLINE)) != 0) +if ((re->options & PCRE_ANCHORED) != 0 || + (re->flags & (PCRE_FIRSTSET|PCRE_STARTLINE)) != 0) return NULL; /* Set the character tables in the block that is passed around */ diff --git a/libpcre/pcre_tables.c b/libpcre/pcre_tables.c index 3e36c931a..2a719f3df 100644 --- a/libpcre/pcre_tables.c +++ b/libpcre/pcre_tables.c @@ -44,6 +44,12 @@ uses macros to change their names from _pcre_xxx to xxxx, thereby avoiding name clashes with the library. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" @@ -83,115 +89,228 @@ const uschar _pcre_utf8_table4[] = { 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 }; -/* This table translates Unicode property names into type and code values. It -is searched by binary chop, so must be in collating sequence of name. */ +/* The pcre_utt[] table below translates Unicode property names into type and +code values. It is searched by binary chop, so must be in collating sequence of +name. Originally, the table contained pointers to the name strings in the first +field of each entry. However, that leads to a large number of relocations when +a shared library is dynamically loaded. A significant reduction is made by +putting all the names into a single, large string and then using offsets in the +table itself. Maintenance is more error-prone, but frequent changes to this +data is unlikely. */ + +const char _pcre_utt_names[] = + "Any\0" + "Arabic\0" + "Armenian\0" + "Balinese\0" + "Bengali\0" + "Bopomofo\0" + "Braille\0" + "Buginese\0" + "Buhid\0" + "C\0" + "Canadian_Aboriginal\0" + "Cc\0" + "Cf\0" + "Cherokee\0" + "Cn\0" + "Co\0" + "Common\0" + "Coptic\0" + "Cs\0" + "Cuneiform\0" + "Cypriot\0" + "Cyrillic\0" + "Deseret\0" + "Devanagari\0" + "Ethiopic\0" + "Georgian\0" + "Glagolitic\0" + "Gothic\0" + "Greek\0" + "Gujarati\0" + "Gurmukhi\0" + "Han\0" + "Hangul\0" + "Hanunoo\0" + "Hebrew\0" + "Hiragana\0" + "Inherited\0" + "Kannada\0" + "Katakana\0" + "Kharoshthi\0" + "Khmer\0" + "L\0" + "L&\0" + "Lao\0" + "Latin\0" + "Limbu\0" + "Linear_B\0" + "Ll\0" + "Lm\0" + "Lo\0" + "Lt\0" + "Lu\0" + "M\0" + "Malayalam\0" + "Mc\0" + "Me\0" + "Mn\0" + "Mongolian\0" + "Myanmar\0" + "N\0" + "Nd\0" + "New_Tai_Lue\0" + "Nko\0" + "Nl\0" + "No\0" + "Ogham\0" + "Old_Italic\0" + "Old_Persian\0" + "Oriya\0" + "Osmanya\0" + "P\0" + "Pc\0" + "Pd\0" + "Pe\0" + "Pf\0" + "Phags_Pa\0" + "Phoenician\0" + "Pi\0" + "Po\0" + "Ps\0" + "Runic\0" + "S\0" + "Sc\0" + "Shavian\0" + "Sinhala\0" + "Sk\0" + "Sm\0" + "So\0" + "Syloti_Nagri\0" + "Syriac\0" + "Tagalog\0" + "Tagbanwa\0" + "Tai_Le\0" + "Tamil\0" + "Telugu\0" + "Thaana\0" + "Thai\0" + "Tibetan\0" + "Tifinagh\0" + "Ugaritic\0" + "Yi\0" + "Z\0" + "Zl\0" + "Zp\0" + "Zs\0"; const ucp_type_table _pcre_utt[] = { - { "Any", PT_ANY, 0 }, - { "Arabic", PT_SC, ucp_Arabic }, - { "Armenian", PT_SC, ucp_Armenian }, - { "Balinese", PT_SC, ucp_Balinese }, - { "Bengali", PT_SC, ucp_Bengali }, - { "Bopomofo", PT_SC, ucp_Bopomofo }, - { "Braille", PT_SC, ucp_Braille }, - { "Buginese", PT_SC, ucp_Buginese }, - { "Buhid", PT_SC, ucp_Buhid }, - { "C", PT_GC, ucp_C }, - { "Canadian_Aboriginal", PT_SC, ucp_Canadian_Aboriginal }, - { "Cc", PT_PC, ucp_Cc }, - { "Cf", PT_PC, ucp_Cf }, - { "Cherokee", PT_SC, ucp_Cherokee }, - { "Cn", PT_PC, ucp_Cn }, - { "Co", PT_PC, ucp_Co }, - { "Common", PT_SC, ucp_Common }, - { "Coptic", PT_SC, ucp_Coptic }, - { "Cs", PT_PC, ucp_Cs }, - { "Cuneiform", PT_SC, ucp_Cuneiform }, - { "Cypriot", PT_SC, ucp_Cypriot }, - { "Cyrillic", PT_SC, ucp_Cyrillic }, - { "Deseret", PT_SC, ucp_Deseret }, - { "Devanagari", PT_SC, ucp_Devanagari }, - { "Ethiopic", PT_SC, ucp_Ethiopic }, - { "Georgian", PT_SC, ucp_Georgian }, - { "Glagolitic", PT_SC, ucp_Glagolitic }, - { "Gothic", PT_SC, ucp_Gothic }, - { "Greek", PT_SC, ucp_Greek }, - { "Gujarati", PT_SC, ucp_Gujarati }, - { "Gurmukhi", PT_SC, ucp_Gurmukhi }, - { "Han", PT_SC, ucp_Han }, - { "Hangul", PT_SC, ucp_Hangul }, - { "Hanunoo", PT_SC, ucp_Hanunoo }, - { "Hebrew", PT_SC, ucp_Hebrew }, - { "Hiragana", PT_SC, ucp_Hiragana }, - { "Inherited", PT_SC, ucp_Inherited }, - { "Kannada", PT_SC, ucp_Kannada }, - { "Katakana", PT_SC, ucp_Katakana }, - { "Kharoshthi", PT_SC, ucp_Kharoshthi }, - { "Khmer", PT_SC, ucp_Khmer }, - { "L", PT_GC, ucp_L }, - { "L&", PT_LAMP, 0 }, - { "Lao", PT_SC, ucp_Lao }, - { "Latin", PT_SC, ucp_Latin }, - { "Limbu", PT_SC, ucp_Limbu }, - { "Linear_B", PT_SC, ucp_Linear_B }, - { "Ll", PT_PC, ucp_Ll }, - { "Lm", PT_PC, ucp_Lm }, - { "Lo", PT_PC, ucp_Lo }, - { "Lt", PT_PC, ucp_Lt }, - { "Lu", PT_PC, ucp_Lu }, - { "M", PT_GC, ucp_M }, - { "Malayalam", PT_SC, ucp_Malayalam }, - { "Mc", PT_PC, ucp_Mc }, - { "Me", PT_PC, ucp_Me }, - { "Mn", PT_PC, ucp_Mn }, - { "Mongolian", PT_SC, ucp_Mongolian }, - { "Myanmar", PT_SC, ucp_Myanmar }, - { "N", PT_GC, ucp_N }, - { "Nd", PT_PC, ucp_Nd }, - { "New_Tai_Lue", PT_SC, ucp_New_Tai_Lue }, - { "Nko", PT_SC, ucp_Nko }, - { "Nl", PT_PC, ucp_Nl }, - { "No", PT_PC, ucp_No }, - { "Ogham", PT_SC, ucp_Ogham }, - { "Old_Italic", PT_SC, ucp_Old_Italic }, - { "Old_Persian", PT_SC, ucp_Old_Persian }, - { "Oriya", PT_SC, ucp_Oriya }, - { "Osmanya", PT_SC, ucp_Osmanya }, - { "P", PT_GC, ucp_P }, - { "Pc", PT_PC, ucp_Pc }, - { "Pd", PT_PC, ucp_Pd }, - { "Pe", PT_PC, ucp_Pe }, - { "Pf", PT_PC, ucp_Pf }, - { "Phags_Pa", PT_SC, ucp_Phags_Pa }, - { "Phoenician", PT_SC, ucp_Phoenician }, - { "Pi", PT_PC, ucp_Pi }, - { "Po", PT_PC, ucp_Po }, - { "Ps", PT_PC, ucp_Ps }, - { "Runic", PT_SC, ucp_Runic }, - { "S", PT_GC, ucp_S }, - { "Sc", PT_PC, ucp_Sc }, - { "Shavian", PT_SC, ucp_Shavian }, - { "Sinhala", PT_SC, ucp_Sinhala }, - { "Sk", PT_PC, ucp_Sk }, - { "Sm", PT_PC, ucp_Sm }, - { "So", PT_PC, ucp_So }, - { "Syloti_Nagri", PT_SC, ucp_Syloti_Nagri }, - { "Syriac", PT_SC, ucp_Syriac }, - { "Tagalog", PT_SC, ucp_Tagalog }, - { "Tagbanwa", PT_SC, ucp_Tagbanwa }, - { "Tai_Le", PT_SC, ucp_Tai_Le }, - { "Tamil", PT_SC, ucp_Tamil }, - { "Telugu", PT_SC, ucp_Telugu }, - { "Thaana", PT_SC, ucp_Thaana }, - { "Thai", PT_SC, ucp_Thai }, - { "Tibetan", PT_SC, ucp_Tibetan }, - { "Tifinagh", PT_SC, ucp_Tifinagh }, - { "Ugaritic", PT_SC, ucp_Ugaritic }, - { "Yi", PT_SC, ucp_Yi }, - { "Z", PT_GC, ucp_Z }, - { "Zl", PT_PC, ucp_Zl }, - { "Zp", PT_PC, ucp_Zp }, - { "Zs", PT_PC, ucp_Zs } + { 0, PT_ANY, 0 }, + { 4, PT_SC, ucp_Arabic }, + { 11, PT_SC, ucp_Armenian }, + { 20, PT_SC, ucp_Balinese }, + { 29, PT_SC, ucp_Bengali }, + { 37, PT_SC, ucp_Bopomofo }, + { 46, PT_SC, ucp_Braille }, + { 54, PT_SC, ucp_Buginese }, + { 63, PT_SC, ucp_Buhid }, + { 69, PT_GC, ucp_C }, + { 71, PT_SC, ucp_Canadian_Aboriginal }, + { 91, PT_PC, ucp_Cc }, + { 94, PT_PC, ucp_Cf }, + { 97, PT_SC, ucp_Cherokee }, + { 106, PT_PC, ucp_Cn }, + { 109, PT_PC, ucp_Co }, + { 112, PT_SC, ucp_Common }, + { 119, PT_SC, ucp_Coptic }, + { 126, PT_PC, ucp_Cs }, + { 129, PT_SC, ucp_Cuneiform }, + { 139, PT_SC, ucp_Cypriot }, + { 147, PT_SC, ucp_Cyrillic }, + { 156, PT_SC, ucp_Deseret }, + { 164, PT_SC, ucp_Devanagari }, + { 175, PT_SC, ucp_Ethiopic }, + { 184, PT_SC, ucp_Georgian }, + { 193, PT_SC, ucp_Glagolitic }, + { 204, PT_SC, ucp_Gothic }, + { 211, PT_SC, ucp_Greek }, + { 217, PT_SC, ucp_Gujarati }, + { 226, PT_SC, ucp_Gurmukhi }, + { 235, PT_SC, ucp_Han }, + { 239, PT_SC, ucp_Hangul }, + { 246, PT_SC, ucp_Hanunoo }, + { 254, PT_SC, ucp_Hebrew }, + { 261, PT_SC, ucp_Hiragana }, + { 270, PT_SC, ucp_Inherited }, + { 280, PT_SC, ucp_Kannada }, + { 288, PT_SC, ucp_Katakana }, + { 297, PT_SC, ucp_Kharoshthi }, + { 308, PT_SC, ucp_Khmer }, + { 314, PT_GC, ucp_L }, + { 316, PT_LAMP, 0 }, + { 319, PT_SC, ucp_Lao }, + { 323, PT_SC, ucp_Latin }, + { 329, PT_SC, ucp_Limbu }, + { 335, PT_SC, ucp_Linear_B }, + { 344, PT_PC, ucp_Ll }, + { 347, PT_PC, ucp_Lm }, + { 350, PT_PC, ucp_Lo }, + { 353, PT_PC, ucp_Lt }, + { 356, PT_PC, ucp_Lu }, + { 359, PT_GC, ucp_M }, + { 361, PT_SC, ucp_Malayalam }, + { 371, PT_PC, ucp_Mc }, + { 374, PT_PC, ucp_Me }, + { 377, PT_PC, ucp_Mn }, + { 380, PT_SC, ucp_Mongolian }, + { 390, PT_SC, ucp_Myanmar }, + { 398, PT_GC, ucp_N }, + { 400, PT_PC, ucp_Nd }, + { 403, PT_SC, ucp_New_Tai_Lue }, + { 415, PT_SC, ucp_Nko }, + { 419, PT_PC, ucp_Nl }, + { 422, PT_PC, ucp_No }, + { 425, PT_SC, ucp_Ogham }, + { 431, PT_SC, ucp_Old_Italic }, + { 442, PT_SC, ucp_Old_Persian }, + { 454, PT_SC, ucp_Oriya }, + { 460, PT_SC, ucp_Osmanya }, + { 468, PT_GC, ucp_P }, + { 470, PT_PC, ucp_Pc }, + { 473, PT_PC, ucp_Pd }, + { 476, PT_PC, ucp_Pe }, + { 479, PT_PC, ucp_Pf }, + { 482, PT_SC, ucp_Phags_Pa }, + { 491, PT_SC, ucp_Phoenician }, + { 502, PT_PC, ucp_Pi }, + { 505, PT_PC, ucp_Po }, + { 508, PT_PC, ucp_Ps }, + { 511, PT_SC, ucp_Runic }, + { 517, PT_GC, ucp_S }, + { 519, PT_PC, ucp_Sc }, + { 522, PT_SC, ucp_Shavian }, + { 530, PT_SC, ucp_Sinhala }, + { 538, PT_PC, ucp_Sk }, + { 541, PT_PC, ucp_Sm }, + { 544, PT_PC, ucp_So }, + { 547, PT_SC, ucp_Syloti_Nagri }, + { 560, PT_SC, ucp_Syriac }, + { 567, PT_SC, ucp_Tagalog }, + { 575, PT_SC, ucp_Tagbanwa }, + { 584, PT_SC, ucp_Tai_Le }, + { 591, PT_SC, ucp_Tamil }, + { 597, PT_SC, ucp_Telugu }, + { 604, PT_SC, ucp_Thaana }, + { 611, PT_SC, ucp_Thai }, + { 616, PT_SC, ucp_Tibetan }, + { 624, PT_SC, ucp_Tifinagh }, + { 633, PT_SC, ucp_Ugaritic }, + { 642, PT_SC, ucp_Yi }, + { 645, PT_GC, ucp_Z }, + { 647, PT_PC, ucp_Zl }, + { 650, PT_PC, ucp_Zp }, + { 653, PT_PC, ucp_Zs } }; const int _pcre_utt_size = sizeof(_pcre_utt)/sizeof(ucp_type_table); diff --git a/libpcre/pcre_try_flipped.c b/libpcre/pcre_try_flipped.c index cd45968a4..deae741e9 100644 --- a/libpcre/pcre_try_flipped.c +++ b/libpcre/pcre_try_flipped.c @@ -43,6 +43,12 @@ see if it was compiled with the opposite endianness. If so, it uses an auxiliary local function to flip the appropriate bytes. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" @@ -104,6 +110,7 @@ if (byteflip(re->magic_number, sizeof(re->magic_number)) != MAGIC_NUMBER) *internal_re = *re; /* To copy other fields */ internal_re->size = byteflip(re->size, sizeof(re->size)); internal_re->options = byteflip(re->options, sizeof(re->options)); +internal_re->flags = (pcre_uint16)byteflip(re->flags, sizeof(re->flags)); internal_re->top_bracket = (pcre_uint16)byteflip(re->top_bracket, sizeof(re->top_bracket)); internal_re->top_backref = diff --git a/libpcre/pcre_ucp_searchfuncs.c b/libpcre/pcre_ucp_searchfuncs.c index 5ecba6b1f..3ad64f052 100644 --- a/libpcre/pcre_ucp_searchfuncs.c +++ b/libpcre/pcre_ucp_searchfuncs.c @@ -41,6 +41,12 @@ POSSIBILITY OF SUCH DAMAGE. /* This module contains code for searching the table of Unicode character properties. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" #include "ucp.h" /* Category definitions */ diff --git a/libpcre/pcre_valid_utf8.c b/libpcre/pcre_valid_utf8.c index 9a35a202e..877c119c0 100644 --- a/libpcre/pcre_valid_utf8.c +++ b/libpcre/pcre_valid_utf8.c @@ -42,6 +42,12 @@ POSSIBILITY OF SUCH DAMAGE. strings. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" @@ -55,6 +61,13 @@ that subsequent code can assume it is dealing with a valid string. The check can be turned off for maximum performance, but the consequences of supplying an invalid string are then undefined. +Originally, this function checked according to RFC 2279, allowing for values in +the range 0 to 0x7fffffff, up to 6 bytes long, but ensuring that they were in +the canonical format. Once somebody had pointed out RFC 3629 to me (it +obsoletes 2279), additional restrictions were applies. The values are now +limited to be between 0 and 0x0010ffff, no more than 4 bytes long, and the +subrange 0xd000 to 0xdfff is excluded. + Arguments: string points to the string length length of string, or -1 if the string is zero-terminated @@ -81,31 +94,48 @@ for (p = string; length-- > 0; p++) register int c = *p; if (c < 128) continue; if (c < 0xc0) return p - string; - ab = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ - if (length < ab) return p - string; + ab = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ + if (length < ab || ab > 3) return p - string; length -= ab; /* Check top bits in the second byte */ if ((*(++p) & 0xc0) != 0x80) return p - string; - /* Check for overlong sequences for each different length */ + /* Check for overlong sequences for each different length, and for the + excluded range 0xd000 to 0xdfff. */ + switch (ab) { - /* Check for xx00 000x */ + /* Check for xx00 000x (overlong sequence) */ + case 1: if ((c & 0x3e) == 0) return p - string; continue; /* We know there aren't any more bytes to check */ - /* Check for 1110 0000, xx0x xxxx */ + /* Check for 1110 0000, xx0x xxxx (overlong sequence) or + 1110 1101, 1010 xxxx (0xd000 - 0xdfff) */ + case 2: - if (c == 0xe0 && (*p & 0x20) == 0) return p - string; + if ((c == 0xe0 && (*p & 0x20) == 0) || + (c == 0xed && *p >= 0xa0)) + return p - string; break; - /* Check for 1111 0000, xx00 xxxx */ + /* Check for 1111 0000, xx00 xxxx (overlong sequence) or + greater than 0x0010ffff (f4 8f bf bf) */ + case 3: - if (c == 0xf0 && (*p & 0x30) == 0) return p - string; + if ((c == 0xf0 && (*p & 0x30) == 0) || + (c > 0xf4 ) || + (c == 0xf4 && *p > 0x8f)) + return p - string; break; +#if 0 + /* These cases can no longer occur, as we restrict to a maximum of four + bytes nowadays. Leave the code here in case we ever want to add an option + for longer sequences. */ + /* Check for 1111 1000, xx00 0xxx */ case 4: if (c == 0xf8 && (*p & 0x38) == 0) return p - string; @@ -116,6 +146,8 @@ for (p = string; length-- > 0; p++) if (c == 0xfe || c == 0xff || (c == 0xfc && (*p & 0x3c) == 0)) return p - string; break; +#endif + } /* Check for valid bytes after the 2nd, if any; all must start 10 */ diff --git a/libpcre/pcre_version.c b/libpcre/pcre_version.c index 1a9ecb2c5..307c5ab94 100644 --- a/libpcre/pcre_version.c +++ b/libpcre/pcre_version.c @@ -42,6 +42,12 @@ POSSIBILITY OF SUCH DAMAGE. string that identifies the PCRE version that is in use. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" diff --git a/libpcre/pcre_xclass.c b/libpcre/pcre_xclass.c index 0b333515f..f17ca67e5 100644 --- a/libpcre/pcre_xclass.c +++ b/libpcre/pcre_xclass.c @@ -43,6 +43,12 @@ class (one that contains characters whose values are > 255). It is used by both pcre_exec() and pcre_def_exec(). */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + #include "pcre_internal.h" diff --git a/libpcre/pcreposix.c b/libpcre/pcreposix.c index 8582fba09..40c9b0efc 100644 --- a/libpcre/pcreposix.c +++ b/libpcre/pcreposix.c @@ -42,10 +42,26 @@ POSSIBILITY OF SUCH DAMAGE. functions. */ +#ifdef WIN32 +#include "pcre_winconfig.h" +#else +#include "config.h" +#endif + + +/* Ensure that the PCREPOSIX_EXP_xxx macros are set appropriately for +compiling these functions. This must come before including pcreposix.h, where +they are set for an application (using these functions) if they have not +previously been set. */ + +#if defined(_WIN32) && !defined(PCRE_STATIC) +# define PCREPOSIX_EXP_DECL extern __declspec(dllexport) +# define PCREPOSIX_EXP_DEFN __declspec(dllexport) +#endif + +#include "pcre.h" #include "pcre_internal.h" #include "pcreposix.h" -#include "stdlib.h" - /* Table to translate PCRE compile time error codes into POSIX error codes. */ @@ -109,7 +125,8 @@ static const int eint[] = { REG_BADPAT, /* repeating a DEFINE group is not allowed */ REG_INVARG, /* inconsistent NEWLINE options */ REG_BADPAT, /* \g is not followed followed by an (optionally braced) non-zero number */ - REG_BADPAT /* (?+ or (?- must be followed by a non-zero number */ + REG_BADPAT, /* (?+ or (?- must be followed by a non-zero number */ + REG_BADPAT /* number is too big */ }; /* Table of texts corresponding to POSIX error codes */ diff --git a/libpcre/pcreposix.h b/libpcre/pcreposix.h index 1a7de125f..5f17925be 100644 --- a/libpcre/pcreposix.h +++ b/libpcre/pcreposix.h @@ -107,14 +107,13 @@ typedef struct { /* When an application links to a PCRE DLL in Windows, the symbols that are imported have to be identified as such. When building PCRE, the appropriate -export settings are needed. */ +export settings are needed, and are set in pcreposix.c before including this +file. */ /* -#ifdef _WIN32 -# ifndef PCREPOSIX_STATIC -# define PCREPOSIX_EXP_DECL extern __declspec(dllimport) -# define PCREPOSIX_EXP_DEFN __declspec(dllimport) -# endif +#if defined(_WIN32) && !defined(PCRE_STATIC) && !defined(PCREPOSIX_EXP_DECL) +# define PCREPOSIX_EXP_DECL extern __declspec(dllimport) +# define PCREPOSIX_EXP_DEFN __declspec(dllimport) #endif */