Updated embedded PCRE to version 7.4 to avoid 2 CVE issues:-
[exim.git] / src / src / pcre / pcre_newline.c
index 26cf0fe1fa4b90c2945fd630f591ba37c706f6c5..c71dbafbad7f590938d73521897fb63cf1e9e481 100644 (file)
@@ -1,4 +1,4 @@
-/* $Cambridge: exim/src/src/pcre/pcre_newline.c,v 1.1 2007/01/23 15:08:45 ph10 Exp $ */
+/* $Cambridge: exim/src/src/pcre/pcre_newline.c,v 1.3 2007/11/12 13:02:20 nm4 Exp $ */
 
 /*************************************************
 *      Perl-Compatible Regular Expressions       *
 
 /*************************************************
 *      Perl-Compatible Regular Expressions       *
@@ -8,7 +8,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2006 University of Cambridge
+           Copyright (c) 1997-2007 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -44,12 +44,15 @@ POSSIBILITY OF SUCH DAMAGE.
 one kind of newline is to be recognized. When a newline is found, its length is
 returned. In principle, we could implement several newline "types", each
 referring to a different set of newline characters. At present, PCRE supports
 one kind of newline is to be recognized. When a newline is found, its length is
 returned. In principle, we could implement several newline "types", each
 referring to a different set of newline characters. At present, PCRE supports
-only NLTYPE_FIXED, which gets handled without these functions, and NLTYPE_ALL,
-so for now the type isn't passed into the functions. It can easily be added
-later if required. The full list of Unicode newline characters is taken from
+only NLTYPE_FIXED, which gets handled without these functions, NLTYPE_ANYCRLF,
+and NLTYPE_ANY. The full list of Unicode newline characters is taken from
 http://unicode.org/unicode/reports/tr18/. */
 
 
 http://unicode.org/unicode/reports/tr18/. */
 
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "pcre_internal.h"
 
 
 #include "pcre_internal.h"
 
 
@@ -63,6 +66,7 @@ string that is being processed.
 
 Arguments:
   ptr          pointer to possible newline
 
 Arguments:
   ptr          pointer to possible newline
+  type         the newline type
   endptr       pointer to the end of the string
   lenptr       where to return the length
   utf8         TRUE if in utf8 mode
   endptr       pointer to the end of the string
   lenptr       where to return the length
   utf8         TRUE if in utf8 mode
@@ -71,12 +75,23 @@ Returns:       TRUE or FALSE
 */
 
 BOOL
 */
 
 BOOL
-_pcre_is_newline(const uschar *ptr, const uschar *endptr, int *lenptr,
-  BOOL utf8)
+_pcre_is_newline(const uschar *ptr, int type, const uschar *endptr,
+  int *lenptr, BOOL utf8)
 {
 int c;
 if (utf8) { GETCHAR(c, ptr); } else c = *ptr;
 {
 int c;
 if (utf8) { GETCHAR(c, ptr); } else c = *ptr;
-switch(c)
+
+if (type == NLTYPE_ANYCRLF) switch(c)
+  {
+  case 0x000a: *lenptr = 1; return TRUE;             /* LF */
+  case 0x000d: *lenptr = (ptr < endptr - 1 && ptr[1] == 0x0a)? 2 : 1;
+               return TRUE;                          /* CR */
+  default: return FALSE;
+  }
+
+/* NLTYPE_ANY */
+
+else switch(c)
   {
   case 0x000a:                                       /* LF */
   case 0x000b:                                       /* VT */
   {
   case 0x000a:                                       /* LF */
   case 0x000b:                                       /* VT */
@@ -101,6 +116,7 @@ the string that is being processed.
 
 Arguments:
   ptr          pointer to possible newline
 
 Arguments:
   ptr          pointer to possible newline
+  type         the newline type
   startptr     pointer to the start of the string
   lenptr       where to return the length
   utf8         TRUE if in utf8 mode
   startptr     pointer to the start of the string
   lenptr       where to return the length
   utf8         TRUE if in utf8 mode
@@ -109,18 +125,31 @@ Returns:       TRUE or FALSE
 */
 
 BOOL
 */
 
 BOOL
-_pcre_was_newline(const uschar *ptr, const uschar *startptr, int *lenptr,
-  BOOL utf8)
+_pcre_was_newline(const uschar *ptr, int type, const uschar *startptr,
+  int *lenptr, BOOL utf8)
 {
 int c;
 ptr--;
 {
 int c;
 ptr--;
+#ifdef SUPPORT_UTF8
 if (utf8)
   {
   BACKCHAR(ptr);
   GETCHAR(c, ptr);
   }
 else c = *ptr;
 if (utf8)
   {
   BACKCHAR(ptr);
   GETCHAR(c, ptr);
   }
 else c = *ptr;
-switch(c)
+#else   /* no UTF-8 support */
+c = *ptr;
+#endif  /* SUPPORT_UTF8 */
+
+if (type == NLTYPE_ANYCRLF) switch(c)
+  {
+  case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;
+               return TRUE;                         /* LF */
+  case 0x000d: *lenptr = 1; return TRUE;            /* CR */
+  default: return FALSE;
+  }
+
+else switch(c)
   {
   case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;
                return TRUE;                         /* LF */
   {
   case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;
                return TRUE;                         /* LF */