View | Details | Raw Unified | Return to bug 27550
Collapse All | Expand All

(-)orig/apache2/Makefile.in (-1 / +3 lines)
Lines 178-184 Link Here
178
	@cp -p $(srcdir)/modules/http/mod_core.h $(DESTDIR)$(includedir)
178
	@cp -p $(srcdir)/modules/http/mod_core.h $(DESTDIR)$(includedir)
179
	@cp -p $(srcdir)/modules/proxy/mod_proxy.h $(DESTDIR)$(includedir)
179
	@cp -p $(srcdir)/modules/proxy/mod_proxy.h $(DESTDIR)$(includedir)
180
	@cp -p $(srcdir)/modules/ssl/*.h $(DESTDIR)$(includedir)
180
	@cp -p $(srcdir)/modules/ssl/*.h $(DESTDIR)$(includedir)
181
	@cp -p $(srcdir)/srclib/pcre/pcre*.h $(DESTDIR)$(includedir)
181
	@if test "$(AP_EXTERN_PCRE)" != "0"; then \
182
		cp -p $(srcdir)/srclib/pcre/pcre*.h $(DESTDIR)$(includedir); \
183
	fi;
182
	@cp -p $(srcdir)/os/$(OS_DIR)/*.h $(DESTDIR)$(includedir)
184
	@cp -p $(srcdir)/os/$(OS_DIR)/*.h $(DESTDIR)$(includedir)
183
	@chmod 644 $(DESTDIR)$(includedir)/*.h
185
	@chmod 644 $(DESTDIR)$(includedir)/*.h
184
186
(-)orig/apache2/acinclude.m4 (+52 lines)
Lines 494-499 Link Here
494
])
494
])
495
495
496
dnl
496
dnl
497
dnl APACHE_CHECK_PCRE
498
dnl Apache includes it's own version of PCRE; however, if PCRE exists
499
dnl on the build system, we link against that instead of building
500
dnl Apache's own PCRE.
501
dnl
502
AC_DEFUN(APACHE_CHECK_PCRE, [
503
  AC_MSG_CHECKING(for external PCRE library)
504
  ap_pcre_base=""
505
  ap_test_pcre=1
506
  AP_EXTERN_PCRE=0
507
508
  AC_ARG_WITH([pcre], AS_HELP_STRING([--with-external-pcre],
509
      [use external libpcre (versus apache-supplied pcre)]), [
510
    if test "x$withval" = "xno"; then
511
      ap_test_pcre=0;
512
    elif test "x$withval" != "xyes" -a "x$withval" != "x"; then
513
      ap_pcre_base="$withval"
514
    fi
515
  ])
516
517
  if test "$ap_test_pcre" != "0"; then
518
    ap_pcre_conf="pcre-config"
519
    if test -f "$ap_pcre_base"; then
520
      ap_pcre_conf="$ap_pcre_base";
521
    elif test -f "$ap_pcre_base/pcre-config"; then
522
      ap_pcre_conf="$ap_pcre_base/pcre-config";
523
    elif test -f "$ap_pcre_base/bin/pcre-config"; then
524
      ap_pcre_conf="$ap_pcre_base/bin/pcre-config";
525
    fi
526
527
    ap_save_CFLAGS="$CFLAGS"
528
    ap_save_LIBS="$LIBS"
529
    CFLAGS="$CFLAGS `$ap_pcre_conf --cflags 2>/dev/null`"
530
    LIBS="$LIBS `$ap_pcre_conf --libs 2>/dev/null`"
531
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <pcre.h>]],
532
        [[char *foo = pcre_version();]])], [
533
      AP_EXTERN_PCRE=1
534
    ], [
535
      CFLAGS="$ap_save_CFLAGS"
536
      LIBS="$ap_save_LIBS"
537
    ])
538
  fi
539
540
  if test "$AP_EXTERN_PCRE" = "1"; then
541
    AC_MSG_RESULT(yes)
542
  else
543
    AC_MSG_RESULT(no)
544
  fi
545
  AC_SUBST(AP_EXTERN_PCRE)
546
])
547
548
dnl
497
dnl APACHE_EXPORT_ARGUMENTS
549
dnl APACHE_EXPORT_ARGUMENTS
498
dnl Export (via APACHE_SUBST) the various path-related variables that
550
dnl Export (via APACHE_SUBST) the various path-related variables that
499
dnl apache will use while generating scripts like autoconf and apxs and
551
dnl apache will use while generating scripts like autoconf and apxs and
(-)orig/apache2/configure.in (-7 / +8 lines)
Lines 114-123 Link Here
114
AC_PROG_CC
114
AC_PROG_CC
115
AC_PROG_CPP
115
AC_PROG_CPP
116
116
117
echo $ac_n "${nl}Configuring PCRE regular expression library ...${nl}"
117
APACHE_CHECK_PCRE
118
118
if test "$AP_EXTERN_PCRE" = "0"; then
119
APR_SUBDIR_CONFIG(srclib/pcre,
119
  echo $ac_n "${nl}Configuring PCRE regular expression library ...${nl}"
120
                  [--prefix=$prefix --exec-prefix=$exec_prefix --libdir=$libdir --includedir=$includedir --bindir=$bindir])
120
  APR_SUBDIR_CONFIG(srclib/pcre,
121
      [--prefix=$prefix --exec-prefix=$exec_prefix --libdir=$libdir --includedir=$includedir --bindir=$bindir])
122
  AP_BUILD_SRCLIB_DIRS="$AP_BUILD_SRCLIB_DIRS pcre"
123
  AP_CLEAN_SRCLIB_DIRS="pcre $AP_CLEAN_SRCLIB_DIRS"
124
fi
121
125
122
echo $ac_n "${nl}Configuring Apache httpd ...${nl}"
126
echo $ac_n "${nl}Configuring Apache httpd ...${nl}"
123
127
Lines 466-474 Link Here
466
APACHE_HELP_STRING(--with-suexec-umask,umask for suexec'd process),[
470
APACHE_HELP_STRING(--with-suexec-umask,umask for suexec'd process),[
467
  AC_DEFINE_UNQUOTED(AP_SUEXEC_UMASK, 0$withval, [umask for suexec'd process] ) ] )
471
  AC_DEFINE_UNQUOTED(AP_SUEXEC_UMASK, 0$withval, [umask for suexec'd process] ) ] )
468
472
469
dnl AP_LIBS specifies the actual libraries. note we have some required libs.
470
AP_LIBS="$abs_builddir/srclib/pcre/libpcre.la $AP_LIBS"
471
472
dnl APR should go after the other libs, so the right symbols can be picked up
473
dnl APR should go after the other libs, so the right symbols can be picked up
473
AP_LIBS="$AP_LIBS `$apu_config --link-libtool --libs` `$apr_config --link-libtool --libs`"
474
AP_LIBS="$AP_LIBS `$apu_config --link-libtool --libs` `$apr_config --link-libtool --libs`"
474
APACHE_SUBST(AP_LIBS)
475
APACHE_SUBST(AP_LIBS)
(-)orig/apache2/server/Makefile.in (-1 / +1 lines)
Lines 9-15 Link Here
9
LTLIBRARY_NAME    = libmain.la
9
LTLIBRARY_NAME    = libmain.la
10
LTLIBRARY_SOURCES = \
10
LTLIBRARY_SOURCES = \
11
    test_char.h \
11
    test_char.h \
12
	config.c log.c main.c vhost.c util.c \
12
	config.c log.c main.c vhost.c util.c util_pcre.c \
13
	util_script.c util_md5.c util_cfgtree.c util_ebcdic.c util_time.c \
13
	util_script.c util_md5.c util_cfgtree.c util_ebcdic.c util_time.c \
14
	rfc1413.c connection.c listen.c \
14
	rfc1413.c connection.c listen.c \
15
	mpm_common.c util_charset.c util_debug.c util_xml.c \
15
	mpm_common.c util_charset.c util_debug.c util_xml.c \
(-)orig/apache2/server/util.c (-22 / +3 lines)
Lines 298-304 Link Here
298
298
299
static apr_status_t regex_cleanup(void *preg)
299
static apr_status_t regex_cleanup(void *preg)
300
{
300
{
301
    regfree((regex_t *) preg);
301
    ap_regfree((regex_t *) preg);
302
    return APR_SUCCESS;
302
    return APR_SUCCESS;
303
}
303
}
304
304
Lines 307-313 Link Here
307
{
307
{
308
    regex_t *preg = apr_palloc(p, sizeof(regex_t));
308
    regex_t *preg = apr_palloc(p, sizeof(regex_t));
309
309
310
    if (regcomp(preg, pattern, cflags)) {
310
    if (ap_regcomp(preg, pattern, cflags)) {
311
        return NULL;
311
        return NULL;
312
    }
312
    }
313
313
Lines 319-325 Link Here
319
319
320
AP_DECLARE(void) ap_pregfree(apr_pool_t *p, regex_t * reg)
320
AP_DECLARE(void) ap_pregfree(apr_pool_t *p, regex_t * reg)
321
{
321
{
322
    regfree(reg);
322
    ap_regfree(reg);
323
    apr_pool_cleanup_kill(p, (void *) reg, regex_cleanup);
323
    apr_pool_cleanup_kill(p, (void *) reg, regex_cleanup);
324
}
324
}
325
325
Lines 386-410 Link Here
386
    return bigstring;
386
    return bigstring;
387
}
387
}
388
388
389
/* 
390
 * Apache stub function for the regex libraries regexec() to make sure the
391
 * whole regex(3) API is available through the Apache (exported) namespace.
392
 * This is especially important for the DSO situations of modules.
393
 * DO NOT MAKE A MACRO OUT OF THIS FUNCTION!
394
 */
395
AP_DECLARE(int) ap_regexec(regex_t *preg, const char *string,
396
                           size_t nmatch, regmatch_t pmatch[], int eflags)
397
{
398
    return regexec(preg, string, nmatch, pmatch, eflags);
399
}
400
401
AP_DECLARE(size_t) ap_regerror(int errcode, const regex_t *preg, char *errbuf,
402
                               size_t errbuf_size)
403
{
404
    return regerror(errcode, preg, errbuf, errbuf_size);
405
}
406
407
408
/* This function substitutes for $0-$9, filling in regular expression
389
/* This function substitutes for $0-$9, filling in regular expression
409
 * submatches. Pass it the same nmatch and pmatch arguments that you
390
 * submatches. Pass it the same nmatch and pmatch arguments that you
410
 * passed ap_regexec(). pmatch should not be greater than the maximum number
391
 * passed ap_regexec(). pmatch should not be greater than the maximum number
(-)orig/apache2/server/util_pcre.c (+254 lines)
Line 0 Link Here
1
/*************************************************
2
*      Perl-Compatible Regular Expressions       *
3
*************************************************/
4
5
/*
6
This is a library of functions to support regular expressions whose syntax
7
and semantics are as close as possible to those of the Perl 5 language. See
8
the file Tech.Notes for some information on the internals.
9
10
This module is a wrapper that provides a POSIX API to the underlying PCRE
11
functions.
12
13
Written by: Philip Hazel <ph10@cam.ac.uk>
14
15
           Copyright (c) 1997-2003 University of Cambridge
16
	   Copyright (C) 2004  Andres Salomon <dilinger@voxel.net>
17
18
-----------------------------------------------------------------------------
19
Permission is granted to anyone to use this software for any purpose on any
20
computer system, and to redistribute it freely, subject to the following
21
restrictions:
22
23
1. This software is distributed in the hope that it will be useful,
24
   but WITHOUT ANY WARRANTY; without even the implied warranty of
25
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26
27
2. The origin of this software must not be misrepresented, either by
28
   explicit claim or by omission.
29
30
3. Altered versions must be plainly marked as such, and must not be
31
   misrepresented as being the original software.
32
33
4. If PCRE is embedded in any software that is released under the GNU
34
   General Purpose Licence (GPL), then the terms of that licence shall
35
   supersede any condition above with which it is incompatible.
36
-----------------------------------------------------------------------------
37
*/
38
39
#include "apr.h"
40
#include "apr_strings.h"
41
#include "apr_lib.h"
42
                                                                                
43
#define APR_WANT_STDIO
44
#define APR_WANT_STRFUNC
45
#include "apr_want.h"
46
                                                                                
47
#if APR_HAVE_UNISTD_H
48
#include <unistd.h>
49
#endif
50
#if APR_HAVE_NETDB_H
51
#include <netdb.h>              /* for gethostbyname() */
52
#endif
53
54
#define CORE_PRIVATE
55
                                                                                
56
#include "ap_config.h"
57
#include "apr_base64.h"
58
#include "httpd.h"
59
#include "http_main.h"
60
#include "http_log.h"
61
#include "http_protocol.h"
62
#include "http_config.h"
63
#include "util_ebcdic.h"
64
                                                                                
65
#include <pcre.h>
66
67
#ifndef PCRE_CONFIG_POSIX_MALLOC_THRESHOLD
68
#define PCRE_CONFIG_POSIX_MALLOC_THRESHOLD 3
69
#endif
70
71
/* Table of texts corresponding to POSIX error codes */
72
73
static const char *pstring[] = {
74
  "",                                /* Dummy for value 0 */
75
  "internal error",                  /* REG_ASSERT */
76
  "invalid repeat counts in {}",     /* BADBR      */
77
  "pattern error",                   /* BADPAT     */
78
  "? * + invalid",                   /* BADRPT     */
79
  "unbalanced {}",                   /* EBRACE     */
80
  "unbalanced []",                   /* EBRACK     */
81
  "collation error - not relevant",  /* ECOLLATE   */
82
  "bad class",                       /* ECTYPE     */
83
  "bad escape sequence",             /* EESCAPE    */
84
  "empty expression",                /* EMPTY      */
85
  "unbalanced ()",                   /* EPAREN     */
86
  "bad range inside []",             /* ERANGE     */
87
  "expression too big",              /* ESIZE      */
88
  "failed to get memory",            /* ESPACE     */
89
  "bad back reference",              /* ESUBREG    */
90
  "bad argument",                    /* INVARG     */
91
  "match failed"                     /* NOMATCH    */
92
};
93
94
95
96
97
/*************************************************
98
*          Translate error code to string        *
99
*************************************************/
100
101
AP_DECLARE(size_t)
102
ap_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
103
{
104
const char *message, *addmessage;
105
size_t length, addlength;
106
107
message = (errcode >= (int)(sizeof(pstring)/sizeof(char *)))?
108
  "unknown error code" : pstring[errcode];
109
length = strlen(message) + 1;
110
111
addmessage = " at offset ";
112
addlength = (preg != NULL && (int)preg->re_erroffset != -1)?
113
  strlen(addmessage) + 6 : 0;
114
115
if (errbuf_size > 0)
116
  {
117
  if (addlength > 0 && errbuf_size >= length + addlength)
118
    sprintf(errbuf, "%s%s%-6d", message, addmessage, (int)preg->re_erroffset);
119
  else
120
    {
121
    strncpy(errbuf, message, errbuf_size - 1);
122
    errbuf[errbuf_size-1] = 0;
123
    }
124
  }
125
126
return length + addlength;
127
}
128
129
130
131
132
/*************************************************
133
*           Free store held by a regex           *
134
*************************************************/
135
136
void
137
ap_regfree(regex_t *preg)
138
{
139
(pcre_free)(preg->re_pcre);
140
}
141
142
143
144
145
/*************************************************
146
*            Compile a regular expression        *
147
*************************************************/
148
149
/*
150
Arguments:
151
  preg        points to a structure for recording the compiled expression
152
  pattern     the pattern to compile
153
  cflags      compilation flags
154
155
Returns:      0 on success
156
              various non-zero codes on failure
157
*/
158
159
int
160
ap_regcomp(regex_t *preg, const char *pattern, int cflags)
161
{
162
const char *errorptr;
163
int erroffset;
164
int options = 0;
165
166
if ((cflags & REG_ICASE) != 0) options |= PCRE_CASELESS;
167
if ((cflags & REG_NEWLINE) != 0) options |= PCRE_MULTILINE;
168
169
preg->re_pcre = pcre_compile(pattern, options, &errorptr, &erroffset, NULL);
170
preg->re_erroffset = erroffset;
171
172
if (preg->re_pcre == NULL) return 1;
173
174
preg->re_nsub = pcre_info(preg->re_pcre, NULL, NULL);
175
return 0;
176
}
177
178
179
180
181
/*************************************************
182
*              Match a regular expression        *
183
*************************************************/
184
185
/* Unfortunately, PCRE requires 3 ints of working space for each captured
186
substring, so we have to get and release working store instead of just using
187
the POSIX structures as was done in earlier releases when PCRE needed only 2
188
ints. However, if the number of possible capturing brackets is small, use a
189
block of store on the stack, to reduce the use of malloc/free. The threshold is
190
in a macro that can be changed at configure time. */
191
192
AP_DECLARE(int)
193
ap_regexec(regex_t *preg, const char *string, size_t nmatch,
194
  regmatch_t pmatch[], int eflags)
195
{
196
int rc;
197
int options = 0;
198
int *ovector = NULL;
199
int small_ovector[PCRE_CONFIG_POSIX_MALLOC_THRESHOLD * 3];
200
int allocated_ovector = 0;
201
202
if ((eflags & REG_NOTBOL) != 0) options |= PCRE_NOTBOL;
203
if ((eflags & REG_NOTEOL) != 0) options |= PCRE_NOTEOL;
204
205
((regex_t *)preg)->re_erroffset = (size_t)(-1);  /* Only has meaning after compile */
206
207
if (nmatch > 0)
208
  {
209
  if (nmatch <= PCRE_CONFIG_POSIX_MALLOC_THRESHOLD)
210
    {
211
    ovector = &(small_ovector[0]);
212
    }
213
  else
214
    {
215
    ovector = (int *)malloc(sizeof(int) * nmatch * 3);
216
    if (ovector == NULL) return REG_ESPACE;
217
    allocated_ovector = 1;
218
    }
219
  }
220
221
rc = pcre_exec(preg->re_pcre, NULL, string, (int)strlen(string), 0, options,
222
  ovector, nmatch * 3);
223
224
if (rc == 0) rc = nmatch;    /* All captured slots were filled in */
225
226
if (rc >= 0)
227
  {
228
  size_t i;
229
  for (i = 0; i < (size_t)rc; i++)
230
    {
231
    pmatch[i].rm_so = ovector[i*2];
232
    pmatch[i].rm_eo = ovector[i*2+1];
233
    }
234
  if (allocated_ovector) free(ovector);
235
  for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1;
236
  return 0;
237
  }
238
239
else
240
  {
241
  if (allocated_ovector) free(ovector);
242
  switch(rc)
243
    {
244
    case PCRE_ERROR_NOMATCH: return REG_NOMATCH;
245
    case PCRE_ERROR_NULL: return REG_INVARG;
246
    case PCRE_ERROR_BADOPTION: return REG_INVARG;
247
    case PCRE_ERROR_BADMAGIC: return REG_INVARG;
248
    case PCRE_ERROR_UNKNOWN_NODE: return REG_ASSERT;
249
    case PCRE_ERROR_NOMEMORY: return REG_ESPACE;
250
    default: return REG_ASSERT;
251
    }
252
  }
253
}
254
(-)orig/apache2/srclib/Makefile.in (-1 / +1 lines)
Lines 1-5 Link Here
1
1
2
SUBDIRS = pcre
2
SUBDIRS = 
3
BUILD_SUBDIRS = $(AP_BUILD_SRCLIB_DIRS)
3
BUILD_SUBDIRS = $(AP_BUILD_SRCLIB_DIRS)
4
CLEAN_SUBDIRS = $(AP_CLEAN_SRCLIB_DIRS)
4
CLEAN_SUBDIRS = $(AP_CLEAN_SRCLIB_DIRS)
5
5

Return to bug 27550