Skip to content

Commit f91be14

Browse files
committed
openldap: limit max incoming size
Set the maximum allowed size of an incoming LDAP message, which to OpenLDAP means that it allows malloc() up to this size. If not set, there is no limit and we instead risk a malloc() failure. The limit is arbitrarily set to 256K as I can't figure out what a reasonable value should be. OpenLDAP docs: https://openldap.org/software/man.cgi?query=lber-sockbuf&apropos=0&sektion=0&manpath=OpenLDAP+2.6-Release&arch=default&format=html Bug: https://issues.oss-fuzz.com/issues/432441303 Closes curl#19087
1 parent da06621 commit f91be14

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

lib/openldap.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,19 @@ static CURLcode oldap_connect(struct Curl_easy *data, bool *done)
659659
/* Do not chase referrals. */
660660
ldap_set_option(li->ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF);
661661

662+
{
663+
ber_len_t max = 256*1024;
664+
Sockbuf *sb;
665+
if(ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, (void **)&sb) ||
666+
/* Set the maximum allowed size of an incoming message, which to
667+
OpenLDAP means that it will malloc() memory up to this size. If not
668+
set, there is no limit and we instead risk a malloc() failure. */
669+
ber_sockbuf_ctrl(sb, LBER_SB_OPT_SET_MAX_INCOMING, &max)) {
670+
result = CURLE_FAILED_INIT;
671+
goto out;
672+
}
673+
}
674+
662675
#ifdef USE_SSL
663676
if(Curl_conn_is_ssl(conn, FIRSTSOCKET)) {
664677
result = oldap_ssl_connect(data, OLDAP_SSL);

0 commit comments

Comments
 (0)