Skip to content

Misbahaving client causes program crash due to exception in send.c #676

@qt1

Description

@qt1

A misbehaving client triggers an exception in send.c, probably because prematurely closing the server->client stream.

As a result the program terminates.

It should be possible to set a try-catch block that will prevent the server stopping .
I did not find a way in the docs.

Call Stack:
libpthread.so.0!__libc_send(int flags, size_t len, const void * buf, int fd) (/build/glibc-ZN95T4/glibc-2.31/sysdeps/unix/sysv/linux/send.c:28)
libpthread.so.0!__libc_send(int fd, const void * buf, size_t len, int flags) (/build/glibc-ZN95T4/glibc-2.31/sysdeps/unix/sysv/linux/send.c:23)
httplib::detail::SocketStream::write(char const*, unsigned long)::{lambda()#1}::operator()() const(const httplib::detail::SocketStream::<lambda()> * const __closure) (/home/baruch/w/eneltec/tunnel-control-service/vendor/cpp-httplib/httplib.h:3693)
httplib::detail::handle_EINTR<httplib::detail::SocketStream::write(char const*, unsigned long)::{lambda()#1}>(httplib::detail::SocketStream::write(char const*, unsigned long)::{lambda()#1})(httplib::detail::SocketStream::<lambda()> fn) (/home/baruch/w/eneltec/tunnel-control-service/vendor/cpp-httplib/httplib.h:1558)
httplib::detail::SocketStream::write(httplib::detail::SocketStream * const this, const char * ptr, size_t size) (/home/baruch/w/eneltec/tunnel-control-service/vendor/cpp-httplib/httplib.h:3693)
httplib::Stream::write(httplib::Stream * const this, const std::string & s) (/home/baruch/w/eneltec/tunnel-control-service/vendor/cpp-httplib/httplib.h:3612)
httplib::Server::write_response(httplib::Server * const this, httplib::Stream & strm, bool close_connection, const httplib::Request & req, httplib::Response & res) (/home/baruch/w/eneltec/tunnel-control-service/vendor/cpp-httplib/httplib.h:4061)
httplib::Server::process_request(httplib::Stream&, bool, bool&, std::function<void (httplib::Request&)> const&)(httplib::Server * const this, httplib::Stream & strm, bool close_connection, bool & connection_closed, const std::function<void(httplib::Request&)> & setup_request) (/home/baruch/w/eneltec/tunnel-control-service/vendor/cpp-httplib/httplib.h:4532)
httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1}::operator()(httplib::Stream&, bool, bool&) const(const httplib::Server::<lambda(httplib::Stream&, bool, bool&)> * const __closure, httplib::Stream & strm, bool close_connection, bool & connection_closed) (/home/baruch/w/eneltec/tunnel-control-service/vendor/cpp-httplib/httplib.h:4542)
httplib::detail::process_server_socket<httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1}>(int, unsigned long, long, long, long, long, httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1})::{lambda(bool, bool)#1}::operator()(bool, bool) const(const httplib::detail::<lambda(bool, bool)> * const this, bool close_connection, bool connection_closed) (/home/baruch/w/eneltec/tunnel-control-service/vendor/cpp-httplib/httplib.h:1768)
httplib::detail::process_server_socket_core<httplib::detail::process_server_socket<httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1}>(int, unsigned long, long, long, long, long, httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1})::{lambda(bool, bool)#1}>(int, unsigned long, httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1})(socket_t sock, size_t keep_alive_max_count, httplib::detail::<lambda(bool, bool)> callback) (/home/baruch/w/eneltec/tunnel-control-service/vendor/cpp-httplib/httplib.h:1750)
httplib::detail::process_server_socket<httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1}>(int, unsigned long, long, long, long, long, httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1})(socket_t sock, size_t keep_alive_max_count, time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec, time_t write_timeout_usec, httplib::Server::<lambda(httplib::Stream&, bool, bool&)> callback) (/home/baruch/w/eneltec/tunnel-control-service/vendor/cpp-httplib/httplib.h:1763)
httplib::Server::process_and_close_socket(httplib::Server * const this, socket_t sock) (/home/baruch/w/eneltec/tunnel-control-service/vendor/cpp-httplib/httplib.h:4538)
httplib::Server::listen_internal()::{lambda()#1}::operator()() const(const httplib::Server::<lambda()> * const __closure) (/home/baruch/w/eneltec/tunnel-control-service/vendor/cpp-httplib/httplib.h:4341)
std::_Function_handler<void (), httplib::Server::listen_internal()::{lambda()#1}>::_M_invoke(std::_Any_data const&)(const std::_Any_data & __functor) (/usr/include/c++/9/bits/std_function.h:300)
std::function<void ()>::operator()() const(const std::function<void()> * const this) (/usr/include/c++/9/bits/std_function.h:688)
httplib::ThreadPool::worker::operator()(httplib::ThreadPool::worker * const this) (/home/baruch/w/eneltec/tunnel-control-service/vendor/cpp-httplib/httplib.h:514)
std::__invoke_impl<void, httplib::ThreadPool::worker>(httplib::ThreadPool::worker && __f) (/usr/include/c++/9/bits/invoke.h:60)
std::__invokehttplib::ThreadPool::worker(httplib::ThreadPool::worker && __fn) (/usr/include/c++/9/bits/invoke.h:95)
std::thread::_Invoker<std::tuplehttplib::ThreadPool::worker >::_M_invoke<0ul>(std::thread::_Invoker<std::tuplehttplib::ThreadPool::worker > * const this) (/usr/include/c++/9/thread:244)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions