]> git.sur5r.net Git - openldap/blobdiff - libraries/librewrite/subst.c
Merge remote branch 'origin/mdb.master'
[openldap] / libraries / librewrite / subst.c
index fe055a35ccae4afb35cfc1a9e54151d3e7c51e2e..5b01a1012421aa17c187bfcc62dd02c79c78a9a4 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2003 The OpenLDAP Foundation.
+ * Copyright 2000-2011 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -55,11 +55,11 @@ rewrite_subst_compile(
                /*
                 * Keep only single escapes '%'
                 */
-               if ( p[ 0 ] != REWRITE_SUBMATCH_ESCAPE ) {
+               if (  !IS_REWRITE_SUBMATCH_ESCAPE( p[ 0 ] ) ) {
                        continue;
                } 
 
-               if ( p[ 1 ] == REWRITE_SUBMATCH_ESCAPE ) {
+               if (  IS_REWRITE_SUBMATCH_ESCAPE( p[ 1 ] ) ) {
                        /* Pull &p[1] over p, including the trailing '\0' */
                        AC_MEMCPY((char *)p, &p[ 1 ], strlen( p ) );
                        continue;
@@ -193,6 +193,10 @@ rewrite_subst_compile(
                subs_len += l;
                subs[ nsub ].bv_len = l;
                subs[ nsub ].bv_val = malloc( l + 1 );
+               if ( subs[ nsub ].bv_val == NULL ) {
+                       free( subs );
+                       goto cleanup;
+               }
                AC_MEMCPY( subs[ nsub ].bv_val, begin, l );
                subs[ nsub ].bv_val[ l ] = '\0';
        } else {
@@ -387,6 +391,7 @@ rewrite_subst_apply(
 
                if ( rc != REWRITE_SUCCESS ) {
                        rc = REWRITE_REGEXEC_ERR;
+                       goto cleanup;
                }
                
                /*
@@ -452,8 +457,8 @@ rewrite_subst_destroy(
        int                     n;
        struct rewrite_subst    *subst;
 
-       assert( psubst );
-       assert( *psubst );
+       assert( psubst != NULL );
+       assert( *psubst != NULL );
 
        subst = *psubst;