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)
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 )
{
struct berval *val,
struct berval *normalized )
{
- char *p, *q, *s;
+ char *p, *q, *s, *e;
int len = 0;
p = val->bv_val;
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;