https://bugs.openldap.org/show_bug.cgi?id=9328
Issue ID: 9328 Summary: CLDAP ldap_result hangs if nobody listens on the port Product: OpenLDAP Version: unspecified Hardware: All OS: All Status: UNCONFIRMED Severity: normal Priority: --- Component: libraries Assignee: bugs@openldap.org Reporter: pbrezina@redhat.com Target Milestone: ---
When using LDAP over UDP, calling ldap_result() hangs if there is nobody listening on the remote port.
The problem is that it calls recvfrom() twice, the first attempt returns ECONNREFUSED but this is ignored. The seconds read then blocks/timeouts/returns EAGAIN depending on the sockets settings, however we know that we will never receive any data so it should return an error. See [1]
poll([{fd=20, events=POLLIN|POLLPRI}], 1, 0) = 1 ([{fd=20, revents=POLLERR}]) recvfrom(20, 0x18dade0, 16256, 0, 0x18dad60, [128]) = -1 ECONNREFUSED (Connection refused) recvfrom(20, <unfinished ...>) = ?
[1] https://git.openldap.org/pbrezina/openldap/-/blob/master/libraries/libldap/r...
https://bugs.openldap.org/show_bug.cgi?id=9328
--- Comment #1 from Howard Chu hyc@openldap.org --- (In reply to pbrezina from comment #0)
When using LDAP over UDP, calling ldap_result() hangs if there is nobody listening on the remote port.
The problem is that it calls recvfrom() twice, the first attempt returns ECONNREFUSED but this is ignored. The seconds read then blocks/timeouts/returns EAGAIN depending on the sockets settings, however we know that we will never receive any data so it should return an error. See [1]
poll([{fd=20, events=POLLIN|POLLPRI}], 1, 0) = 1 ([{fd=20, revents=POLLERR}]) recvfrom(20, 0x18dade0, 16256, 0, 0x18dad60, [128]) = -1 ECONNREFUSED (Connection refused) recvfrom(20, <unfinished ...>) = ?
[1] https://git.openldap.org/pbrezina/openldap/-/blob/master/libraries/libldap/ result.c#L489
Need more details on how to reproduce this. On my own run, the poll() hangs since it's called with an infinite timeout. (result.c:1135, ldap_int_select()).
https://bugs.openldap.org/show_bug.cgi?id=9328
--- Comment #2 from pbrezina@redhat.com --- Created attachment 757 --> https://bugs.openldap.org/attachment.cgi?id=757&action=edit Minimal reproducer
$ gcc -ggdb3 -o client ./main.c -lldap $ strace ./client ... sendto(3, "0'\2\1\1\4\0c \4\0\n\1\0\n\1\0\2\1\0\2\1\0\1\1\0\207\vobje"..., 41, 0, {sa_family=AF_INET, sin_port=htons(3333), sin_addr=inet_addr("127.0.0.1")}, 16) = 41 poll([{fd=3, events=POLLIN|POLLPRI}], 1, 1000) = 1 ([{fd=3, revents=POLLERR}]) recvfrom(3, 0x493b10, 16256, 0, 0x493a90, [128]) = -1 ECONNREFUSED (Connection refused) recvfrom(3,
No LDAP server is running at localhost.
https://bugs.openldap.org/show_bug.cgi?id=9328
Howard Chu hyc@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |TEST
--- Comment #3 from Howard Chu hyc@openldap.org --- Thanks, fix is in https://git.openldap.org/openldap/openldap/-/merge_requests/122
https://bugs.openldap.org/show_bug.cgi?id=9328
--- Comment #4 from Quanah Gibson-Mount quanah@openldap.org --- Commits: • e3faae93 by Howard Chu at 2020-08-26T20:53:38+00:00 ITS#9328 cldap: check for error on connected socket
libldap doesn't use a connected socket for UDP sessions, but 3rd parties can, passed in with ldap_init_fd().
https://bugs.openldap.org/show_bug.cgi?id=9328
Quanah Gibson-Mount quanah@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Resolution|TEST |FIXED Target Milestone|--- |2.4.52
--- Comment #5 from Quanah Gibson-Mount quanah@openldap.org --- RE24 fix:
Commits: • ec5eba53 by Howard Chu at 2020-08-26T21:38:17+00:00 ITS#9328 cldap: check for error on connected socket
libldap doesn't use a connected socket for UDP sessions, but 3rd parties can, passed in with ldap_init_fd().
https://bugs.openldap.org/show_bug.cgi?id=9328
--- Comment #6 from pbrezina@redhat.com --- Thank you for prompt resolution.
https://bugs.openldap.org/show_bug.cgi?id=9328
Quanah Gibson-Mount quanah@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |VERIFIED