]> git.sur5r.net Git - openldap/commitdiff
ITS#2737: ensure buffer is realloc'ed as necessary
authorKurt Zeilenga <kurt@openldap.org>
Tue, 2 Dec 2003 18:26:44 +0000 (18:26 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Tue, 2 Dec 2003 18:26:44 +0000 (18:26 +0000)
CHANGES
libraries/liblunicode/ucstr.c

diff --git a/CHANGES b/CHANGES
index a4b8ae83d295b66331f1d8a3917677def6b63b11..9615798d8486b490f46deadad988ea0d7456fb8b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,7 @@ OpenLDAP 2.1.24 Engineering
        Fixed slapd extended op referrals (ITS#2678, ITS#2781)
        Fixed slurpd memory leaks (ITS#2423, ITS#2620)
        Fixed back-bdb compatibility with BDB 4.2 (ITS#2848)
+       Fixed lunicode insufficient buffer allocation bug (ITS#2727)
        Fixed libldap_r pthread support (ITS#2820)
        Fixed slapd berbuf align bugs
        Added lutil_passwd extensions
index e6060156b588ef34c34b4749016ec8e9acb1e250..b1b0d50366a0de666b11b18db3f7a6a45741ab26 100644 (file)
@@ -117,9 +117,9 @@ struct berval * UTF8bvnormalize(
                return ber_dupbv( newbv, bv );
        }
        
-       /* FIXME: Should first check to see if string is already in
-        * proper normalized form. This is almost as time consuming
-        * as the normalization though.
+       /* Should first check to see if string is already in proper
+        * normalized form. This is almost as time consuming as
+        * the normalization though.
         */
 
        /* finish off everything up to character before first non-ascii */
@@ -136,7 +136,7 @@ struct berval * UTF8bvnormalize(
                                out[outpos++] = TOLOWER( s[i-1] );
                        }
                        if ( i == len ) {
-                               out[outpos++] = TOLOWER( s[len - 1] );
+                               out[outpos++] = TOLOWER( s[len-1] );
                                out[outpos] = '\0';
                                return ber_str2bv( out, outpos, 0, newbv);
                        }
@@ -249,6 +249,18 @@ struct berval * UTF8bvnormalize(
 
                last = i;
 
+               /* Allocate more space in out if necessary */
+               if (len - i >= outsize - outpos) {
+                       outsize += 1 + ((len - i) - (outsize - outpos));
+                       outtmp = (char *) realloc(out, outsize);
+                       if (outtmp == NULL) {
+                               free(out);
+                               free(ucs);
+                               return NULL;
+                       }
+                       out = outtmp;
+               }
+
                /* s[i] is ascii */
                /* finish off everything up to char before next non-ascii */
                for ( i++; (i < len) && LDAP_UTF8_ISASCII(s + i); i++ ) {
@@ -317,7 +329,8 @@ int UTF8bvnormcmp(
                                        break;
                                }
                        } else if (((len < l1) && !LDAP_UTF8_ISASCII(s1)) ||
-                                  ((len < l2) && !LDAP_UTF8_ISASCII(s2))) {
+                          ((len < l2) && !LDAP_UTF8_ISASCII(s2)))
+                       {
                                break;
                        }
                        return res;
@@ -344,10 +357,9 @@ int UTF8bvnormcmp(
                l2 -= i - 1;
        }
                        
-       /* FIXME: Should first check to see if strings are already in
+       /* Should first check to see if strings are already in
         * proper normalized form.
         */
-
        ucs = malloc( ( ( norm1 || l1 > l2 ) ? l1 : l2 ) * sizeof(*ucs) );
        if ( ucs == NULL ) {
                return l1 > l2 ? 1 : -1; /* what to do??? */