From: Kurt Zeilenga Date: Tue, 2 Dec 2003 18:26:44 +0000 (+0000) Subject: ITS#2737: ensure buffer is realloc'ed as necessary X-Git-Tag: OPENLDAP_REL_ENG_2_1_24~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=997b3b6bd2bdc442f6b08900629fa7ac31fc80c7;p=thirdparty%2Fopenldap.git ITS#2737: ensure buffer is realloc'ed as necessary --- diff --git a/CHANGES b/CHANGES index a4b8ae83d2..9615798d84 100644 --- 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 diff --git a/libraries/liblunicode/ucstr.c b/libraries/liblunicode/ucstr.c index e6060156b5..b1b0d50366 100644 --- a/libraries/liblunicode/ucstr.c +++ b/libraries/liblunicode/ucstr.c @@ -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??? */