ITS#2737: ensure buffer is realloc'ed as necessary

This commit is contained in:
Kurt Zeilenga 2003-12-02 18:26:44 +00:00
parent 5ea9c67160
commit 997b3b6bd2
2 changed files with 20 additions and 7 deletions

View file

@ -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

View 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??? */