From: Pierangelo Masarati Date: Sun, 23 Dec 2001 09:26:44 +0000 (+0000) Subject: least escaping in dnPretty (hope my wife doesn't catch me in front of the laptop :) X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~568 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=dcc062dce5934b19a073613aed5517579fb25c45;p=openldap least escaping in dnPretty (hope my wife doesn't catch me in front of the laptop :) --- diff --git a/libraries/libldap/getdn.c b/libraries/libldap/getdn.c index 59d0bb572e..f0be32b57a 100644 --- a/libraries/libldap/getdn.c +++ b/libraries/libldap/getdn.c @@ -676,8 +676,9 @@ dn2dn( const char *dnin, unsigned fin, char **dnout, unsigned fout ) ( LDAP_DN_ASCII_SPACE(c) || LDAP_DN_NEEDESCAPE(c) ) #define LDAP_DN_WILLESCAPE_CHAR( c) \ ( LDAP_DN_RDN_SEP(c) || LDAP_DN_AVA_SEP(c) ) +#define LDAP_DN_IS_PRETTY( f ) ( (f) & LDAP_DN_PRETTY ) #define LDAP_DN_WILLESCAPE(f, c) \ - ( ( !( (f) & LDAP_DN_PRETTY ) ) && LDAP_DN_WILLESCAPE_CHAR(c) ) + ( ( !LDAP_DN_IS_PRETTY( f ) ) && LDAP_DN_WILLESCAPE_CHAR(c) ) /* LDAPv2 */ #define LDAP_DN_VALUE_END_V2(c) \ @@ -2147,6 +2148,7 @@ strval2strlen( struct berval *val, unsigned flags, ber_len_t *len ) { ber_len_t l, cl = 1; char *p; + int escaped_byte_len = LDAP_DN_IS_PRETTY( flags ) ? 1 : 3; assert( val ); assert( len ); @@ -2170,8 +2172,7 @@ strval2strlen( struct berval *val, unsigned flags, ber_len_t *len ) return( -1 ); } } - /* need to escape it */ - l += 3 * cl; + l += escaped_byte_len * cl; /* * there might be some chars we want to escape in form @@ -2224,7 +2225,8 @@ strval2str( struct berval *val, char *str, unsigned flags, ber_len_t *len ) * there might be some chars we want to escape in form * of a couple of hexdigits for optimization purposes */ - if ( cl > 1 || LDAP_DN_WILLESCAPE( flags, val->bv_val[ s ] ) ) { + if ( ( cl > 1 && !LDAP_DN_IS_PRETTY( flags ) ) + || LDAP_DN_WILLESCAPE( flags, val->bv_val[ s ] ) ) { for ( ; cl--; ) { str[ d++ ] = '\\'; byte2hexpair( &val->bv_val[ s ], &str[ d ] ); @@ -2232,6 +2234,11 @@ strval2str( struct berval *val, char *str, unsigned flags, ber_len_t *len ) d += 2; } + } else if ( cl > 1 ) { + for ( ; cl--; ) { + str[ d++ ] = val->bv_val[ s++ ]; + } + } else { if ( LDAP_DN_NEEDESCAPE( val->bv_val[ s ] ) || ( d == 0 && LDAP_DN_NEEDESCAPE_LEAD( val->bv_val[ s ] ) )