Author: nhosoi
Update of /cvs/dirsec/ldapserver/ldap/servers/slapd
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv24889/ldap/servers/slapd
Modified Files:
Tag: Directory71RtmBranch
regex.c
Log Message:
Resolves: #182621
Summary: Allow larger regex buffer to enable long substring filters
Description: Applying the patches provided by ulf.weltman(a)hp.com.
regex.c: use dynamically allocated regex buffer, use ptrdiff_t to store the offsets to be
restored after the realloc, and use a constant for the value of "how much the NFA
buffer can grow in one iteration on the pattern".
string.c: use dynamically allocated buffer if the prepared buffer is not large enough,
used wrong pointer (pat instead of p) in a debug message, and performed an unneeded strcat
of ".*"
Index: regex.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/regex.c,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -u -r1.4 -r1.4.2.1
--- regex.c 19 Apr 2005 22:07:37 -0000 1.4
+++ regex.c 30 Apr 2008 20:57:44 -0000 1.4.2.1
@@ -38,31 +38,6 @@
#include "slap.h" /* must come before regex.h */
#include "portable.h"
-static PRLock *regex_mutex = NULL;
-
-int
-slapd_re_init( void )
-{
- if ( NULL == regex_mutex ) {
- regex_mutex = PR_NewLock();
- }
- return( NULL == regex_mutex ? -1 : 0 );
-}
-
-void
-slapd_re_lock( void )
-{
- PR_ASSERT( NULL != regex_mutex );
- PR_Lock( regex_mutex );
-}
-
-int
-slapd_re_unlock( void )
-{
- PR_ASSERT( NULL != regex_mutex );
- return( PR_Unlock( regex_mutex ) );
-}
-
#if defined( MACOS ) || defined( DOS ) || defined( _WIN32 ) || defined( NEED_BSDREGEX )
#include "regex.h"
@@ -86,6 +61,13 @@
* Modification history:
*
* $Log$
+ * Revision 1.4.2.1 2008/04/30 20:57:44 nhosoi
+ * Resolves: #182621
+ * Summary: Allow larger regex buffer to enable long substring filters
+ * Description: Applying the patches provided by ulf.weltman(a)hp.com.
+ * regex.c: use dynamically allocated regex buffer, use ptrdiff_t to store the offsets to
be restored after the realloc, and use a constant for the value of "how much the NFA
buffer can grow in one iteration on the pattern".
+ * string.c: use dynamically allocated buffer if the prepared buffer is not large enough,
used wrong pointer (pat instead of p) in a debug message, and performed an unneeded strcat
of ".*"
+ *
* Revision 1.4 2005/04/19 22:07:37 nkinder
* Fixed licensing typo
*
@@ -401,6 +383,12 @@
* matches: foo-foo fo-fo fob-fob foobar-foobar ...
*/
+/* This is the maximum the NFA buffer might grow for every op code processed.
+ The max seems to be the + after a character class, like "[a-z]+". It
+ needs 1 byte for the CCL code, 16 for the CCL bit map, and 2 for END codes
+ and 1 for a CLO code. */
+#define MAXOPSPACE 20
+
#define MAXNFA 1024
#define MAXTAG 10
@@ -439,7 +427,8 @@
*/
static int tagstk[MAXTAG]; /* subpat tag stack..*/
-static UCHAR nfa[MAXNFA]; /* automaton.. */
+static UCHAR *nfa = NULL; /* automaton.. */
+static int nfasize = MAXNFA; /* tracks size of nfa buffer */
static int sta = NOP; /* status of lastpat */
static UCHAR bittab[BITBLK]; /* bit table for CCL */
@@ -483,6 +472,20 @@
sta = NOP;
for (p = (UCHAR*)pat; *p; p++) {
+ /* Check if we are approaching end of nfa buffer. MAXOPSPACE is+ the max we might
add to the nfa per loop. */
+ if (mp - (UCHAR*)nfa + MAXOPSPACE >= nfasize) {
+ /* Save offsets */
+ ptrdiff_t mppos = mp - nfa;
+ ptrdiff_t sppos = sp - nfa;
+
+ /* Double the nfa buffer size */
+ nfasize *= 2;
+ nfa = (UCHAR*)slapi_ch_realloc((char*)nfa, nfasize);
+
+ /* Restore pointers into realloced space */
+ mp = nfa + mppos;
+ sp = nfa + sppos;
+ }
lp = mp;
switch(*p) {
@@ -1084,3 +1087,35 @@
}
#endif
#endif /* MACOS or DOS or NEED_BSDREGEX */
+
+static PRLock *regex_mutex = NULL;
+
+int
+slapd_re_init( void )
+{
+ if ( NULL == regex_mutex ) {
+ regex_mutex = PR_NewLock();
+ }
+
+#if defined( MACOS ) || defined( DOS ) || defined( _WIN32 ) || defined( NEED_BSDREGEX )
+ if ( NULL == nfa ) {
+ nfa = (UCHAR*)slapi_ch_malloc( MAXNFA );
+ }
+#endif
+
+ return( NULL == regex_mutex ? -1 : 0 );
+}
+
+void
+slapd_re_lock( void )
+{
+ PR_ASSERT( NULL != regex_mutex );
+ PR_Lock( regex_mutex );
+}
+
+int
+slapd_re_unlock( void )
+{
+ PR_ASSERT( NULL != regex_mutex );
+ return( PR_Unlock( regex_mutex ) );
+}
Show replies by date