]> git.sur5r.net Git - openldap/blobdiff - libraries/librewrite/config.c
Fix UTF8StringNormalize overrun on zero-length string
[openldap] / libraries / librewrite / config.c
index 9cf3ad98dc45f6c5f2de29fb0d647ba464567398..085af5fbbdc4893015eeed9d938d6dbbcad569df 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
@@ -39,7 +39,7 @@ rewrite_parse_builtin_map(
  * lines handled are of the form:
  *
  *      rewriteEngine          {on|off}
- *      rewriteMaxPasses        numPasses
+ *      rewriteMaxPasses        numPasses [numPassesPerRule]
  *      rewriteContext                 contextName [alias aliasedContextName]
  *      rewriteRule            pattern substPattern [ruleFlags]
  *      rewriteMap             mapType mapName [mapArgs]
@@ -103,7 +103,39 @@ rewrite_parse(
                                        fname, lineno, "" );
                        return -1;
                }
-               info->li_max_passes = atoi( argv[ 1 ] );
+
+               if ( lutil_atoi( &info->li_max_passes, argv[ 1 ] ) != 0 ) {
+                       Debug( LDAP_DEBUG_ANY,
+                                       "[%s:%d] unable to parse rewriteMaxPasses=\"%s\"\n",
+                                       fname, lineno, argv[ 1 ] );
+                       return -1;
+               }
+
+               if ( info->li_max_passes <= 0 ) {
+                       Debug( LDAP_DEBUG_ANY,
+                                       "[%s:%d] negative or null rewriteMaxPasses\n",
+                                       fname, lineno, 0 );
+                       return -1;
+               }
+
+               if ( argc > 2 ) {
+                       if ( lutil_atoi( &info->li_max_passes_per_rule, argv[ 2 ] ) != 0 ) {
+                               Debug( LDAP_DEBUG_ANY,
+                                               "[%s:%d] unable to parse rewriteMaxPassesPerRule=\"%s\"\n",
+                                               fname, lineno, argv[ 2 ] );
+                               return -1;
+                       }
+
+                       if ( info->li_max_passes_per_rule <= 0 ) {
+                               Debug( LDAP_DEBUG_ANY,
+                                               "[%s:%d] negative or null rewriteMaxPassesPerRule\n",
+                                               fname, lineno, 0 );
+                               return -1;
+                       }
+
+               } else {
+                       info->li_max_passes_per_rule = info->li_max_passes;
+               }
                rc = REWRITE_SUCCESS;
        
        /*
@@ -381,8 +413,8 @@ rewrite_parse_builtin_map(
        /*
         * Built-in ldap map
         */
-       if ( strcasecmp( argv[ MAP_TYPE ], "ldap" ) == 0 ) {
-               map->lb_type = REWRITE_BUILTIN_MAP_LDAP;
+       if (( map->lb_mapper = rewrite_mapper_find( argv[ MAP_TYPE ] ))) {
+               map->lb_type = REWRITE_BUILTIN_MAP;
 
 #ifdef USE_REWRITE_LDAP_PVT_THREADS
                if ( ldap_pvt_thread_mutex_init( & map->lb_mutex ) ) {
@@ -392,13 +424,14 @@ rewrite_parse_builtin_map(
                }
 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
                
-               map->lb_private = map_ldap_parse( info, fname, lineno,
+               map->lb_private = map->lb_mapper->rm_config( fname, lineno,
                                argc - 3, argv + 3 );
                
        /* 
         * Error
         */     
        } else {
+               free( map );
                Debug( LDAP_DEBUG_ANY, "[%s:%d] unknown map type\n%s",
                                fname, lineno, "" );
                return -1;