Browse Source

Bug 504817 - Handle LDAPv2 quoted RDN values correctly

The bug fix for bug 438139 introduced a regression that causes the
server to not handle LDAPv2 quoted RDN values correctly.  We were
including the '"' characters used to contain an unescaped value in
the actual value itself.

The proper thing to do is to eliminate any '"' characters that are
not escaped when we unescape the value.  I have tested this new fix
with the oringinal issue from bug 438139 to ensure that it does not
introduce a regression for that bug.
Nathan Kinder 16 years ago
parent
commit
4c333c1319
1 changed files with 26 additions and 28 deletions
  1. 26 28
      ldap/servers/slapd/util.c

+ 26 - 28
ldap/servers/slapd/util.c

@@ -211,42 +211,40 @@ strcpy_unescape_value( char *d, const char *s )
     {
         switch ( *s )
         {
+        case '"':
+            break;
         case '\\':
-            if ( gotesc ) {
-                gotesc = 0;
-            } else {
-                gotesc = 1;
-                if ( s+2 < end ) {
-                    int n = hexchar2int( s[1] );
-                    /* If 8th bit is on, the char is not ASCII (not UTF-8).  
-                     * Thus, not UTF-8 */
-                    if ( n >= 0 && n < 8 ) {
-                        int n2 = hexchar2int( s[2] );
-                        if ( n2 >= 0 ) {
-                            n = (n << 4) + n2;
-                            if (n == 0) { /* don't change \00 */
-                                *d++ = *s++;
-                                *d++ = *s++;
-                                *d++ = *s;
-                            } else { /* change \xx to a single char */
-                                *d++ = (char)n;
-                                s += 2;
-                            }
-                            gotesc = 0;
+            gotesc = 1;
+            if ( s+2 < end ) {
+                int n = hexchar2int( s[1] );
+                /* If 8th bit is on, the char is not ASCII (not UTF-8).  
+                 * Thus, not UTF-8 */
+                if ( n >= 0 && n < 8 ) {
+                    int n2 = hexchar2int( s[2] );
+                    if ( n2 >= 0 ) {
+                        n = (n << 4) + n2;
+                        if (n == 0) { /* don't change \00 */
+                            *d++ = *s++;
+                            *d++ = *s++;
+                            *d++ = *s;
+                        } else { /* change \xx to a single char */
+                            *d++ = (char)n;
+                            s += 2;
                         }
+                        gotesc = 0;
                     }
                 }
-                if (gotesc) {
-                    *d++ = *s;
-                }
             }
-            break;
-        default:
+            /* This is an escaped single character (like \"), so
+             * just copy the special character and not the escape. */
             if (gotesc) {
-                d--;
+                s++;
+                *d++ = *s;
+                gotesc = 0;
             }
+            break;
+        default:
             *d++ = *s;
-            gotesc = 0;
             break;
         }
     }