Server crashes if HTTP version cant be casted from string to float
Sending a GET / HTTP/notANumber
request crashes the server due to string to float conversion, this gives std::invalid_argument.
Tested on Ubuntu 20.04
Steps to reproduce:
telnet localhost 8080
GET / HTTP/notANumber
Backtrace
terminate called after throwing an instance of 'std::invalid_argument'
what(): stof
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007ffff7bc8859 in __GI_abort () at abort.c:79
#2 0x00007ffff7e4e951 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff7e5a47c in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff7e5a4e7 in std::terminate() () from /lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ffff7e5a799 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x00007ffff7e5130e in std::__throw_invalid_argument(char const*) () from /lib/x86_64-linux-gnu/libstdc++.so.6
#7 0x00005555556a0cbe in __gnu_cxx::__stoa<float, float, char> (__convf=0x7ffff7bef6b0 <__GI_strtof>, __name=0x555555706036 "stof", __str=0x55555575ae60 "a", __idx=0x0)
at /usr/include/c++/9/ext/string_conversions.h:83
#8 0x000055555569190c in std::__cxx11::stof (__str="a", __idx=0x0) at /usr/include/c++/9/bits/basic_string.h:6530
#9 0x00005555556b1240 in SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::write(std::shared_ptr<SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Session> const&, std::function<void (std::shared_ptr<SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Response>, std::shared_ptr<SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Request>)>&)::{lambda(SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Response*)#1}::operator()(SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Response*) const::{lambda(boost::system::error_code const&)#1}::operator()(boost::system::error_code const) const (this=0x7fffffffdbf0, ec=...)
at /home/madsen/Documents/dataing/TDAT3020 Sikkerhet i programvare og nettverk/ovinger/oving2/buggy-web-server/server_http.hpp:765
#10 0x00005555556bc680 in std::_Function_handler<void (boost::system::error_code const&), SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::write(std::shared_ptr<SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Session> const&, std::function<void (std::shared_ptr<SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Response>, std::shared_ptr<SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Request>)>&)::{lambda(SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Response*)#1}::operator()(SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Response*) const::{lambda(boost::system::error_code const&)#1}>::_M_invoke(std::_Any_data const&, boost::system::error_code const&) (__functor=..., __args#0=...)
at /usr/include/c++/9/bits/std_function.h:300
#11 0x00005555556bc807 in std::function<void (boost::system::error_code const&)>::operator()(boost::system::error_code const&) const (this=0x7fffffffd860, __args#0=...)
at /usr/include/c++/9/bits/std_function.h:688
#12 0x00005555556b710f in SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Response::send_on_delete(std::function<void (boost::system::error_code const&)> const&)::{lambda(boost::system::error_code const&, unsigned long)#1}::operator()(boost::system::error_code const&, unsigned long) const (this=0x7fffffffd850, ec=...)
at /home/madsen/Documents/dataing/TDAT3020 Sikkerhet i programvare og nettverk/ovinger/oving2/buggy-web-server/server_http.hpp:118
#13 0x00005555556d6d9b in boost::asio::detail::write_dynbuf_v1_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::basic_streambuf_ref<std::allocator<char> >, boost::asio::detail::transfer_all_t, SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Response::send_on_delete(std::function<void (boost::system::error_code const&)> const&)::{lambda(boost::system::error_code const&, unsigned long)#1}>::operator()(boost::system::error_code const&, unsigned long, int) (this=0x7fffffffd838, ec=..., bytes_transferred=74, start=0)
at /usr/include/boost/asio/impl/write.hpp:569
#14 0x00005555556f6dd0 in boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::const_buffers_1, boost::asio::const_buffer const*, boost::asio::detail::transfer_all_t, boost::asio::detail::write_dynbuf_v1_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::basic_streambuf_ref<std::allocator<char> >, boost::asio::detail::transfer_all_t, SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Response::send_on_delete(std::function<void (boost::system::error_code const&)> const&)::{lambda(boost::system::error_code const&, unsigned long)#1}> >::operator()(boost::system::error_code const&, unsigned long, int) (this=0x7fffffffd810, ec=..., bytes_transferred=74, start=0)
at /usr/include/boost/asio/impl/write.hpp:338
#15 0x000055555570214a in boost::asio::detail::binder2<boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::const_buffers_1, boost::asio::const_buffer const*, boost::asio::detail::transfer_all_t, boost::asio::detail::write_dynbuf_v1_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::basic_streambuf_ref<std::allocator<char> >, boost::asio::detail::transfer_all_t, SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Response::send_on_delete(std::function<void (boost::system::error_code const&)> const&)::{lambda(boost::system::error_code const&, unsigned long)#1}> >, boost::system::error_code, unsigned long>::operator()() (this=0x7fffffffd810)
at /usr/include/boost/asio/detail/bind_handler.hpp:164
#16 0x0000555555702221 in boost::asio::asio_handler_invoke<boost::asio::detail::binder2<boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::const_buffers_1, boost::asio::const_buffer const*, boost::asio::detail::transfer_all_t, boost::asio::detail::write_dynbuf_v1_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::basic_streambuf_ref<std::allocator<char> >, boost::asio::detail::transfer_all_t, SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Response::send_on_delete(std::function<void (boost::system::error_code const&)> const&)::{lambda(boost::system::error_code const&, unsigned long)#1}> >, boost::system::error_code, unsigned long> >(boost::asio::detail::binder2<boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::const_buffers_1, boost::asio::const_buffer const*, boost::asio::detail::transfer_all_t, boost::asio::detail::write_dynbuf_v1_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::basic_streambuf_ref<std::allocator<char> >, boost::asio::detail::transfer_all_t, SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::Response::send_on_delete(std::function<void (boost::system::error_code const&)> const&)::{lambda(boost::system::error_code const&, unsigned long)#1}> >, boost::system::error_code, unsigned long>&, ...) (function=...) at /usr/include/boost/asio/handler_invoke_hook.hpp:69