--- httpd-2.2.6/modules/ldap/util_ldap.c 2007-08-20 01:19:46.000000000 +0200 +++ httpd-2.2.6-swisslife/modules/ldap/util_ldap.c 2007-12-07 10:41:44.000000000 +0100 @@ -45,6 +45,8 @@ #include "unixd.h" #endif +#define ATTRIBUTE_VALUE_SIZE 256 + /* defines for certificate file types */ #define LDAP_CA_TYPE_UNKNOWN 0 @@ -1038,16 +1040,45 @@ char **values; int j = 0; char *str = NULL; + int len = 0; + int size = 0; + int maxsize = 0; + int nextsize = 0; + char *buffer = NULL; + /* get values */ values = ldap_get_values(ldc->ldap, entry, attrs[i]); - while (values && values[j]) { - str = str ? apr_pstrcat(r->pool, str, "; ", values[j], NULL) - : apr_pstrdup(r->pool, values[j]); + + maxsize = ldap_count_values(values) * ATTRIBUTE_VALUE_SIZE; + + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, + "[%" APR_PID_T_FMT "] ldap cache: allocating %i bytes for attribute values", + getpid(), maxsize); + + buffer = apr_pcalloc(r->pool,maxsize); + str = buffer; + + while (values && values[j] && nextsize < maxsize) { + len=strlen(values[j]); + buffer[0]=';'; + memcpy(++buffer, values[j], len); + buffer+=len; + size+=len; j++; + + nextsize=size+strlen(values[j]); + + if (nextsize >= maxsize) { + ap_log_error(APLOG_MARK, APLOG_WARNING , 0, r->server, + "[%" APR_PID_T_FMT "] ldap cache: buffer overflow while storing attributes values. attribute %s has more than %i bytes ", + getpid(), attrs[i], maxsize); + } + } ldap_value_free(values); vals[i] = str; i++; + } *retvals = vals; } @@ -1233,12 +1264,40 @@ char **values; int j = 0; char *str = NULL; + int len = 0; + int size = 0; + int maxsize = 0; + int nextsize = 0; + char *buffer = NULL; + /* get values */ values = ldap_get_values(ldc->ldap, entry, attrs[i]); - while (values && values[j]) { - str = str ? apr_pstrcat(r->pool, str, "; ", values[j], NULL) - : apr_pstrdup(r->pool, values[j]); + + maxsize = ldap_count_values(values) * ATTRIBUTE_VALUE_SIZE; + + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, + "[%" APR_PID_T_FMT "] ldap cache: allocating %i bytes for attribute values", + getpid(), maxsize); + + buffer = apr_pcalloc(r->pool,maxsize); + str = buffer; + + while (values && values[j] && nextsize < maxsize) { + len=strlen(values[j]); + buffer[0]=';'; + memcpy(++buffer, values[j], len); + buffer+=len; + size+=len; j++; + + nextsize=size+strlen(values[j]); + + if (nextsize >= maxsize) { + ap_log_error(APLOG_MARK, APLOG_WARNING , 0, r->server, + "[%" APR_PID_T_FMT "] ldap cache: buffer overflow while storing attributes values. attribute %s has more than %i bytes ", + getpid(), attrs[i], maxsize); + } + } ldap_value_free(values); vals[i] = str;