]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/schema_init.c
Do not require ac/string.h for lber_pvt.h
[openldap] / servers / slapd / schema_init.c
index 16c4d1ce5d7804bb952331bdbc94de564b51b225..eb7a09bbbef7e4543a32e50f8424531171f71fb1 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2017 The OpenLDAP Foundation.
+ * Copyright 1998-2018 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -2290,7 +2290,7 @@ approxFilter(
        return LDAP_SUCCESS;
 }
 
-/* Remove all spaces and '-' characters */
+/* Remove all spaces and '-' characters, unless the result would be empty */
 static int
 telephoneNumberNormalize(
        slap_mask_t usage,
@@ -2304,8 +2304,11 @@ telephoneNumberNormalize(
 
        assert( SLAP_MR_IS_VALUE_OF_SYNTAX( usage ) != 0 );
 
-       /* validator should have refused an empty string */
-       assert( !BER_BVISEMPTY( val ) );
+       /* Ensure q is big enough, though validator should have caught this */
+       if ( BER_BVISEMPTY( val )) {
+               BER_BVZERO( normalized );
+               return LDAP_INVALID_SYNTAX;
+       }
 
        q = normalized->bv_val = slap_sl_malloc( val->bv_len + 1, ctx );
 
@@ -2314,16 +2317,13 @@ telephoneNumberNormalize(
                        *q++ = *p;
                }
        }
+       if ( q == normalized->bv_val ) {
+               *q++ = ' ';
+       }
        *q = '\0';
 
        normalized->bv_len = q - normalized->bv_val;
 
-       if( BER_BVISEMPTY( normalized ) ) {
-               slap_sl_free( normalized->bv_val, ctx );
-               BER_BVZERO( normalized );
-               return LDAP_INVALID_SYNTAX;
-       }
-
        return LDAP_SUCCESS;
 }