From: Kurt Zeilenga Date: Sun, 12 Oct 2003 23:31:00 +0000 (+0000) Subject: Apply patch suggested in ITS#2737 to address underallocation bug. X-Git-Tag: OPENLDAP_REL_ENG_2_1_MP~583 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6aff66cf6741acc4f2dba2452430b1d5eaf17910;p=openldap Apply patch suggested in ITS#2737 to address underallocation bug. This could should be reworked to avoid multiple reallocs (likely by overallocating). --- diff --git a/libraries/liblunicode/ucstr.c b/libraries/liblunicode/ucstr.c index a8c65df861..d854b2aead 100644 --- a/libraries/liblunicode/ucstr.c +++ b/libraries/liblunicode/ucstr.c @@ -251,6 +251,18 @@ struct berval * UTF8bvnormalize( last = i; + /* Allocate more space in out if necessary */ + if (len - i > outsize - outpos) { + outsize = outsize + ((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++ ) {