Commit graph

85 commits

Author SHA1 Message Date
Ashod Nakashian
b9eb4111ae wsd: http: define named HTTP status codes
This replaces the hard-coded status-code
numbers with named compile-time constants.

Change-Id: Ibe678fb2c533b29efd696e4430f5377523eeb298
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-01-24 07:58:07 -05:00
Ashod Nakashian
b644904448 wsd: asyncRequest needs only wakeup its own poll thread
Apparently it woke up the world unnecessarily.

Change-Id: Iad65215da898b017860e7d7b803771f657a3e1ab
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-12-21 19:41:38 -05:00
Ashod Nakashian
7a74227164 wsd: http: improved logs
Change-Id: I075c1069b489b45283cfac75d8c8c90543a10644
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-11-28 12:50:36 +01:00
Michael Meeks
ac1c386c37 Tag polls correctly as running synchronously in the client thread.
This avoids wakeup warning us that the thread is not started to wakeup.

Change-Id: Ifd5c483717024cb1c30521433d0d10acead01e2f
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2022-11-21 18:54:35 -05:00
Ashod Nakashian
7bf0e980bb wsd: http: correct written data-size reporting
Change-Id: I9268b0c8bd99c1f06d20916503f7df7cdbde0cc4
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-11-21 08:45:34 -05:00
Ashod Nakashian
76ac5d09c2 wsd: support embedded media
Change-Id: I28c1a813bad22c49ae759b89ad90e377890acddb
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-10-25 09:16:36 +02:00
Aron Budea
c4975d01e5 Split config.h into separate headers to avoid extensive rebuild
Eg. if only the version was changed, config.h was updated, and
everything was recompiled.

New structure, maintain these manually:
config.h.in - for configured variables that are stable if
              configuration parameters are unchanged
config_version.h.in - for version/hash related variables

----
config_unused.h.in - still generated by autoheader with all
                     variables, don't use it

Signed-off-by: Aron Budea <aron.budea@collabora.com>
Change-Id: Id9a50a9f1e798a3b3814778d8683b7d7cb57bb29
2022-09-05 12:32:49 +01:00
Andras Timar
cf6e22c22c Fix typos in comments
Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I813f652b516c79f350b46317e589b91e0ef39a1a
2022-08-23 18:37:44 +02:00
Ashod Nakashian
81399bff64 fuzzers: fixup HttpEcho
This improves the performance of fuzzing
and removes the checks that can't be guaranteed.

And fixes a test failure.

Change-Id: I987fe15b098c00d9a3d60077f0581d2ef35e306c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-08-17 08:55:12 -04:00
Ashod Nakashian
eca9b0bb4e wsd: http: check for timeout in sync requests
This should cap the loop either when we timeout
or when termination is flagged.

Change-Id: I78a6b05df99d6bac5286e4b1e4957829ea91c500
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-08-17 08:55:12 -04:00
Ashod Nakashian
a87d1ae54f wsd: add HttpEcho fuzzer
This is a full round-trip http fuzzer.
It can achieve >1000 iterations per second
on a single 2 Ghz core, even while going
through the network loopback layer.
The advantage is that more networking code
is fuzzed this way, including not just
the http code, but also the sockets.

Change-Id: I75d21bd0e25221ee6621097a2605d62c4bb2ae4d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-08-17 08:55:12 -04:00
Aron Budea
d30b423c07 Replace #ifdef-s with #if-s, and enable -Wundef
...for variables coming from configure.ac.

Signed-off-by: Aron Budea <aron.budea@collabora.com>
Change-Id: I39ebd21c4cb56d2a3bd38fdc35dc59b5f1fd4b49
2022-08-03 11:07:38 +02:00
Ashod Nakashian
068907c7dd wsd: http: do not assert on net::connect returning nullptr
Apparently this is an issue for proxy.php.

Change-Id: I18090f17f22fe3145e7fa2364992a34a7e722f1b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-07-03 18:03:35 -04:00
Henry Castro
92b2d9f6aa net: add "response" getter function
non constant.

Change-Id: I08c74100003f294ea5a513273507cfea548807eb
Signed-off-by: Henry Castro <hcastro@collabora.com>
2022-06-27 16:04:32 +01:00
Henry Castro
342a42997a net: add getter funtion "getUrl"
Change-Id: I23dd49f8f6dac784961395c6bb38e56d215b8387
Signed-off-by: Henry Castro <hcastro@collabora.com>
2022-06-27 16:04:32 +01:00
Ashod Nakashian
67c3b9548d wsd: http: support shutting down the socket
Change-Id: I9559a126048abd79db37579b5a9ca7282b0485e5
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-24 07:08:55 +01:00
Ashod Nakashian
48b510d4f4 wsd: test: fix heap-use-after-free
In HttpRequestTests::test500GetStatuses, since we reused
the http::Session without removing from SocketPoll,
it is possible for the poll thread to access the
Session object while we create a new request, where
we replace its Response and Socket members.

To avoid that, we can try to remove the http::Session
instance from the SocketPoll. Alternatively, we
can create a new one for each request, which is
what we do here.

Below is the results of ASan, for the record.

==949494==ERROR: AddressSanitizer: heap-use-after-free on address 0x61700005afe0 at pc 0x55dc0c092c75 bp 0x7f8b539e5a10 sp 0x7f8b539e5a08
READ of size 4 at 0x61700005afe0 thread T10 (HttpAsyncReqPol)
    #0 0x55dc0c092c74 in http::Response::logPrefix(std::ostream&) const /home/ash/prj/lo/online/test/../net/HttpRequest.hpp:835:66
    #1 0x55dc0c08f499 in http::Response::readData(char const*, long) /home/ash/prj/lo/online/test/../net/HttpRequest.cpp:641:5
    #2 0x55dc0c0998c9 in http::Session::handleIncomingMessage(SocketDisposition&) /home/ash/prj/lo/online/test/../net/HttpRequest.hpp:1248:41
    #3 0x55dc0c0f0c3b in StreamSocket::handlePoll(SocketDisposition&, std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, int) /home/ash/prj/lo/online/test/../net/Socket.hpp:1339:33
    #4 0x55dc0c0b092d in SocketPoll::poll(long) /home/ash/prj/lo/online/test/../net/Socket.cpp:444:34
    #5 0x55dc0c10407c in SocketPoll::poll(std::chrono::duration<long, std::ratio<1l, 1000000l> >) /home/ash/prj/lo/online/test/../net/Socket.hpp:691:61
    #6 0x55dc0c10407c in SocketPoll::pollingThread() /home/ash/prj/lo/online/test/../net/Socket.hpp:648:13
    #7 0x55dc0c0ac445 in SocketPoll::pollingThreadEntry() /home/ash/prj/lo/online/test/../net/Socket.cpp:299:9
    #8 0x55dc0c12b6b9 in void std::__invoke_impl<void, void (SocketPoll::*)(), SocketPoll*>(std::__invoke_memfun_deref, void (SocketPoll::*&&)(), SocketPoll*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:73:14
    #9 0x55dc0c12b590 in std::__invoke_result<void (SocketPoll::*)(), SocketPoll*>::type std::__invoke<void (SocketPoll::*)(), SocketPoll*>(void (SocketPoll::*&&)(), SocketPoll*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:95:14
    #10 0x55dc0c12b574 in void std:🧵:_Invoker<std::tuple<void (SocketPoll::*)(), SocketPoll*> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:264:13
    #11 0x55dc0c12b463 in std:🧵:_Invoker<std::tuple<void (SocketPoll::*)(), SocketPoll*> >::operator()() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:271:11
    #12 0x55dc0c12b463 in std:🧵:_State_impl<std:🧵:_Invoker<std::tuple<void (SocketPoll::*)(), SocketPoll*> > >::_M_run() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:215:13
    #13 0x7f8b5a08cde3  (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xd6de3) (BuildId: c90e6603c7cdf84713cd445700a575d3ea446d9b)
    #14 0x7f8b59e4c608 in start_thread /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477:8
    #15 0x7f8b59d44132 in __clone /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95

0x61700005afe0 is located 736 bytes inside of 744-byte region [0x61700005ad00,0x61700005afe8)
freed by thread T0 here:
LLVMSymbolizer: error reading file: No such file or directory
    #0 0x55dc0bfe43dd in operator delete(void*) (/home/ash/prj/lo/online/test/unithttplib+0x20d3dd) (BuildId: 7954f6bea5efa6c39ca02e7033c014e826b9f5fd)
    #1 0x55dc0c1fe168 in std::_Sp_counted_ptr<http::Response*, (__gnu_cxx::_Lock_policy)2>::_M_dispose() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr_base.h:380:9
    #2 0x55dc0c033768 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr_base.h:158:6
    #3 0x55dc0c0335d5 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr_base.h:733:11
    #4 0x55dc0c1f972c in std::__shared_ptr<http::Response, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr_base.h:1183:31
    #5 0x55dc0c1f972c in std::enable_if<__sp_is_constructible<http::Response, http::Response>::value, void>::type std::__shared_ptr<http::Response, (__gnu_cxx::_Lock_policy)2>::reset<http::Response>(http::Response*) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr_base.h:1309:4
    #6 0x55dc0c1f972c in http::Session::newRequest(http::Request) /home/ash/prj/lo/online/test/../net/HttpRequest.hpp:1174:19
    #7 0x55dc0c1ee08b in http::Session::asyncRequest(http::Request const&, SocketPoll&) /home/ash/prj/lo/online/test/../net/HttpRequest.hpp:1079:9
    #8 0x55dc0c1b718f in HttpRequestTests::test500GetStatuses() /home/ash/prj/lo/online/test/HttpRequestTests.cpp:515:9
    #9 0x55dc0c219ec9 in void std::__invoke_impl<void, void (HttpRequestTests::*&)(), HttpRequestTests*&>(std::__invoke_memfun_deref, void (HttpRequestTests::*&)(), HttpRequestTests*&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:73:14
    #10 0x55dc0c219de0 in std::__invoke_result<void (HttpRequestTests::*&)(), HttpRequestTests*&>::type std::__invoke<void (HttpRequestTests::*&)(), HttpRequestTests*&>(void (HttpRequestTests::*&)(), HttpRequestTests*&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:95:14
    #11 0x55dc0c219dbc in void std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>::__call<void, 0ul>(std::tuple<>&&, std::_Index_tuple<0ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/functional:416:11
    #12 0x55dc0c219d47 in void std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>::operator()<void>() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/functional:499:17
    #13 0x55dc0c219d47 in void std::__invoke_impl<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>(std::__invoke_other, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:60:14
    #14 0x55dc0c219d47 in std::enable_if<is_invocable_r_v<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>, void>::type std::__invoke_r<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>(std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:110:2
    #15 0x55dc0c219a72 in std::_Function_handler<void (), std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()> >::_M_invoke(std::_Any_data const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:291:9
    #16 0x55dc0c09776b in std::function<void ()>::operator()() const /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:622:14
    #17 0x55dc0c219713 in CppUnit::TestCaller<HttpRequestTests>::runTest() /usr/include/cppunit/TestCaller.h:175:7
    #18 0x7f8b5ab23614 in CppUnit::TestCaseMethodFunctor::operator()() const (/usr/lib/x86_64-linux-gnu/libcppunit-1.15.so.1+0x24614) (BuildId: 4329d55843a6cf32b3e88d4d9aec95035315b163)
    #19 0x7ffdc354a41f  ([stack]+0x2b41f)

previously allocated by thread T0 here:
    #0 0x55dc0bfe3b7d in operator new(unsigned long) (/home/ash/prj/lo/online/test/unithttplib+0x20cb7d) (BuildId: 7954f6bea5efa6c39ca02e7033c014e826b9f5fd)
    #1 0x55dc0c1f969c in http::Session::newRequest(http::Request) /home/ash/prj/lo/online/test/../net/HttpRequest.hpp:1174:25
    #2 0x55dc0c1ee08b in http::Session::asyncRequest(http::Request const&, SocketPoll&) /home/ash/prj/lo/online/test/../net/HttpRequest.hpp:1079:9
    #3 0x55dc0c1b718f in HttpRequestTests::test500GetStatuses() /home/ash/prj/lo/online/test/HttpRequestTests.cpp:515:9
    #4 0x55dc0c219ec9 in void std::__invoke_impl<void, void (HttpRequestTests::*&)(), HttpRequestTests*&>(std::__invoke_memfun_deref, void (HttpRequestTests::*&)(), HttpRequestTests*&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:73:14
    #5 0x55dc0c219de0 in std::__invoke_result<void (HttpRequestTests::*&)(), HttpRequestTests*&>::type std::__invoke<void (HttpRequestTests::*&)(), HttpRequestTests*&>(void (HttpRequestTests::*&)(), HttpRequestTests*&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:95:14
    #6 0x55dc0c219dbc in void std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>::__call<void, 0ul>(std::tuple<>&&, std::_Index_tuple<0ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/functional:416:11
    #7 0x55dc0c219d47 in void std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>::operator()<void>() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/functional:499:17
    #8 0x55dc0c219d47 in void std::__invoke_impl<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>(std::__invoke_other, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:60:14
    #9 0x55dc0c219d47 in std::enable_if<is_invocable_r_v<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>, void>::type std::__invoke_r<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>(std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:110:2
    #10 0x55dc0c219a72 in std::_Function_handler<void (), std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()> >::_M_invoke(std::_Any_data const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:291:9
    #11 0x55dc0c09776b in std::function<void ()>::operator()() const /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:622:14
    #12 0x55dc0c219713 in CppUnit::TestCaller<HttpRequestTests>::runTest() /usr/include/cppunit/TestCaller.h:175:7
    #13 0x7f8b5ab23614 in CppUnit::TestCaseMethodFunctor::operator()() const (/usr/lib/x86_64-linux-gnu/libcppunit-1.15.so.1+0x24614) (BuildId: 4329d55843a6cf32b3e88d4d9aec95035315b163)
    #14 0x7ffdc354a41f  ([stack]+0x2b41f)

Thread T10 (HttpAsyncReqPol) created by T0 here:
    #0 0x55dc0bf922bc in __interceptor_pthread_create (/home/ash/prj/lo/online/test/unithttplib+0x1bb2bc) (BuildId: 7954f6bea5efa6c39ca02e7033c014e826b9f5fd)
    #1 0x7f8b5a08d0a8 in std:🧵:_M_start_thread(std::unique_ptr<std:🧵:_State, std::default_delete<std:🧵:_State> >, void (*)()) (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xd70a8) (BuildId: c90e6603c7cdf84713cd445700a575d3ea446d9b)
    #2 0x55dc0c0aa467 in SocketPoll::startThread() /home/ash/prj/lo/online/test/../net/Socket.cpp:238:23
    #3 0x55dc0c1b57b3 in HttpRequestTests::test500GetStatuses() /home/ash/prj/lo/online/test/HttpRequestTests.cpp:482:16
    #4 0x55dc0c219ec9 in void std::__invoke_impl<void, void (HttpRequestTests::*&)(), HttpRequestTests*&>(std::__invoke_memfun_deref, void (HttpRequestTests::*&)(), HttpRequestTests*&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:73:14
    #5 0x55dc0c219de0 in std::__invoke_result<void (HttpRequestTests::*&)(), HttpRequestTests*&>::type std::__invoke<void (HttpRequestTests::*&)(), HttpRequestTests*&>(void (HttpRequestTests::*&)(), HttpRequestTests*&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:95:14
    #6 0x55dc0c219dbc in void std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>::__call<void, 0ul>(std::tuple<>&&, std::_Index_tuple<0ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/functional:416:11
    #7 0x55dc0c219d47 in void std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>::operator()<void>() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/functional:499:17
    #8 0x55dc0c219d47 in void std::__invoke_impl<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>(std::__invoke_other, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:60:14
    #9 0x55dc0c219d47 in std::enable_if<is_invocable_r_v<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>, void>::type std::__invoke_r<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>(std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:110:2
    #10 0x55dc0c219a72 in std::_Function_handler<void (), std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()> >::_M_invoke(std::_Any_data const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:291:9
    #11 0x55dc0c09776b in std::function<void ()>::operator()() const /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:622:14
    #12 0x55dc0c219713 in CppUnit::TestCaller<HttpRequestTests>::runTest() /usr/include/cppunit/TestCaller.h:175:7
    #13 0x7f8b5ab23614 in CppUnit::TestCaseMethodFunctor::operator()() const (/usr/lib/x86_64-linux-gnu/libcppunit-1.15.so.1+0x24614) (BuildId: 4329d55843a6cf32b3e88d4d9aec95035315b163)
    #14 0x7ffdc354a41f  ([stack]+0x2b41f)

SUMMARY: AddressSanitizer: heap-use-after-free /home/ash/prj/lo/online/test/../net/HttpRequest.hpp:835:66 in http::Response::logPrefix(std::ostream&) const
Shadow bytes around the buggy address:
  0x0c2e800035a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2e800035b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2e800035c0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2e800035d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2e800035e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
=>0x0c2e800035f0: fd fd fd fd fd fd fd fd fd fd fd fd[fd]fa fa fa
  0x0c2e80003600: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c2e80003610: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2e80003620: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2e80003630: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2e80003640: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==949494==ABORTING

Change-Id: I5e1539c3adbab9b5027d84cc1dbab4b90271c458
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-24 07:08:55 +01:00
Ashod Nakashian
3b9cc13b7a wsd: improved socket logging
More consistent logging of the socket FD.

Change-Id: Iee24ad4eb067969abfc06f78a768563351d264c7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-07 09:09:00 +01:00
Ashod Nakashian
1da8d6dd24 wsd: use STATE_ENUM for http
Change-Id: Iaacf03856b9a07286f4fdf1f1eac34f2b75d2244
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-06 18:33:45 -04:00
Ashod Nakashian
e164cb4a4d wsd: trace poll events and revents flags arround ppoll
Change-Id: If6aedff69a6421a16eec9f86fed6d0ea381ecc0c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-21 08:57:41 +00:00
Ashod Nakashian
f74192d9ac wsd: always include the BIO errors in SSL logs
And improved socket logging in general while
making them more consistent.

Change-Id: I1ed7f2561476ca5370af91079d5d616804396f8e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-21 08:57:41 +00:00
Andras Timar
f07ff8c7e0 rename: remaining lool->cool changes
Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: Ib7d4e804bebe52dead8d53b0e0bbaed0f08bf3d0
2021-11-18 14:14:11 +01:00
Luboš Luňák
897c5df270 make Socket use Buffer for input buffer too
SteamSocket::eraseFirstInputBytes() removes from the beginning
of std::vector, which is generally slow. If the buffer becomes
too big, which it may under a load, then the function will get
slow, which in turn will likely lead to the buffer getting even
bigger because of accumulated backlog.

The Buffer class is optimized for removal at the beginning,
so use it instead of std::vector, including some API additions
for it to be an in-place replacement where it's used.

Signed-off-by: Luboš Luňák <l.lunak@collabora.com>
Change-Id: I4cf7ec56c908c7d3df391dc3f8e230ad32abb162
2021-10-26 12:11:58 +02:00
Ashod Nakashian
347fd43f7c wsd: chunked transfer and tests
Change-Id: I07f7f126891f4d6b5137b45bf91cbcaa11796cda
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 866cb8f2f25e958f834adc51e2191fb60e2e85b9)
2021-09-26 17:02:01 -04:00
Michael Meeks
e0d7337877 Host: header don't append port for standard ports.
HA Proxy doesn't tolerate this very happily cf.

https: //serverfault.com/questions/502443/ignore-port-numbers-in-haproxy-host-header-matches/502630
Change-Id: Id285f8acd0e168a734cabd9eccc4a01fe323ab84
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-08-13 09:36:27 +05:30
Ashod Nakashian
823f349383 wsd: http: break cyclic dependency
The Socket instance owns the protocol handler
by design. This implies that the Session,
which is also the protocol handler, cannot
itself own the Socket.

Here we change that ownership into a weak_ptr
and pass the exclusive ownership of the Socket
to SocketPoll. We track the connection state,
so we can create a new socket when we are
disconnected.

Change-Id: Id6bf6506b0c8e2e0564f91977e1e7189d934a68f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-14 23:02:39 -04:00
Ashod Nakashian
7b32b96a08 wsd: http: better logs
Change-Id: I790308c872ca9c20c4b29a04deae19059ca36818
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 21:57:43 -04:00
Ashod Nakashian
74e575de4b wsd: http: always destroy the socket last
When the socket is destroyed, it may invoke
the onDisconnect handler, which updates
the Response instance. If the order of
destruction is incorrect, we may have
a null instance.

Also make the State atomic to make sure
its visibility is consistent across threads.
The shared_ptr instances will fence and will
always be consistently visible across threads,
but if the State isn't in sync, then we can
seem to have an inconsistent state. The State
instance will be set and accessed from different
threads in an async request.

Change-Id: Ia2a48285d140646f3640f59634e14a46e4a4d640
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
513e33582f wsd: http: an incomplete response is an error
If we haven't had a complete response or a timeout,
then we have an incomplete transmission, which is
an error.

Change-Id: I1b775760186021e0a704eba2c9f3647efa4f5ed0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
bbb4fe14ae wsd: http: sync requests accept external poller
Reusing a SocketPoll is encouraged rather than
creating throwaway instances. Session now supports
external SocketPoll instances for the sync members
as it does for the async (which is unavoidable).

Also, use TerminatingPoll to break the poll
when the terminating the process is flagged.

Change-Id: Ide6f674080ce20bb764c482871e48c94d83d4214
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
b8c3e97cc6 wsd: better handling of invalid port in URL
Detect invalid port values and error out.

Change-Id: If45bcacaf64f48356147aa5461bcd2e30b7c7ea1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
dbf45e8641 wsd: http: performWrites can be called after destroying the socket
Change-Id: Ieb745a7706bf57c9bd16995e1f1336f7053ab30c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
aea70a563c wsd: http: disconnect if the server closed the socket
Change-Id: If00566939708d71482a8aac8e97cc371a4a381fd
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-06 22:14:51 -04:00
Ashod Nakashian
a0696403a9 wsd: http: complete the http response only once
Change-Id: I2c015f004883272bb6efe4ffc5a14e3cc101f60f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-06 22:14:51 -04:00
Ashod Nakashian
a0549fd7cc wsd: http: simplify http::get
Change-Id: Id94d2e7340b393bd4a42f5108621f16b46a0ee9b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-02 22:35:39 -04:00
Ashod Nakashian
117db770cd wsd: http: add isConnected getter to http::Session
Change-Id: Iad12f00f9ced434d4e1493aba03be98a3cd7f2ab
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-02 22:35:39 -04:00
Ashod Nakashian
ea12aa7635 wsd: http: braces always on new line
Seems like this was a bug in clang-format
that is fixed in clang-12.

Change-Id: I8144179d2b290f5d875af41dbd44dedcf4152639
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-02 22:35:39 -04:00
Ashod Nakashian
dc5ca2738e wsd: http: simplify appending to Buffer
Instead of supporting char appending,
we now support appending literal strings
with size capturing. This covers both
single- and multi-character appending
without the need for an explicit size.

Change-Id: Iee2c20b7aa2cdb6863c88e91cd770205719c2ba6
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 96e3e88a014960a5249fc83a5b2f3b785ac8737d)
2021-05-02 22:35:39 -04:00
Miklos Vajna
656eb310bb Fix Debian 8 / gcc-4.9 warnings
net/HttpRequest.cpp:126:19: error: declaration of 'end' shadows a member of 'this' [-Werror=shadow]

kit/Kit.cpp:163:29: error: missing initializer for member 'statfs::f_bsize' [-Werror=missing-field-initializers]

kit/Kit.cpp:171:14: error: 'OVERLAYFS_SUPER_MAGIC' was not declared in this scope

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Ibbd35ab5af3adad403ed22a0aeb70917b9e21970
2021-04-30 10:38:09 +02:00
Ashod Nakashian
352840c0ea wsd: http: larger 64kb upload-file read buffer
Change-Id: Ie9a0e6f76425d796979dbc77eecf1b05993b834d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 34f629c6adc5bb6eb93fd8c813d72ee923d09a05)
2021-04-27 17:48:23 -04:00
Ashod Nakashian
3decba7eec wsd: specify the minimum bytes we can write to the socket
When writing to the socket, it's always more efficient
to fill the buffer up to the hardware limit for each
write. This is doubly important for efficiency with
SSL, due to the overhead of encrypting multiple
small buffers instead of one large one.

Currently we don't write more than one message
at a time, primarily due to limitations in
the Poco sockets in the unit-tests, which
have a hard time consuming multiple WS frames
with a single poll (subsequent calls to poll
doesn't enter signalled state until new data
arrives, possibly because the data is read and
buffered internally, making the whole scheme
of using poll unreliable and meaningless).

Change-Id: Ic2e2cf1babfb5ab4116efd93f392977ba234d92b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 17:48:23 -04:00
Miklos Vajna
9afe974848 Add a fuzzer for http::Response::readData()
And remove the httpheader one, which is not useful, since it uses Poco
for the actual parsing, it did not find anything. (If we switch away
from Poco there in the future, it's easy enough to restore it.)

Also fix some problems found by the fuzzer.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I254247c46ecc78c9c3e75aac4f10c441b0e10fb3
2021-04-23 17:54:36 +02:00
Ashod Nakashian
1239685620 wsd: http: explicit Request constructor and Header arg
Change-Id: Ief228862d882ae96650708e30442693cc127f0c9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
d9fa64b4a0 wsd: http: support http Connection: close header
According to the RFC, HTTP/1.1 assumes persistent
connection unless the client or server sends
'Connection: close' header. See
https://tools.ietf.org/html/rfc7230#section-6.3

Now we fully support disconnecting when we
get this header, which is important for when
reusing the same http::Session (we need to
reconnect in such a case).

Change-Id: Ib278eff21be32c1414478296e90e2e807ab24132
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
4b43b3cd6e wsd: http: set the port in the Host header entry
Change-Id: I2d46c1ef3b72e21ce8924dcf7616cd26fb5bc98d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
41275f0423 wsd: http: new syncRequest with timeout and new helper
Change-Id: I64a5d6f0984b9f35fe0224683527d80cf77fff99
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
2bb07adb54 wsd: http: simplify syncRequest to return Response
Since the return value of syncRequest and syncDownload
was derived from Response anyway, there is no reason
to have multiple values for callers to look at.

This simplifies the API.

Change-Id: I0f136e515dd0ef6eda84f6a7cd662b260809d2f1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
8aa329c17d wsd: http: default Session timeout is now public
Change-Id: I34376a68a130ccb0d36f04b90ff26af1a1535873
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
45b15803ad wsd: http: use std::move
Change-Id: I3c287b96ccce5f8b3cb245c065922a9c35df5bf7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
fb6e7793ff wsd: http: use parseUri
Change-Id: I5c1e95acb30509f2b1865da31a8a0e622a94c4e3
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00