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

don't allow values just below typemax(Clong) in set_timeout #193

Open
manuelbb-upb opened this issue May 10, 2022 · 1 comment
Open

don't allow values just below typemax(Clong) in set_timeout #193

manuelbb-upb opened this issue May 10, 2022 · 1 comment

Comments

@manuelbb-upb
Copy link

The set_timeout function in src/Curl/Easy.jl checks the argument timeout against typemax(Clong).
But (at least in my case) setopt(easy, CURLOPT_TIMEOUT, typemax(Clong)) leads to

Error: curl_easy_setopt: 43

which is a CURL_BAD_FUNCTION_ARGUMENT.
From the C Code I would guess that checking against typemax(Clong) ÷ 1000 is more appropriate.
Simply plugging that in gives:

function set_timeout(easy::Easy, timeout::Real)
    timeout > 0 ||
        throw(ArgumentError("timeout must be positive, got $timeout"))
    _max = typemax(Clong) ÷ 1000
    if timeout  _max
        timeout_ms = round(Clong, timeout * 1000)
        setopt(easy, CURLOPT_TIMEOUT_MS, timeout_ms)
    else
        timeout = timeout  _max ? round(Clong, timeout) : Clong(0)
        setopt(easy, CURLOPT_TIMEOUT, timeout)
    end
end

But the second conditional is redundant and the above is equivalent to

function set_timeout(easy::Easy, timeout::Real)
    timeout > 0 ||
        throw(ArgumentError("timeout must be positive, got $timeout"))
    _max = typemax(Clong) ÷ 1000
    if timeout  _max
        timeout_ms = round(Clong, timeout * 1000)
        setopt(easy, CURLOPT_TIMEOUT_MS, timeout_ms)
    else
        setopt(easy, CURLOPT_TIMEOUT, Clong(0))
    end
end
manuelbb-upb added a commit to manuelbb-upb/gRPCClient.jl that referenced this issue May 10, 2022
manuelbb-upb added a commit to manuelbb-upb/gRPCClient.jl that referenced this issue May 10, 2022
@StefanKarpinski
Copy link
Member

Thanks for the detailed bug report! I'll take a look.

tanmaykm added a commit to JuliaComputing/gRPCClient.jl that referenced this issue Jul 20, 2022
This adds an upper limit to the connect timeout value that can be specified,
to limit it to `typemax(Clong) ÷ 1000`. An `ArgumentError` is thrown if the
value is out of range.

This matches what libcurl expects [here](https://github.com/curl/curl/blob/4a8f6869db3a4ba7cd1bcb153c3d5b4298728afa/lib/setopt.c#L1376).

Originally reported at JuliaLang/Downloads.jl#193 and #23.
tanmaykm added a commit to JuliaComputing/gRPCClient.jl that referenced this issue Jul 20, 2022
This adds an upper limit to the connect timeout value that can be specified,
to limit it to `typemax(Clong) ÷ 1000`. An `ArgumentError` is thrown if the
value is out of range.

This matches what libcurl expects [here](https://github.com/curl/curl/blob/4a8f6869db3a4ba7cd1bcb153c3d5b4298728afa/lib/setopt.c#L1376).

Originally reported at JuliaLang/Downloads.jl#193 and #23.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants