#define        LBER_BV_ALLOC   0x01    /* allocate/copy result, otherwise in-place */
 #define        LBER_BV_NOTERM  0x02    /* omit NUL-terminator if parsing in-place */
 #define        LBER_BV_STRING  0x04    /* fail if berval contains embedded \0 */
+/* LBER_BV_STRING currently accepts a terminating \0 in the berval, because
+ * Active Directory sends that in at least the diagonsticMessage field.
+ */
 
 LBER_F( ber_tag_t )
 ber_get_stringbv LDAP_P((
 
 
        tag = ber_skip_element( ber, bv );
        if ( tag == LBER_DEFAULT ||
-               (( option & LBER_BV_STRING ) && memchr( bv->bv_val, 0, bv->bv_len )))
+               (( option & LBER_BV_STRING ) &&
+                bv->bv_len && memchr( bv->bv_val, 0, bv->bv_len - 1 )))
        {
                bv->bv_val = NULL;
                return LBER_DEFAULT;
                return tag;
        }
 
-       if (( option & LBER_BV_STRING ) && memchr( bv->bv_val, 0, bv->bv_len )) {
+       if (( option & LBER_BV_STRING ) &&
+               memchr( bv->bv_val, 0, bv->bv_len - 1 ))
+       {
                bv->bv_val = NULL;
                return LBER_DEFAULT;
        }