From cc9101d9806cffbe2ec62241f9aee9bd19dd6127 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Fri, 2 Jan 2004 06:07:22 +0000 Subject: [PATCH] Check value is a C string in slapi_value_get_string() --- servers/slapd/slapi/slapi_utils.c | 39 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/servers/slapd/slapi/slapi_utils.c b/servers/slapd/slapi/slapi_utils.c index 9d8c2341e3..29fa81010d 100644 --- a/servers/slapd/slapi/slapi_utils.c +++ b/servers/slapd/slapi/slapi_utils.c @@ -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. @@ -3012,31 +3028,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 -- 2.39.5