pistache: "Stack smashing detected" error in ubuntu docker container
After a system update of our libpistache-dev
install, I am now running into stack smashing warnings like:
*** stack smashing detected ***: terminated
curl: (52) Empty reply from server
[1]+ Aborted ./test 9081
The first version I noticed this behavior was on
$ dpkg -s libpistache-dev | grep Version
Version: 0.2.3.20231022+git20231024.37ce2d4~ubuntu20.04.1
but can also reproduce on the latest release
$ dpkg -s libpistache-dev | grep Version
Version: 0.2.7.20240103+git20240106.1c733a1~ubuntu20.04.1
I was able to distill it down to a simplified MWE
Using the following test file and Dockerfile
:
test.cpp
#include <pistache/endpoint.h>
#include <pistache/http.h>
#include <pistache/router.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <time.h>
#include <stdio.h>
using namespace Pistache;
void Empty_Route(const Rest::Request& request, Http::ResponseWriter response ){
if (request.headers().list().size() == 0)
{
response.send(Pistache::Http::Code::Ok);
}
response.send(Pistache::Http::Code::Ok);
}
int main( int argc, char *argv[] )
{
using namespace Rest;
std::cerr << "Started " << "\n";
// get port number if specified
Port port(81);
if( argc > 1 )
port = static_cast<uint16_t>(std::stol(argv[1]));
Address addr(Ipv4::any(),port);
std::cerr << "opened port " << port.toString() << "\n";
Router router;
auto opts = Http::Endpoint::options().maxRequestSize(45000000).threads(4);
std::shared_ptr<Http::Endpoint> server = std::make_shared<Http::Endpoint>(addr);
server->init(opts);
//empty route part 1
Routes::Get(router, "/", Routes::bind(&Empty_Route));
Routes::Post(router, "/", Routes::bind(&Empty_Route));
server->setHandler(router.handler());
std::cerr << "server handler set\n";
server->serve();
}
Dockerfile
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
# install pistache
RUN apt-get update && apt install -y software-properties-common build-essential curl \
&& add-apt-repository ppa:pistache+team/unstable \
&& apt update \
&& apt install -y libpistache-dev
ADD test.cpp /tmp/test.cpp
#compile test executable - simplified down from a larger CMake based build using -DCMAKE_BUILD_TYPE=Release
RUN g++ /tmp/test.cpp --std=c++17 -L/usr/lib/x86_64-linux-gnu -lpistache -fstack-protector-strong -o /tmp/test
# expose port used by rest api
EXPOSE 9081
USER nobody
ENTRYPOINT ["/tmp/test", "9081"]
After building and running the container, any request will throw that e.g. curl -i localhost:9081
I was able to get a valgrind
dump and I believe the relevant portion is
==27==
==27== Process terminating with default action of signal 6 (SIGABRT)
==27== at 0x4BB800B: raise (raise.c:51)
==27== by 0x4B97858: abort (abort.c:79)
==27== by 0x4C0226D: __libc_message (libc_fatal.c:155)
==27== by 0x4CA4CD9: __fortify_fail (fortify_fail.c:26)
==27== by 0x4CA4CA5: __stack_chk_fail (stack_chk_fail.c:24)
==27== by 0x110AA6: Pistache::Rest::Routes::bind<void, Pistache::Rest::Request const&, Pistache::Http::ResponseWriter>(void (*)(Pistache::Rest::Request const&, Pistache::Http::ResponseWriter))::{lambda(Pistache::Rest::Request const&, Pistache::Http::ResponseWriter)#1}::operator()(Pistache::Rest::Request const&, Pistache::Http::ResponseWriter) const (in /tmp/test)
==27== by 0x112397: std::_Function_handler<Pistache::Rest::Route::Result (Pistache::Rest::Request, Pistache::Http::ResponseWriter), Pistache::Rest::Routes::bind<void, Pistache::Rest::Request const&, Pistache::Http::ResponseWriter>(void (*)(Pistache::Rest::Request const&, Pistache::Http::ResponseWriter))::{lambda(Pistache::Rest::Request const&, Pistache::Http::ResponseWriter)#1}>::_M_invoke(std::_Any_data const&, Pistache::Rest::Request&&, Pistache::Http::ResponseWriter&&) (in /tmp/test)
==27== by 0x492149E: Pistache::Rest::Router::route(Pistache::Http::Request const&, Pistache::Http::ResponseWriter) (in /usr/lib/x86_64-linux-gnu/libpistache.so.0.2.7)
==27== by 0x4921F25: Pistache::Rest::Private::RouterHandler::onRequest(Pistache::Http::Request const&, Pistache::Http::ResponseWriter) (in /usr/lib/x86_64-linux-gnu/libpistache.so.0.2.7)
==27== by 0x48D0D6D: Pistache::Http::Handler::onInput(char const*, unsigned long, std::shared_ptr<Pistache::Tcp::Peer> const&) (in /usr/lib/x86_64-linux-gnu/libpistache.so.0.2.7)
==27== by 0x49013AA: Pistache::Tcp::Transport::handleIncoming(std::shared_ptr<Pistache::Tcp::Peer> const&) (in /usr/lib/x86_64-linux-gnu/libpistache.so.0.2.7)
==27== by 0x49056FC: Pistache::Tcp::Transport::onReady(Pistache::Aio::FdSet const&) (in /usr/lib/x86_64-linux-gnu/libpistache.so.0.2.7)
==27==
==27== HEAP SUMMARY:
==27== in use at exit: 107,132 bytes in 177 blocks
==27== total heap usage: 360 allocs, 183 frees, 113,877 bytes allocated
==27==
==27== Searching for pointers to 177 not-freed blocks
==27== Checked 33,760,840 bytes
==27==
I can post the full log if helpful but it’s about 1500 lines or so.
About this issue
- Original URL
- State: closed
- Created 6 months ago
- Comments: 17 (9 by maintainers)
I tweaked my CMakeList.txt, and it’s working now 😃 Sorry for any trouble!
Yeah, sorry, we forgot to add that package to the dependencies of
libpistache-dev
- if libbrotli.pc
files are missing, pkg-config refuses to output the correct flags because of reasons. We’ve added it now in https://github.com/pistacheio/pistache/pull/1187 😃@WY-CGhilardi the issue is most likely here:
As mentioned in the README, the only way to properly use a precompiled version of Pistache is to use pkg-config (either directly or indirectly). You should change the compilation line above to: