httpc crashing on particular urls

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

httpc crashing on particular urls

Antti Siponen
Hello everybody, it is my first appearance on this mailing list so feel free to remind me of all the rules I possibly break...

I noticed that in one specific case the inets:httpc request function fails to return a meaningful error and silently crashes instead. This seems to happen when the provided URL scheme is not http or https. I am just an Erlang beginner so I don't expect to be able to provide a good patch, but I have written up a mockup patch that does solve the issue, although the error message it produces is very likely not in line with the conventions used and the code itself is ugly and based only on guesswork from the surrouding code without any real understanding of what I am doing.

Anyway to reproduce the bug you might try to execute the following request on httpc: httpc:request(get, {"broken://erlang.org:80", []}, [], [{sync,false}, {stream, self}, {receiver,fun(X)-> io:format("~p",[X])end}]).

Instead of an error I get {ok, #Ref} and in the background a httpc crash. The same happens on sync requests as well and the erl shell hangs.

The mock fix that I wrote is available here:
https://github.com/lantti/otp/commit/8872f1ca2986757a670f386eba022481f126febc

The main points there to notice are that the function socket_type() fails with a missing clause when an unrecognized URL scheme is introduced and that we are inside the httpc:init where failing is not allowed. So I fixed that by returning an error tuple instead and pattern matching against that tuple at the calling side.

Maybe somebody here would like to take the time to actually write that fix properly.

Thank you,

Antti Siponen

_______________________________________________
erlang-patches mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-patches
Reply | Threaded
Open this post in threaded view
|

Re: httpc crashing on particular urls

Jesper Louis Andersen-2

On Tue, Sep 29, 2015 at 11:29 PM, Antti Siponen <[hidden email]> wrote:

Nice!

While I am not an OTP developer, I know the OTP like to have test cases for fixes. So there is something to think about from the perspective of creating a PR.


--
J.

_______________________________________________
erlang-patches mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-patches
Reply | Threaded
Open this post in threaded view
|

Re: httpc crashing on particular urls

Antti Siponen
In reply to this post by Antti Siponen
On 1 October 2015 at 11:32, Ingela Anderton Andin <[hidden email]> wrote:
I think it could be caught earlier.  I think maybe we should accept PR 846, and then make
httpc define its fun to accept http and https schemes.

Ok, using the URI scheme validation scheme introduced by PR 846 the fix could be as simple as this instead:
 https://github.com/lantti/otp/commit/15714ed9834cdd34ae2456e868546e4d319c50ff

Antti

_______________________________________________
erlang-patches mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-patches