openziti / tlsuv

TLS and HTTP(s) client library for libuv
https://docs.openziti.io/tlsuv/
MIT License
43 stars 5 forks source link

Required to call tlsuv_stream_set_protocol()? #178

Closed plajjan closed 1 year ago

plajjan commented 1 year ago

ISTM that after the merge of ALPN support in #165 we must initialize by setting ALPN protocols, right?

I followed sample.c (https://github.com/openziti/tlsuv/blob/main/sample/sample.c) and ended up with a segfaulting program. It died trying to work with alpn_count & alpn_protocols field in a struct. I don't see those being initialized.

I added two lines to set alpn and it's now working.

    tlsuv_stream_t stream;
    tlsuv_stream_init(get_uv_loop(), &mbed, NULL);
    // Following two lines fixed segfaults and I got a working TLS connection
    const char *alpn[] = { "http/1.1" };
    tlsuv_stream_set_protocols(&mbed, 1, alpn);

I noticed https://github.com/openziti/tlsuv/commit/2e8dd315e80fa091c801390e816fe86027b2dfa3 that fixes the engine sample. Should sample.c also be updated or what is the API here?

I sort of expected tlsuv_stream_init to give me something that at least would not lead to segfault. Feels like ALPN count field should default to 0, i.e. not using ALPN, right?

ekoby commented 1 year ago

this is certainly a bug. thank you for catching it