]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapi/slapi_utils.c
Sync with HEAD
[openldap] / servers / slapd / slapi / slapi_utils.c
index 9d8c2341e3507f2e6b95c8b82cc3cfc71ca09066..9a1fc49b32e0b3459d411ff5bd07777a18827f61 100644 (file)
@@ -49,6 +49,22 @@ struct slapi_condvar {
        ldap_pvt_thread_mutex_t mutex;
 };
 
+#ifdef LDAP_SLAPI
+static int checkBVString(const struct berval *bv)
+{
+       int i;
+
+       for ( i = 0; i < bv->bv_len; i++ ) {
+               if ( bv->bv_val[i] == '\0' )
+                       return 0;
+       }
+       if ( bv->bv_val[i] != '\0' )
+               return 0;
+
+       return 1;
+}
+#endif /* LDAP_SLAPI */
+
 /*
  * This function converts an array of pointers to berval objects to
  * an array of berval objects.
@@ -293,7 +309,12 @@ slapi_entry_attr_get_charptr( const Slapi_Entry *e, const char *type )
        }
 
        if ( attr->a_vals != NULL && attr->a_vals[0].bv_len != 0 ) {
-               return slapi_ch_strdup( attr->a_vals[0].bv_val );
+               const char *p;
+
+               p = slapi_value_get_string( &attr->a_vals[0] );
+               if ( p != NULL ) {
+                       return slapi_ch_strdup( (char *)p );
+               }
        }
 
        return NULL;
@@ -3012,31 +3033,16 @@ int slapi_value_set_int(Slapi_Value *value, int intVal)
 const char *slapi_value_get_string(const Slapi_Value *value)
 {
 #ifdef LDAP_SLAPI
-       if ( value == NULL ) {
-               return NULL;
-       }
+       if ( value == NULL ) return NULL;
+       if ( value->bv_val == NULL ) return NULL;
+       if ( !checkBVString( value ) ) return NULL;
+
        return value->bv_val;
 #else
        return NULL;
 #endif
 }
 
-#ifdef LDAP_SLAPI
-static int checkBVString(const struct berval *bv)
-{
-       int i;
-
-       for ( i = 0; i < bv->bv_len; i++ ) {
-               if ( bv->bv_val[i] == '\0' )
-                       return 0;
-       }
-       if ( bv->bv_val[i] != '\0' )
-               return 0;
-
-       return 1;
-}
-#endif /* LDAP_SLAPI */
-
 int slapi_value_get_int(const Slapi_Value *value)
 {
 #ifdef LDAP_SLAPI