ikod / dlang-requests

dlang http client library inspired by python-requests
Boost Software License 1.0
156 stars 32 forks source link

Segfault fetching URL, ERR_get_error() returns ERR_get_error() #54

Closed zorael closed 7 years ago

zorael commented 7 years ago
import requests;

void main()
{
    Req req;
    req.get("https://www.humblebundle.com/store");  // segfaults
}

GDB stacktrace is thousands of lines of requests.ssl_adapter.OpenSSL.ERR_get_error() const (this=...) at ../../../.dub/packages/requests-0.5.1/requests/source/requests/ssl_adapter.d:232;

ulong ERR_get_error() const {
    return ERR_get_error();
}
ikod commented 7 years ago

Hello, Thanks for report! What is Req? There is no such object in 'requests'. Do you have openssl libraries installed? If yes - please give me more details on your system

Thanks

PS and please show me stacktrace, it would be helpfull

zorael commented 7 years ago

Sorry, I copied it by hand, it's supposed to be Request.

import requests;

void main()
{
    Request req;
    req.get("https://www.humblebundle.com/store");
}

With only that and dub run:

Performing "debug" build using dmd for x86_64.
requests 0.5.1: building configuration "std"...
/usr/include/dlang/dmd/std/range/primitives.d(1428): Note: length must have type size_t on all systems, please update your code by December 2017.
req ~master: building configuration "application"...
Linking...
Running ./req
Program exited with code -11

Tested on two machines running Arch Linux. OpenSSL 1.1 is installed as 1.1.0-f and alongside it 1.0 as 1.0.2.l.

$ pacman -Q | grep ^openssl
openssl 1.1.0.f-2
openssl-1.0 1.0.2.l-1

GDB backtrace is almost 262 000 frames and way too long to paste, but here is the end (and note frame numbers): https://gist.github.com/zorael/54acdffca7c474f3ad5f2daa963e77f4.

ikod commented 7 years ago

Thanks! this all I need for now, will try to check today what is wrong.

ikod commented 7 years ago

Hello, @zorael

I reproduced this bug and it should be fixed in current master. It was mistype in ERR_get_error() functions which recursively call itself until stack overflows.

But there is some another problem. most likely if you will run you test program you will receive exception about failed ssl connection. The same problem you will receive with openssl commandline tool

$ openssl s_client -host www.humblebundle.com -port 443
CONNECTED(00000003)
140735134244944:error:140790E5:SSL routines:ssl23_write:ssl handshake failure:s23_lib.c:177:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 308 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : 0000
    Session-ID:
    Session-ID-ctx:
    Master-Key:
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1504381066
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
---

Do you have any idea what wrong with this ssl connection?

zorael commented 7 years ago

I don't know, but curiously humblebundle.com (without www) seems to work.

$ openssl s_client -host humblebundle.com -port 443
CONNECTED(00000003)
depth=2 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Certification Authority
verify return:1
depth=1 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Extended Validation Secure Server CA
verify return:1
depth=0 serialNumber = 4903485, jurisdictionC = US, jurisdictionST = Delaware, businessCategory = Private Organization, C = US, postalCode = 94108, ST = CA, L = San Francisco, street = Floor 11, street = 201 Post St, O = "Humble Bundle, Inc.", OU = COMODO EV SSL, CN = www.humblebundle.com
verify return:1
---
Certificate chain
0 s:/serialNumber=4903485/jurisdictionC=US/jurisdictionST=Delaware/businessCategory=Private Organization/C=US/postalCode=94108/ST=CA/L=San Francisco/street=Floor 11/street=201 Post St/O=Humble Bundle, Inc./OU=COMODO EV SSL/CN=www.humblebundle.com
...

It even says CN = www.humblebundle.com... But I don't know enough about certificates.

ikod commented 7 years ago

hi @zorael so there was two distinct problems:

  1. mistype in ERR_get_error, and - which is fixed
  2. abort ssl from the www.humblebundle.com side - looks like humblebundle require ALPN negitiation. I'll try to fix this in next few days.
ikod commented 7 years ago

hello, @zorael

second problem should be fixed in last release, try it please. If everything is ok - I'll close issue.

ikod commented 7 years ago

Hello, I'm closing this issue. Please, feel free to reopen it in case of any problems.