Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in curl_multi_fdset() #7718

Closed
0xee opened this issue Sep 14, 2021 · 3 comments
Closed

Crash in curl_multi_fdset() #7718

0xee opened this issue Sep 14, 2021 · 3 comments
Assignees
Labels

Comments

@0xee
Copy link

@0xee 0xee commented Sep 14, 2021

I did this

Used curl v7.78.0 with xmlrpc-c (which calls curl_multi_fdset()) in an application with more than 1023 open file descriptors.

I expected the following

No crash (but got memory corruption)

curl/libcurl version

curl 7.78.0 (x86_64-conda-linux-gnu) libcurl/7.78.0 OpenSSL/1.1.1k zlib/1.2.11 libssh2/1.9.0 nghttp2/1.43.0
Release-Date: 2021-07-21

Obtained curl from conda-forge:

# Name                    Version                   Build  Channel
libcurl                   7.78.0               h2574ce0_0    conda-forge

operating system

Linux 031b5845863a 3.10.0-1160.25.1.el7.x86_64 #1 SMP Wed Apr 28 21:49:45 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Problem

xmlrpc-c uses curl_multi_fdset() unconditionally (whether or not HAVE_FINE_POLL is set while building curl). #7241 disabled checking the file descriptor values against FD_SETSIZE when HAVE_FINE_POLL is defined. I guess this is fine for curl itself, because it probably doesn't call curl_multi_fdset() when using poll() instead of select(), but calling curl_multi_fdset() in an application with more than FD_SETSIZE file descriptors, might now result in memory corruption.

If this behavior is intended (i.e. curl_multi_fdset() is not safe to be called when HAVE_FINE_POLL is defined), this should at the very least be documented. Specifically this sentence from the curl_multi_fdset() man page is not correct anymore:

If one of the sockets used by libcurl happens to be larger than what can be set
in an fd_set, which on POSIX systems means that the file descriptor is larger
than FD_SETSIZE, then libcurl will try to not set it.

@bagder bagder self-assigned this Sep 14, 2021
@bagder
Copy link
Member

@bagder bagder commented Sep 14, 2021

Indeed, the macro that is supposed to check for this isn't doing the right thing if libcurl is built to use poll(), even though poll is not used in this function...

bagder added a commit that referenced this issue Sep 14, 2021
The VALID_SOCK() macro was made to only check for FD_SETSIZE if curl was
built to use select(), even though the curl_multi_fdset() function
always and unconditionally uses FD_SET and needs the check.

Reported-by: 0xee on github
Fixes #7718
@bagder bagder added the crash label Sep 14, 2021
@bagder
Copy link
Member

@bagder bagder commented Sep 14, 2021

@0xee I made #7719 which I think corrects this. Any comments on that?

@0xee
Copy link
Author

@0xee 0xee commented Sep 15, 2021

Thanks for taking action so quickly! #7719 fixes the issue for me. It also looks correct to me.

@bagder bagder closed this in d5a70e7 Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants