From 39891e4e5b333c6297ddd13577d850f958a09705 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Wed, 13 Feb 2002 21:25:57 +0000 Subject: [PATCH] make UTF8STringNormalize handle NUL --- include/lber.h | 4 ++++ libraries/liblber/memory.c | 40 +++++++++++++++++++++++++++++++++++++ servers/slapd/schema_init.c | 7 ++++--- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/include/lber.h b/include/lber.h index c031ec1d96..1a0316b218 100644 --- a/include/lber.h +++ b/include/lber.h @@ -567,6 +567,10 @@ LBER_F( struct berval * ) ber_str2bv LDAP_P(( LDAP_CONST char *, ber_len_t len, int dup, struct berval *bv)); +LBER_F( struct berval * ) +ber_mem2bv LDAP_P(( + LDAP_CONST char *, ber_len_t len, int dup, struct berval *bv)); + #define ber_bvstr(a) ber_str2bv(a, 0, 0, NULL) #define ber_bvstrdup(a) ber_str2bv(a, 0, 1, NULL) diff --git a/libraries/liblber/memory.c b/libraries/liblber/memory.c index 8cdad0ec8b..b8692e1d57 100644 --- a/libraries/liblber/memory.c +++ b/libraries/liblber/memory.c @@ -523,6 +523,46 @@ ber_str2bv( return( new ); } +struct berval * +ber_mem2bv( + LDAP_CONST char *s, ber_len_t len, int dup, struct berval *bv) +{ + struct berval *new; + + ber_int_options.lbo_valid = LBER_INITIALIZED; + + if( s == NULL || len == 0 ) { + ber_errno = LBER_ERROR_PARAM; + return NULL; + } + + if( bv ) { + new = bv; + } else { + if(( new = LBER_MALLOC( sizeof(struct berval) )) == NULL ) { + ber_errno = LBER_ERROR_MEMORY; + return NULL; + } + } + + new->bv_len = len; + if ( dup ) { + if ( (new->bv_val = LBER_MALLOC( new->bv_len+1 )) == NULL ) { + ber_errno = LBER_ERROR_MEMORY; + if ( !bv ) + LBER_FREE( new ); + return NULL; + } + + AC_MEMCPY( new->bv_val, s, new->bv_len ); + new->bv_val[new->bv_len] = '\0'; + } else { + new->bv_val = (char *) s; + } + + return( new ); +} + char * ber_strdup( LDAP_CONST char *s ) { diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index a6e68b5316..a392547a61 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -522,7 +522,7 @@ UTF8StringNormalize( struct berval *val, struct berval *normalized ) { - char *p, *q, *s; + char *p, *q, *s, *e; int len = 0; p = val->bv_val; @@ -537,14 +537,15 @@ UTF8StringNormalize( return LDAP_INVALID_SYNTAX; } - ber_str2bv( p, val->bv_len - (p - val->bv_val), 1, normalized ); + ber_mem2bv( p, val->bv_len - (p - val->bv_val), 1, normalized ); + e = normalized->bv_val + val->bv_len - (p - val->bv_val); assert( normalized->bv_val ); p = q = normalized->bv_val; s = NULL; - while ( *p ) { + while ( p < e ) { q += len; if ( ASCII_SPACE( *p ) ) { s = q - len;