mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-21 03:10:25 +08:00
make UTF8STringNormalize handle NUL
This commit is contained in:
parent
6e88ea7108
commit
39891e4e5b
@ -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)
|
||||
|
||||
|
@ -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 )
|
||||
{
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user