From 57253688b381375ae8b5a1ffce7a2d2d369bb743 Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Sun, 26 Nov 2017 21:22:23 +0100 Subject: [PATCH] ITS#8778 Fix telephoneNumberNormalize("-" or " ") --- servers/slapd/schema_init.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index 16c4d1ce5d..b51ce53e3c 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -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; } -- 2.39.2