openldap: avoid NULL pointer dereferences

Follow-up to a59c33ceff
Reported-by: Patrick Monnerat
Fixes #6676
Closes #6780
This commit is contained in:
Daniel Stenberg 2021-03-23 09:28:07 +01:00
parent 3bbf62b5a4
commit e467ea3bd9
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
1 changed files with 25 additions and 15 deletions

View File

@ -369,6 +369,9 @@ static CURLcode ldap_disconnect(struct Curl_easy *data,
if(li) { if(li) {
if(li->ld) { if(li->ld) {
Sockbuf *sb;
ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb);
ber_sockbuf_add_io(sb, &ldapsb_tls, LBER_SBIOD_LEVEL_TRANSPORT, NULL);
ldap_unbind_ext(li->ld, NULL, NULL); ldap_unbind_ext(li->ld, NULL, NULL);
li->ld = NULL; li->ld = NULL;
} }
@ -726,14 +729,18 @@ static ber_slen_t
ldapsb_tls_read(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len) ldapsb_tls_read(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
{ {
struct Curl_easy *data = sbiod->sbiod_pvt; struct Curl_easy *data = sbiod->sbiod_pvt;
struct connectdata *conn = data->conn; ber_slen_t ret = 0;
struct ldapconninfo *li = conn->proto.ldapc; if(data) {
ber_slen_t ret; struct connectdata *conn = data->conn;
CURLcode err = CURLE_RECV_ERROR; if(conn) {
struct ldapconninfo *li = conn->proto.ldapc;
CURLcode err = CURLE_RECV_ERROR;
ret = (li->recv)(data, FIRSTSOCKET, buf, len, &err); ret = (li->recv)(data, FIRSTSOCKET, buf, len, &err);
if(ret < 0 && err == CURLE_AGAIN) { if(ret < 0 && err == CURLE_AGAIN) {
SET_SOCKERRNO(EWOULDBLOCK); SET_SOCKERRNO(EWOULDBLOCK);
}
}
} }
return ret; return ret;
} }
@ -742,14 +749,17 @@ static ber_slen_t
ldapsb_tls_write(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len) ldapsb_tls_write(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
{ {
struct Curl_easy *data = sbiod->sbiod_pvt; struct Curl_easy *data = sbiod->sbiod_pvt;
struct connectdata *conn = data->conn; ber_slen_t ret = 0;
struct ldapconninfo *li = conn->proto.ldapc; if(data) {
ber_slen_t ret; struct connectdata *conn = data->conn;
CURLcode err = CURLE_SEND_ERROR; if(conn) {
struct ldapconninfo *li = conn->proto.ldapc;
ret = (li->send)(data, FIRSTSOCKET, buf, len, &err); CURLcode err = CURLE_SEND_ERROR;
if(ret < 0 && err == CURLE_AGAIN) { ret = (li->send)(data, FIRSTSOCKET, buf, len, &err);
SET_SOCKERRNO(EWOULDBLOCK); if(ret < 0 && err == CURLE_AGAIN) {
SET_SOCKERRNO(EWOULDBLOCK);
}
}
} }
return ret; return ret;
} }