ava->la_attr = ad->ad_cname;
 
                        if( ava->la_flags & LDAP_AVA_BINARY ) {
+                               if( ava->la_value.bv_len == 0 ) {
+                                       /* BER encoding is empty */
+                                       return LDAP_INVALID_SYNTAX;
+                               }
+
                                /* AVA is binary encoded, don't muck with it */
                        } else if( flags & SLAP_LDAPDN_PRETTY ) {
                                transf = ad->ad_type->sat_syntax->ssyn_pretty;
 
                        snprintf( textbuf, textlen, 
                                "naming attribute '%s' is not present in entry",
                                ava->la_attr.bv_val );
-                       rc = LDAP_NO_SUCH_ATTRIBUTE;
+                       rc = LDAP_NAMING_VIOLATION;
                        break;
                }
 
+               if( ava->la_flags & LDAP_AVA_BINARY ) {
+                       snprintf( textbuf, textlen, 
+                               "value of naming attribute '%s' in unsupported BER form",
+                               ava->la_attr.bv_val );
+                       rc = LDAP_NAMING_VIOLATION;
+               }
+
 #ifdef SLAP_NVALUES
                if ( value_find_ex( desc,
                        SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
                        snprintf( textbuf, textlen, 
                                "value of naming attribute '%s' is not present in entry",
                                ava->la_attr.bv_val );
-                       rc = LDAP_NO_SUCH_ATTRIBUTE;
+                       rc = LDAP_NAMING_VIOLATION;
                        break;
                }
        }